import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
  buildProductionConfig,
  PRODUCTION_RESOURCES,
} from "../../scripts/cloudflare-production-config.mjs";

test("the checked-in production config binds only exact HearBooks resources", async () => {
  const config = JSON.parse(
    await readFile(new URL("../../wrangler.production.jsonc", import.meta.url), "utf8"),
  );
  const databaseId = config.d1_databases?.[0]?.database_id;

  assert.deepEqual(config, buildProductionConfig({ databaseId }));
  assert.equal(config.name, PRODUCTION_RESOURCES.worker);
  assert.equal(config.d1_databases[0].database_name, PRODUCTION_RESOURCES.database);
  assert.equal(config.r2_buckets[0].bucket_name, PRODUCTION_RESOURCES.bucket);
  assert.doesNotMatch(
    JSON.stringify(config),
    /reader-1|site-creator|chatgpt\.site|IMAGES/,
  );
});
