// src/lib/backlink/fixtures.test.ts
import { describe, expect, test } from "bun:test";
import { BACKLINK_SOURCES } from "./fixtures";
import { SOURCE_KINDS } from "./types";

const KIND_IDS = new Set(SOURCE_KINDS.map((k) => k.id));

describe("BACKLINK_SOURCES (generated seed)", () => {
  test("loads a substantial, deduped set", () => {
    expect(BACKLINK_SOURCES.length).toBeGreaterThan(300);
    const urls = BACKLINK_SOURCES.map((s) => s.url);
    expect(new Set(urls).size).toBe(urls.length); // unique target URLs
  });
  test("every url is https and every id/domain is non-empty", () => {
    for (const s of BACKLINK_SOURCES) {
      expect(s.url.startsWith("https://")).toBe(true);
      expect(s.id.length).toBeGreaterThan(0);
      expect(s.domainNorm.length).toBeGreaterThan(0);
    }
  });
  test("ids are unique", () => {
    const ids = BACKLINK_SOURCES.map((s) => s.id);
    expect(new Set(ids).size).toBe(ids.length);
  });
  test("da is null or within 0..100; kind is valid", () => {
    for (const s of BACKLINK_SOURCES) {
      if (s.da !== null) {
        expect(s.da).toBeGreaterThanOrEqual(0);
        expect(s.da).toBeLessThanOrEqual(100);
      }
      expect(KIND_IDS.has(s.kind)).toBe(true);
    }
  });
});
