fix(tests): corrige 3 suites Mocha DB révélées par leur 1er run sur main #17

Merged
kyuno merged 1 commit from fix/mocha-db-suites-first-run into main 2026-08-29 12:02:07 +02:00
3 changed files with 57 additions and 35 deletions

View file

@ -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);

View file

@ -105,17 +105,16 @@ 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) {
return prisma.recipe.create({
data: {
name,
authorId,
portions: 4,
steps: {
create: [
{
/**
* 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: {
@ -137,20 +136,31 @@ describe("Cooking session", () => {
},
],
},
},
{
};
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: 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: {

View file

@ -95,6 +95,8 @@ describe("Reference data", () => {
"reproducible",
"allergens",
"diets",
"isPlaceholder",
"displayName",
]);
});