import { expect, test } from "bun:test";
import en from "../../messages/en.json";
import fr from "../../messages/fr.json";
import {
  ALLOWED_IDENTICAL_KEYS,
  ALLOWED_IDENTICAL_VALUES,
} from "./untranslated-allowlist";

function flatten(obj: unknown, prefix = "", out: Record<string, string> = {}) {
  if (obj && typeof obj === "object") {
    for (const [k, v] of Object.entries(obj as Record<string, unknown>))
      flatten(v, prefix ? `${prefix}.${k}` : k, out);
  } else if (typeof obj === "string") out[prefix] = obj;
  return out;
}

test("aucune valeur FR identique à EN hors allowlist", () => {
  const enFlat = flatten(en);
  const frFlat = flatten(fr);
  const suspects = Object.entries(enFlat)
    .filter(([k, enVal]) => {
      const frVal = frFlat[k];
      return (
        frVal !== undefined &&
        frVal === enVal &&
        !ALLOWED_IDENTICAL_VALUES.has(frVal.trim()) &&
        !ALLOWED_IDENTICAL_KEYS.has(k)
      );
    })
    .map(([k]) => k);
  expect(suspects).toEqual([]);
});
