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");
  });
});
