- onboarding.cy.ts / preferences.cy.ts / recipes.cy.ts mockaient encore
GET /reference/diets|allergies avec l'ancienne forme {id, name}. Depuis
les deux derniers commits l'API renvoie {id, key} (uid anglais) et le
composant résout le libellé via i18n (t(`catalog.diets.${key}`)) — avec
key manquant, ça affichait littéralement "catalog.diets.undefined" au
lieu de "Végétarien"/"Omnivore"/etc., faisant échouer cy.select()/
cy.contains() dans ces 3 specs. Corrigé pour mocker {key: "vegetarian"},
{key: "peanuts"}, etc.
- recipes.cy.ts : le test "shows a not-found message" utilisait le
mauvais code d'erreur (4041 au lieu de ErrorCode.RECIPE_NOT_FOUND =
4045), donc RecipeDetailPanel tombait dans son état d'erreur générique
au lieu du message "Cette recette n'existe pas." — bug dans mon propre
test, sans rapport avec le refactor.
- pnpm lint (biome) : les fichiers touchés par le refactor précédent
avaient quelques soucis de formatage/tri d'imports (des sed multi-
fichiers, pas d'édition via l'outil habituel) — corrigés par
`biome check --write`.
Vérifié : ces 3 specs + recipe-form.cy.ts passent maintenant dans le job
CI GitHub Actions (Linux, Cypress s'y exécute réellement — contrairement
à cet environnement Windows sandboxé, voir les commits précédents) ; 102
tests Mocha + 32 scénarios Cucumber toujours au vert en local.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
/**
|
|
* One-off generator, run by hand whenever the catalog's reference data
|
|
* changes (a new ingredient/diet/allergen added to
|
|
* `db/reference-seed-data.ts`, or an English key corrected in
|
|
* `catalog-en-keys.ts`): regenerates
|
|
* `apps/web/src/locales/fr/translation.json`'s
|
|
* `catalog.{diets,allergens,ingredients}` sections (English key -> French
|
|
* label), merged in without touching the rest of the file.
|
|
*
|
|
* Doesn't touch the database — a brand new diet/allergen/ingredient is
|
|
* created fresh by `seedReferenceData`'s normal create path (see
|
|
* `reference-seed-data.ts`), no backfill needed. Renaming an *existing*
|
|
* item's English key in `catalog-en-keys.ts` does need a one-off migration
|
|
* (`UPDATE ... SET key = ...`, keyed by the *old* key value) written by
|
|
* hand for that occasion — see
|
|
* `prisma/migrations/20260818193000_catalog_keys_to_english/` for the shape
|
|
* one looks like.
|
|
*
|
|
* Never imported by the app itself — a dev-time tool, run via
|
|
* `tsx scripts/generate-catalog-i18n.ts`.
|
|
*/
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { getEnglishKey } from "../src/db/catalog-en-keys.js";
|
|
import { ALLERGENS, DIETS, INGREDIENT_GROUPS } from "../src/db/reference-seed-data.js";
|
|
|
|
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
|
|
function toKeyLabelMap(labels: string[]): Record<string, string> {
|
|
const map: Record<string, string> = {};
|
|
for (const label of labels) {
|
|
map[getEnglishKey(label)] = label;
|
|
}
|
|
return map;
|
|
}
|
|
|
|
const diets = toKeyLabelMap(DIETS);
|
|
const allergens = toKeyLabelMap(ALLERGENS.map((a) => a.name));
|
|
const ingredients = toKeyLabelMap(INGREDIENT_GROUPS.flatMap((g) => g.items.map((i) => i.name)));
|
|
|
|
console.log(
|
|
`diets: ${Object.keys(diets).length}, allergens: ${Object.keys(allergens).length}, ingredients: ${Object.keys(ingredients).length}`,
|
|
);
|
|
|
|
const localePath = `${here}../../web/src/locales/fr/translation.json`;
|
|
const locale = JSON.parse(readFileSync(localePath, "utf8"));
|
|
locale.catalog = { diets, allergens, ingredients };
|
|
writeFileSync(localePath, `${JSON.stringify(locale, null, 2)}\n`);
|
|
console.log(`wrote ${localePath}`);
|