import { afterEach, describe, expect, it } from 'vitest'; import { buildFakeRepos } from '../helpers/fake-repos.js'; import { makeIntervention, makeProjet, makeTache } from '../helpers/fixtures.js'; import { READ_ALL_TOKEN, buildTestApp, installTestContainer, resetTestContainer, } from '../helpers/test-app.js'; function bootApp() { const tache = makeTache(400, 300); // Une intervention realisee de 2h sur la tache. tache.interventions.push(makeIntervention({ id: 600, tacheId: 400, personneId: 2 })); const repos = buildFakeRepos({ projets: [makeProjet(300, 50)], taches: [tache], }); const container = installTestContainer({ repos }); return { app: buildTestApp(container) }; } describe('GET /api/v1/projets', () => { afterEach(resetTestContainer); it('401 sans token', async () => { const { app } = bootApp(); const res = await app.request('/api/v1/projets'); expect(res.status).toBe(401); }); it('200 list', async () => { const { app } = bootApp(); const res = await app.request('/api/v1/projets', { headers: { Authorization: `Bearer ${READ_ALL_TOKEN}` }, }); expect(res.status).toBe(200); const body = (await res.json()) as { data: { id: number }[] }; expect(body.data).toHaveLength(1); }); it('GET /:id avec taches + heures rollup', async () => { const { app } = bootApp(); const res = await app.request('/api/v1/projets/300', { headers: { Authorization: `Bearer ${READ_ALL_TOKEN}` }, }); expect(res.status).toBe(200); const body = (await res.json()) as { data: { taches: { id: number; heures_realisees: string }[]; heures_realisees: string }; }; expect(body.data.taches).toHaveLength(1); expect(body.data.heures_realisees).toBe('2.00'); }); it('404 si projet inconnu', async () => { const { app } = bootApp(); const res = await app.request('/api/v1/projets/9999', { headers: { Authorization: `Bearer ${READ_ALL_TOKEN}` }, }); expect(res.status).toBe(404); }); });