import assert from "node:assert/strict"; import { DateTime } from "@batch-cooking/date-tools"; import { Given, Then, When } from "@cucumber/cucumber"; import { prisma } from "../../src/db/prisma.js"; import type { CustomWorld } from "../support/world.js"; /** `GET /planning` takes `?date=` explicitly — this scenario wording ("the current planning") maps to "today". */ When("I request the current planning", async function (this: CustomWorld) { this.response = await this.agent.get("/planning").query({ date: DateTime.utc().toISODate() }); }); Then("the current planning response should be empty", function (this: CustomWorld) { assert.equal(this.response.body, null); }); // Creates the planning/recipe rows directly via Prisma rather than through // the API — there's no "create a planning" endpoint yet (see // specs/batch-cooking-architecture.md, "Calcul batch-cooking" is still // TODO), so this is the only way to get a household into a state where it // has one. A household is no longer created implicitly at signup, so this // step creates one via `POST /house` first — the scenario never names it // explicitly, its name doesn't matter here. Given( "my household has a planning covering today with recipe {string} on {string} for {string}", async function (this: CustomWorld, recipeName: string, weekDay: string, meal: string) { const houseRes = await this.agent.post("/house").send({ name: "Foyer de test" }); const houseId: number = houseRes.body.id; const recipe = await prisma.recipe.create({ data: { name: recipeName } }); const today = new Date(); const planning = await prisma.planning.create({ data: { houseId, startDate: new Date( Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 2), ), finishDate: new Date( Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 2), ), }, }); await prisma.planningItem.create({ data: { planningId: planning.id, weekDay, meal, recipeId: recipe.id }, }); }, ); Then( "the current planning response should include recipe {string} on {string} for {string}", function (this: CustomWorld, recipeName: string, weekDay: string, meal: string) { const items = this.response.body.items as Array<{ weekDay: string; meal: string; recipe: { name: string }; }>; const item = items.find((i) => i.recipe.name === recipeName); assert.ok(item, `expected an item with recipe "${recipeName}", got ${JSON.stringify(items)}`); assert.equal(item.weekDay, weekDay); assert.equal(item.meal, meal); }, );