All checks were successful
`RecipeDiet` (tag manuel) est supprimé — table droppée, `dietIds` retiré de `createRecipeSchema`, `DietTagSelect` retiré des formulaires de recette (création + import). `RecipeSummaryView.diets` / `RecipeView.diets` sont désormais **dérivés** via `computeRecipeDietViews` (`@batch-cooking/shared`, pur, testé isolément) : - un régime (vegetarian / vegan / pescatarian) est retenu ssi *tous* les ingrédients y sont compatibles (`IngredientDiet`, exposé par `IngredientView.diets`) ; - `glutenFree` est dérivé des allergènes (aucun ingrédient ne porte `gluten`) — cohérent avec le fait que le seed ne le stocke pas dans `IngredientDiet` ; - `[]` dès qu'une recette contient un ingrédient placeholder (hors-catalogue) : un ingrédient inconnu ne certifie rien. Filtres du sélecteur de planning (`suitableForHousehold`, `dietIds`) : ne peuvent plus être du SQL sur une colonne stockée — devenus des post-filtres sur `diets` calculé dans `listRecipes` ; `omnivore` traité comme « aucune contrainte ». `assertDietsExist` / `ErrorCode.DIET_NOT_FOUND` sur la création recette supprimés (le code d'erreur reste, utilisé par la préférence profil). `DietBadges` inchangé (affiche `diets` tel quel). `RecipePickerDialog` garde son filtre régime (fonctionne via le post-filtre). Tests : `recipe-diets.test.ts` (fonction pure) + `recipe.test.ts` réécrit (régimes calculés attendus, tests DIET_NOT_FOUND retirés) ; Cypress OK (formulaire sans sélecteur de régime, régression recettes/sources/planning). Migration `DROP TABLE recipe_diet` — aucune donnée à conserver. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
86 lines
3.2 KiB
TypeScript
86 lines
3.2 KiB
TypeScript
import { computeRecipeDietViews, type DietView, type IngredientView } from "@batch-cooking/shared";
|
|
import { expect } from "chai";
|
|
|
|
/**
|
|
* Pure regime derivation from `@batch-cooking/shared` — no DB, so this suite
|
|
* skips `resetDatabase`. `recipe.service.ts`'s `toRecipeSummaryView` calls
|
|
* it for every recipe read (issue #131 dropped the hand-tagged `RecipeDiet`).
|
|
*/
|
|
|
|
const VEGETARIAN: DietView = { id: 1, key: "vegetarian" };
|
|
const VEGAN: DietView = { id: 2, key: "vegan" };
|
|
const PESCATARIAN: DietView = { id: 3, key: "pescatarian" };
|
|
const GLUTEN_FREE: DietView = { id: 4, key: "glutenFree" };
|
|
|
|
/** A minimal ingredient fixture — only the fields `computeRecipeDietViews` reads. */
|
|
function ingredient(
|
|
diets: DietView[],
|
|
opts: { gluten?: boolean; placeholder?: boolean } = {},
|
|
): Pick<IngredientView, "diets" | "allergens" | "isPlaceholder"> {
|
|
return {
|
|
diets,
|
|
allergens: opts.gluten ? [{ id: 9, key: "gluten", kind: "INTOLERANCE" }] : [],
|
|
isPlaceholder: opts.placeholder ?? false,
|
|
};
|
|
}
|
|
|
|
describe("computeRecipeDietViews", () => {
|
|
it("keeps only the regimes every ingredient is compatible with", () => {
|
|
const result = computeRecipeDietViews(
|
|
[
|
|
ingredient([VEGETARIAN, VEGAN, PESCATARIAN]),
|
|
ingredient([VEGETARIAN, PESCATARIAN]), // e.g. egg — not vegan
|
|
],
|
|
GLUTEN_FREE,
|
|
);
|
|
expect(result.map((d) => d.key)).to.deep.equal(["vegetarian", "pescatarian", "glutenFree"]);
|
|
});
|
|
|
|
it("drops every ingredient-derived regime when one ingredient is compatible with none", () => {
|
|
const result = computeRecipeDietViews(
|
|
[ingredient([VEGETARIAN, VEGAN, PESCATARIAN]), ingredient([])],
|
|
GLUTEN_FREE,
|
|
);
|
|
// Still gluten-free — nothing carries the allergen.
|
|
expect(result.map((d) => d.key)).to.deep.equal(["glutenFree"]);
|
|
});
|
|
|
|
it("is not gluten-free when any ingredient carries the gluten allergen", () => {
|
|
const result = computeRecipeDietViews(
|
|
[
|
|
ingredient([VEGETARIAN, VEGAN, PESCATARIAN]),
|
|
ingredient([VEGETARIAN, VEGAN, PESCATARIAN], { gluten: true }),
|
|
],
|
|
GLUTEN_FREE,
|
|
);
|
|
expect(result.map((d) => d.key)).to.deep.equal(["vegetarian", "vegan", "pescatarian"]);
|
|
});
|
|
|
|
it("returns [] for a recipe with any placeholder (off-catalog) ingredient", () => {
|
|
const result = computeRecipeDietViews(
|
|
[ingredient([VEGETARIAN, VEGAN, PESCATARIAN]), ingredient([], { placeholder: true })],
|
|
GLUTEN_FREE,
|
|
);
|
|
expect(result).to.deep.equal([]);
|
|
});
|
|
|
|
it("returns [] when there are no ingredients", () => {
|
|
expect(computeRecipeDietViews([], GLUTEN_FREE)).to.deep.equal([]);
|
|
});
|
|
|
|
it("omits gluten-free entirely when no glutenFree DietView is supplied", () => {
|
|
const result = computeRecipeDietViews(
|
|
[ingredient([VEGAN, VEGETARIAN, PESCATARIAN])],
|
|
undefined,
|
|
);
|
|
expect(result.map((d) => d.key)).to.deep.equal(["vegetarian", "vegan", "pescatarian"]);
|
|
});
|
|
|
|
it("borrows each regime's DietView (id + key) from the ingredients themselves", () => {
|
|
const result = computeRecipeDietViews(
|
|
[ingredient([VEGETARIAN]), ingredient([VEGETARIAN])],
|
|
undefined,
|
|
);
|
|
expect(result).to.deep.equal([VEGETARIAN]);
|
|
});
|
|
});
|