batchCooking/apps/api/test/sources/sources-index.test.ts
Nicolas 4ac8744384 feat(recipes): ajoute un adaptateur RecipeSourceAdapter pour Manger Bouger
Suit le même schéma que marmitonAdapter/sevenFiftyGAdapter (construit sur
jsonLdRecipeAdapter), avec des différences propres à mangerbouger.fr
(« La Fabrique à Menus », Santé publique France) :

- list() n'utilise pas de JSON-LD du tout — la page de résultats (une app
  Next.js) n'embarque aucun ItemList. Elle est cependant rendue
  côté serveur et expose le même state Redux que le client hydrate, via un
  <script id="__NEXT_DATA__">, qui contient déjà tout ce dont list() a
  besoin (slug/nom/image, pagination). Vérifié en direct : ?query=<texte
  libre> filtre bien côté serveur, et hasMorePages donne un signal de fin
  de pagination plus propre que le 404 de Marmiton ou l'absence de vraie
  pagination de 750g.
- parse() délègue à jsonLdRecipeAdapter mais corrige deux lacunes réelles
  et systématiques de son propre JSON-LD (vérifiées sur 9 recettes,
  72 étapes) : recipeInstructions[].text est un document Slate.js
  sérialisé en JSON (pas du texte) plutôt qu'être aplati ; recipeYield est
  absent partout alors que le nombre de portions existe bien côté site
  (__NEXT_DATA__) — les deux sont corrigés par un patch structuré (parse →
  mutation → réécriture) avant délégation, pas une réimplémentation.

Enregistre mangerBougerAdapter dans registerAllRecipeSources
(sources/index.ts) et complète sources-index.test.ts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-22 18:55:10 +02:00

61 lines
2.3 KiB
TypeScript

import { expect } from "chai";
import {
clearRecipeSources,
getRecipeSource,
listRecipeSources,
} from "../../src/lib/recipe-sources/recipe-source-registry.js";
import { registerAllRecipeSources } from "../../src/sources/index.js";
// Not exercised by any other test file — `registerAllRecipeSources` is
// deliberately never imported by `app.ts` (see its own doc comment), so
// nothing else in the suite triggers it. Registers/clears explicitly here
// rather than relying on module-load order, so this test's outcome doesn't
// depend on which other test file Mocha happens to load first.
describe("registerAllRecipeSources", () => {
afterEach(() => {
clearRecipeSources();
});
it("registers TheMealDB into the shared registry", () => {
registerAllRecipeSources();
const theMealDb = getRecipeSource("theMealDb");
expect(theMealDb).to.not.be.undefined;
expect(theMealDb?.name).to.equal("TheMealDB");
expect(listRecipeSources().map((adapter) => adapter.key)).to.include("theMealDb");
});
it("registers Marmiton into the shared registry", () => {
registerAllRecipeSources();
const marmiton = getRecipeSource("marmiton");
expect(marmiton).to.not.be.undefined;
expect(marmiton?.name).to.equal("Marmiton");
expect(listRecipeSources().map((adapter) => adapter.key)).to.include("marmiton");
});
it("registers 750g into the shared registry", () => {
registerAllRecipeSources();
const sevenFiftyG = getRecipeSource("750g");
expect(sevenFiftyG).to.not.be.undefined;
expect(sevenFiftyG?.name).to.equal("750g");
expect(listRecipeSources().map((adapter) => adapter.key)).to.include("750g");
});
it("registers Manger Bouger into the shared registry", () => {
registerAllRecipeSources();
const mangerBouger = getRecipeSource("mangerBouger");
expect(mangerBouger).to.not.be.undefined;
expect(mangerBouger?.name).to.equal("Manger Bouger");
expect(listRecipeSources().map((adapter) => adapter.key)).to.include("mangerBouger");
});
it("does not register the generic JSON-LD adapter — it's not a household-toggleable source in its own right", () => {
registerAllRecipeSources();
expect(getRecipeSource("jsonLdRecipe")).to.be.undefined;
expect(listRecipeSources().map((adapter) => adapter.key)).to.not.include("jsonLdRecipe");
});
});