63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { useQualimatSearch, type QualimatCarrierRow } from '../useQualimatSearch'
|
|
|
|
const mockApiGet = vi.hoisted(() => vi.fn())
|
|
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
|
|
|
/**
|
|
* Tests de la saisie assistée QUALIMAT (M4 Transport, ERP-166 — RG-4.01).
|
|
*
|
|
* `useQualimatSearch` est une fine enveloppe de `usePaginatedList<QualimatCarrierRow>`
|
|
* sur `/qualimat_carriers`. La pagination générique est couverte par
|
|
* `usePaginatedList.test.ts` ; on vérifie ici le CONTRAT propre à la recherche :
|
|
* - ressource ciblée `/qualimat_carriers` + enveloppe Hydra + `Accept: application/ld+json` ;
|
|
* - le filtre `search` (branché sur le nom du transporteur) est transmis et
|
|
* retombe en page 1.
|
|
*/
|
|
describe('useQualimatSearch', () => {
|
|
beforeEach(() => {
|
|
mockApiGet.mockReset()
|
|
})
|
|
|
|
const PAGE: QualimatCarrierRow[] = [
|
|
{
|
|
'@id': '/api/qualimat_carriers/1',
|
|
id: '1',
|
|
name: 'TRANSPORTS ACME',
|
|
siret: '12345678900012',
|
|
address: '1 rue du Port',
|
|
postalCode: '86000',
|
|
city: 'Poitiers',
|
|
validityDate: '2027-01-15',
|
|
status: 'VALIDE',
|
|
},
|
|
]
|
|
|
|
it('cible /qualimat_carriers, consomme l\'enveloppe Hydra et envoie l\'Accept ld+json', async () => {
|
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
|
const repo = useQualimatSearch()
|
|
|
|
await repo.fetch()
|
|
|
|
const [url, query, opts] = mockApiGet.mock.calls[0]
|
|
expect(url).toBe('/qualimat_carriers')
|
|
expect(query).toMatchObject({ page: 1, itemsPerPage: 10 })
|
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
|
expect(repo.items.value).toEqual(PAGE)
|
|
expect(repo.totalItems.value).toBe(1)
|
|
})
|
|
|
|
it('transmet le filtre `search` (nom du transporteur) et retombe en page 1', async () => {
|
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
|
const repo = useQualimatSearch()
|
|
await repo.fetch()
|
|
|
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
|
await repo.setFilters({ search: 'acme' })
|
|
|
|
expect(repo.currentPage.value).toBe(1)
|
|
const query = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
|
expect(query.search).toBe('acme')
|
|
})
|
|
})
|