From 9532ea4e8320968c2ce2eb6ed2ea790e12d708f5 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 29 Aug 2026 12:00:43 +0200 Subject: [PATCH] fix(tests): corrige 3 suites Mocha DB revelees par leur 1er run sur main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ces suites ont ete ecrites pendant le dev des features cooking / admin / hors-catalogue mais jamais executees (pas de Postgres dans ces sessions). Leur 1re execution reelle sur `main` echouait — bugs dans les tests, pas dans le code merge. - reference.test.ts : `GET /reference/ingredients` renvoie desormais `isPlaceholder` (toujours false) et `displayName` (toujours null) depuis la PR #16 (champs de `IngredientView`). L'assertion `to.have.keys([...])` exacte est mise a jour. - cooking-session.test.ts : la fixture "pooling merged-prep" avait 2 recettes symetriques (chop -> simmer) ; apres mise en commun du chop les deux simmer tournent dans l'unique phase de cuisson, donc aucun `background` possible (l'optimiseur est correct, cf. le test pur equivalent). « Tarte » recoit une etape active `mix` de plus pour que son simmer flotte en background pendant que « Soupe » est en hold. - admin-tech-steps.test.ts : une requete supertest ne part qu'a l'`await`/ `.then` ; la 1re requete /retrain concurrente n'etait jamais lancee, donc le verrou process n'etait jamais tenu et la 2e recevait 200 au lieu de 409. Ajout d'un `.then(res => res, err => err)` pour la declencher avant l'attente de 100 ms. Co-Authored-By: Claude Sonnet 5 --- apps/api/test/admin-tech-steps.test.ts | 14 ++++- apps/api/test/cooking-session.test.ts | 76 +++++++++++++++----------- apps/api/test/reference.test.ts | 2 + 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/apps/api/test/admin-tech-steps.test.ts b/apps/api/test/admin-tech-steps.test.ts index 02e630f..b99f633 100644 --- a/apps/api/test/admin-tech-steps.test.ts +++ b/apps/api/test/admin-tech-steps.test.ts @@ -286,8 +286,18 @@ describe("Admin tech-steps triage", () => { } this.timeout(60000); const agent = await adminAgent(); - const first = agent.post("/admin/tech-steps/retrain").send({}); - // Let the first handler acquire the process-wide lock before the second starts. + // supertest requests are lazy — they only dispatch when awaited/then'd. + // Attaching the `.then` here is what actually fires the first request, + // so its handler acquires the process-wide lock before the second one + // (100ms later) checks it. Swallow its result/rejection — this test + // only asserts on the second request. + const first = agent + .post("/admin/tech-steps/retrain") + .send({}) + .then( + (res) => res, + (err) => err, + ); await new Promise((resolve) => setTimeout(resolve, 100)); const second = await agent.post("/admin/tech-steps/retrain").send({}); expect(second.status).to.equal(409); diff --git a/apps/api/test/cooking-session.test.ts b/apps/api/test/cooking-session.test.ts index b218aff..c23d127 100644 --- a/apps/api/test/cooking-session.test.ts +++ b/apps/api/test/cooking-session.test.ts @@ -105,52 +105,62 @@ describe("Cooking session", () => { const pieceId = await unitId("piece"); const chopId = await techStepId("chop"); const simmerId = await techStepId("simmer"); + const mixId = await techStepId("mix"); - /** A recipe: one pure-prep "chop onion" step, then one simmer step. */ - async function makeRecipe(name: string, onionQty: number) { + /** + * A recipe: one pure-prep "chop onion" step, then (optionally) an + * active "mix" step, then one simmer step. The `withActiveStep` recipe + * is still doing hands-on work in the phase after its simmer starts, so + * the other recipe's simmer floats into that phase as `background`. + */ + async function makeRecipe(name: string, onionQty: number, withActiveStep = false) { + const chopStep = { + order: 0, + description: "Émincer les oignons", + techSteps: { + create: [ + { + techStepId: chopId, + order: 0, + ingredients: { + create: [ + { + ingredientId: onionId, + quantity: onionQty, + unitId: pieceId, + start: 0, + end: 1, + }, + ], + }, + }, + ], + }, + }; + const activeStep = { + order: 1, + description: "Mélanger l'appareil", + techSteps: { create: [{ techStepId: mixId, order: 0 }] }, + }; + const simmerStep = { + order: withActiveStep ? 2 : 1, + description: "Faire mijoter", + techSteps: { create: [{ techStepId: simmerId, order: 0 }] }, + }; return prisma.recipe.create({ data: { name, authorId, portions: 4, steps: { - create: [ - { - order: 0, - description: "Émincer les oignons", - techSteps: { - create: [ - { - techStepId: chopId, - order: 0, - ingredients: { - create: [ - { - ingredientId: onionId, - quantity: onionQty, - unitId: pieceId, - start: 0, - end: 1, - }, - ], - }, - }, - ], - }, - }, - { - order: 1, - description: "Faire mijoter", - techSteps: { create: [{ techStepId: simmerId, order: 0 }] }, - }, - ], + create: withActiveStep ? [chopStep, activeStep, simmerStep] : [chopStep, simmerStep], }, }, }); } const soupe = await makeRecipe("Soupe", 2); - const tarte = await makeRecipe("Tarte", 3); + const tarte = await makeRecipe("Tarte", 3, true); const planning = await prisma.planning.create({ data: { diff --git a/apps/api/test/reference.test.ts b/apps/api/test/reference.test.ts index c21d040..2acc9e3 100644 --- a/apps/api/test/reference.test.ts +++ b/apps/api/test/reference.test.ts @@ -95,6 +95,8 @@ describe("Reference data", () => { "reproducible", "allergens", "diets", + "isPlaceholder", + "displayName", ]); });