feat(transport) : consultation + modification transporteur (ERP-170)

This commit is contained in:
2026-06-17 11:35:14 +02:00
parent fb9c15c52a
commit e612eae391
8 changed files with 1250 additions and 1 deletions
@@ -912,3 +912,49 @@ describe('useCarrierForm — onglet Prix (ERP-169)', () => {
expect(form.prices.value).toHaveLength(1)
})
})
describe('useCarrierForm — édition (ERP-170)', () => {
beforeEach(() => {
mockPost.mockReset()
mockPatch.mockReset()
})
it('prefillFrom : peuple carrierId + principal + sous-collections, passe en editMode', () => {
const form = useCarrierForm()
form.prefillFrom({
'@id': '/api/carriers/7',
id: 7,
name: 'TRANSPORTS ACME',
certificationType: 'GMP_PLUS',
addresses: [{ '@id': '/api/carrier_addresses/3', id: 3, city: 'Poitiers' }],
contacts: [{ '@id': '/api/carrier_contacts/9', id: 9, lastName: 'Doe', phonePrimary: '0102030405' }],
prices: [{ '@id': '/api/carrier_prices/5', id: 5, direction: 'CLIENT', client: { '@id': '/api/clients/3' }, containerType: 'BENNE', pricingUnit: 'FORFAIT', price: '120', priceState: 'EN_COURS' }],
})
expect(form.carrierId.value).toBe(7)
expect(form.editMode.value).toBe(true)
expect(form.main.name).toBe('TRANSPORTS ACME')
expect(form.main.certificationType).toBe('GMP_PLUS')
expect(form.addresses.value).toHaveLength(1)
expect(form.addresses.value[0]?.id).toBe(3)
expect(form.contacts.value[0]?.id).toBe(9)
expect(form.prices.value[0]?.clientIri).toBe('/api/clients/3')
})
it('updateMain : PATCH /carriers/{id} (pas de POST), réaffiche le nom normalisé', async () => {
mockPatch.mockResolvedValueOnce({ id: 7, name: 'TRANSPORTS ACME', certificationType: 'GMP_PLUS' })
const form = useCarrierForm()
form.prefillFrom({ '@id': '/api/carriers/7', id: 7, name: 'Transports Acme', certificationType: 'GMP_PLUS' })
const ok = await form.updateMain()
expect(ok).toBe(true)
expect(mockPost).not.toHaveBeenCalled()
expect(mockPatch).toHaveBeenCalledWith(
'/carriers/7',
expect.objectContaining({ name: 'Transports Acme', certificationType: 'GMP_PLUS' }),
{ toast: false },
)
expect(form.main.name).toBe('TRANSPORTS ACME')
})
})