import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { allQuestions, chapters } from "./question-bank.js";

test("Score-API-Katalog entspricht exakt der Fragenbank", async () => {
  const catalog = JSON.parse(
    await readFile(
      new URL("../server/question-catalog.json", import.meta.url),
      "utf8"
    )
  );
  const expected = Object.fromEntries(
    allQuestions.map(({ id, chapterId, xp }) => [id, { chapterId, xp }])
  );

  assert.deepEqual(
    catalog.chapters,
    chapters.map(({ id, number }) => ({ id, number }))
  );
  assert.deepEqual(catalog.questions, expected);
});
