import { periodSourceTable } from "./billing.service";

/**
 * A closed year is imported as its own tagged set of rows rather than being
 * identified by date. The tag is written by migration/transform_transactions.py
 * and read by BillingService.statement, the edo-cuenta-datos report, and the
 * PHP portal — three places that must agree on the exact string.
 */
describe("periodSourceTable", () => {
  it("names the archive the migration writes", () => {
    expect(periodSourceTable(2025)).toBe("datos2@2025");
    expect(periodSourceTable(2024)).toBe("datos2@2024");
  });

  it("stays distinct from the live ledger's own table", () => {
    // The live table is plain `datos2`. legacyId is a positional ordinal that
    // restarts at 0 in every archive, so a shared name would collide with the
    // current year row-for-row on the unique key.
    expect(periodSourceTable(2025)).not.toBe("datos2");
    expect(periodSourceTable(2025).startsWith("datos2@")).toBe(true);
  });

  it("is not matched by the statement's cash-source exclusion list", () => {
    // STATEMENT_EXCLUDED_SOURCE_TABLES drops the EFECTIVO family to reproduce
    // legacy's DATOS2-only datosfreak. An archive holds DATOS2 rows, so it must
    // survive that filter or a prior year renders empty.
    const excluded = [
      "EFECTIVO",
      "EFECTIVO_BACKUP",
      "EFECTIVO FM3",
      "CHEQUE FM3",
      "IVA 2015",
    ];
    expect(excluded).not.toContain(periodSourceTable(2025));
  });
});
