- GET/PATCH /house/current — renomme le foyer de l'utilisateur connecté.
PATCH avec houseId null -> 404 HOUSE_NOT_FOUND.
- PATCH /profile/diet { dietId: number | null } — régime du profil ;
null l'efface (étape skippable du parcours). dietId invalide ->
404 DIET_NOT_FOUND.
- GET/PATCH /profile/allergies — allergènes/intolérances, liste d'IDs ;
PATCH remplace l'ensemble complet (pas une fusion, cohérent avec un
multi-select). ID invalide -> 404 ALLERGY_NOT_FOUND.
- 3 nouveaux ErrorCode (4041-4043) + libellés fr.
- Extraction de toSafeProfile() dans src/lib/safe-profile.ts —
auparavant dupliqué dans auth.service.ts et require-auth.ts,
profile.service.ts le réutilise aussi.
- Tests Mocha (28 passing) + Cucumber (15 scenarios) — même convention
que le reste, doc README.
Deuxième commit de la feature profil/foyer/régime/allergènes —
composants front partagés dans le commit suivant.
46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { Then, When } from "@cucumber/cucumber";
|
|
import { prisma } from "../../src/db/prisma.js";
|
|
import type { CustomWorld } from "../support/world.js";
|
|
|
|
/** Splits a comma-separated list of names from a `.feature` string into trimmed, non-empty parts. */
|
|
function splitNames(names: string): string[] {
|
|
return names
|
|
.split(",")
|
|
.map((name) => name.trim())
|
|
.filter(Boolean);
|
|
}
|
|
|
|
/** Resolves allergen names (Category.name) to their Allergy id — see reference.service.ts for why the name lives on Category, not Allergy. */
|
|
async function allergyIdsFor(names: string[]): Promise<number[]> {
|
|
const allergies = await prisma.allergy.findMany({ include: { category: true } });
|
|
return names.map((name) => {
|
|
const match = allergies.find((allergy) => allergy.category.name === name);
|
|
if (!match) throw new Error(`No seeded allergen named "${name}"`);
|
|
return match.id;
|
|
});
|
|
}
|
|
|
|
When("I set my regime to {string}", async function (this: CustomWorld, dietName: string) {
|
|
const diet = await prisma.diet.findFirstOrThrow({ where: { name: dietName } });
|
|
this.response = await this.agent.patch("/profile/diet").send({ dietId: diet.id });
|
|
});
|
|
|
|
Then(
|
|
"my profile's regime should be {string}",
|
|
async function (this: CustomWorld, dietName: string) {
|
|
const diet = await prisma.diet.findFirstOrThrow({ where: { name: dietName } });
|
|
assert.equal(this.response.body.dietId, diet.id);
|
|
},
|
|
);
|
|
|
|
When("I set my allergens to {string}", async function (this: CustomWorld, names: string) {
|
|
const allergyIds = await allergyIdsFor(splitNames(names));
|
|
this.response = await this.agent.patch("/profile/allergies").send({ allergyIds });
|
|
});
|
|
|
|
Then("my selected allergens should be {string}", async function (this: CustomWorld, names: string) {
|
|
const expected = (await allergyIdsFor(splitNames(names))).sort();
|
|
const actual = [...this.response.body].sort();
|
|
assert.deepEqual(actual, expected);
|
|
});
|