- house.test.ts réécrit (le foyer n'est plus auto-créé) + POST /house, POST /house/join, POST /house/leave, DELETE /house/current, DELETE /house/members/:id - auth.test.ts: signup renvoie houseId=null, DELETE /auth/me (mauvais mot de passe, suppression, transfert d'admin) - planning.test.ts/steps.ts: création explicite du foyer (POST /house) - household.feature: scénarios créer/rejoindre/quitter/supprimer/ retirer un membre, via un second agent (CustomWorld.secondAgent) - auth.feature: scénarios de suppression de compte
59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { Given, Then, When } from "@cucumber/cucumber";
|
|
import { prisma } from "../../src/db/prisma.js";
|
|
import type { CustomWorld } from "../support/world.js";
|
|
|
|
When("I request the current planning", async function (this: CustomWorld) {
|
|
this.response = await this.agent.get("/planning/current");
|
|
});
|
|
|
|
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);
|
|
},
|
|
);
|