Quand le catalogue seede ne couvre pas un ingredient, l'utilisateur pouvait etre bloque (creation manuelle) ou perdre silencieusement la ligne (import). Une ligne de recette accepte desormais `placeholderName` (texte libre) au lieu de `ingredientId` : l'API cree une ligne `Ingredient` `isPlaceholder` (cle `placeholder:<uuid>`, `displayName`, `createdById`) dans la transaction de la recette, et emet `ingredient.placeholder_created`. Ces lignes sont exclues de `GET /reference/ingredients` et de `ingredient-matcher`. Front : bouton "Ajouter << ... >>" dans l'etat vide de `IngredientPicker` (formulaire + import), badge "a completer" sur la ligne, helper `ingredientLabel` applique partout ou un libelle d'ingredient est rendu. Admin : `/admin/catalog/*` (+ page `apps/admin-web`) liste les placeholders regroupes par nom normalise, "marquer traite" (`reviewedAt`) et purge des orphelins. La promotion en vraie entree catalogue reste manuelle. Migration `ingredient_placeholder` ecrite a la main (Postgres indisponible). Suites Mocha DB-backed ecrites, non executees en session ; test pur `normalizePlaceholderName` + Cypress admin-web/web verts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
96 lines
2.9 KiB
TypeScript
96 lines
2.9 KiB
TypeScript
// Mocks the admin API via cy.intercept — no live backend.
|
|
|
|
const adminBody = {
|
|
id: 1,
|
|
email: "ops@example.com",
|
|
name: "Ops",
|
|
createdAt: "2026-08-01T00:00:00.000Z",
|
|
lastLoginAt: "2026-08-28T09:00:00.000Z",
|
|
};
|
|
|
|
function pendingGroups() {
|
|
return [
|
|
{
|
|
normalizedName: "piment d espelette",
|
|
displayNames: ["Piment d'Espelette", "piment d espelette"],
|
|
ingredientIds: [11, 12],
|
|
recipeCount: 2,
|
|
sampleRecipes: [
|
|
{ id: 1, name: "Poulet basquaise" },
|
|
{ id: 2, name: "Piperade" },
|
|
],
|
|
firstSeenAt: "2026-08-20T10:00:00.000Z",
|
|
allReviewed: false,
|
|
},
|
|
{
|
|
normalizedName: "sumac",
|
|
displayNames: ["Sumac"],
|
|
ingredientIds: [13],
|
|
recipeCount: 1,
|
|
sampleRecipes: [{ id: 3, name: "Fattoush" }],
|
|
firstSeenAt: "2026-08-22T10:00:00.000Z",
|
|
allReviewed: false,
|
|
},
|
|
];
|
|
}
|
|
|
|
describe("Admin catalog — off-catalog ingredients", () => {
|
|
beforeEach(() => {
|
|
cy.viewport(1400, 900);
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
});
|
|
|
|
it("lists placeholder groups newest-impact first with their recipe count and spelling variants", () => {
|
|
cy.intercept("GET", "**/admin/catalog/placeholders*", {
|
|
statusCode: 200,
|
|
body: pendingGroups(),
|
|
}).as("getPlaceholders");
|
|
cy.visit("/catalogue");
|
|
cy.wait("@getPlaceholders");
|
|
|
|
cy.get(".catalog-card").should("have.length", 2);
|
|
cy.get(".catalog-card").first().should("contain.text", "Piment d'Espelette");
|
|
cy.contains(".catalog-card", "Piment d'Espelette")
|
|
.should("contain.text", "2 recette")
|
|
.and("contain.text", "piment d espelette")
|
|
.and("contain.text", "Poulet basquaise");
|
|
});
|
|
|
|
it("marks a group reviewed and reloads the list", () => {
|
|
cy.intercept("GET", "**/admin/catalog/placeholders*", {
|
|
statusCode: 200,
|
|
body: pendingGroups(),
|
|
}).as("getPlaceholders");
|
|
cy.intercept("PATCH", "**/admin/catalog/placeholders/mark-reviewed", {
|
|
statusCode: 200,
|
|
body: { reviewed: 1 },
|
|
}).as("markReviewed");
|
|
|
|
cy.visit("/catalogue");
|
|
cy.wait("@getPlaceholders");
|
|
|
|
cy.contains(".catalog-card", "Sumac").contains("button", "Marquer comme traité").click();
|
|
|
|
cy.wait("@markReviewed")
|
|
.its("request.body")
|
|
.should("deep.equal", { ingredientIds: [13] });
|
|
// The page re-fetches the list after the PATCH.
|
|
cy.get("@getPlaceholders.all").should("have.length.greaterThan", 1);
|
|
});
|
|
|
|
it("switches to the reviewed archive tab", () => {
|
|
cy.intercept("GET", "**/admin/catalog/placeholders", {
|
|
statusCode: 200,
|
|
body: pendingGroups(),
|
|
});
|
|
cy.intercept("GET", "**/admin/catalog/placeholders?reviewed=true", {
|
|
statusCode: 200,
|
|
body: [],
|
|
}).as("getReviewed");
|
|
|
|
cy.visit("/catalogue");
|
|
cy.contains(".catalog-tabs button", "Traités").click();
|
|
cy.wait("@getReviewed");
|
|
cy.contains("Aucun ingrédient hors-catalogue").should("be.visible");
|
|
});
|
|
});
|