import test from "node:test";
import assert from "node:assert/strict";

import { isLicenseUploadRequired } from "@/data/orgTypes";

/*
 * The client's rule, 2026-10-05: the licence upload is optional for تعليمي،
 * حكومي and مجتمع, and required for every other organization type. This
 * reverses the 2026-09-27 rule, under which only a volunteer team had to
 * upload one — which is exactly why it is pinned here.
 */

test("optional for the three exempt types", () => {
  for (const type of ["Educational", "Governmental", "Community"]) {
    assert.equal(
      isLicenseUploadRequired(type),
      false,
      `${type} must be able to register without a licence file`
    );
  }
});

test("every earlier name of those three types is exempt too", () => {
  // A cached /choices/org_type/ response, or a record written before a backend
  // rename, must land on the same answer as a fresh one.
  for (const type of ["Education", "Institution", "Public"]) {
    assert.equal(isLicenseUploadRequired(type), false, type);
  }
});

test("required for every other type", () => {
  for (const type of [
    "Commercial",
    "NonProfit",
    "NGO",
    "Association",
    "Society",
    "Volunteer Team",
  ]) {
    assert.equal(
      isLicenseUploadRequired(type),
      true,
      `${type} must be asked for a licence file`
    );
  }
});

test("the 2026-09-27 rule is genuinely reversed", () => {
  // Under the old rule this pair was true/false. Asserting both directions so
  // a revert cannot pass by accident.
  assert.equal(isLicenseUploadRequired("Volunteer Team"), true);
  assert.equal(isLicenseUploadRequired("Commercial"), true);
});

test("matching ignores case and surrounding space", () => {
  for (const type of ["  educational ", "GOVERNMENTAL", "cOmMuNiTy"]) {
    assert.equal(isLicenseUploadRequired(type), false, JSON.stringify(type));
  }
});

test("an unknown or missing type is required, not exempt", () => {
  // The safe direction: a licence asked for in error is a question the
  // applicant can raise; one skipped in error reaches approval unverifiable.
  for (const type of [undefined, null, "", "   ", "Cooperative", "Startup"]) {
    assert.equal(isLicenseUploadRequired(type), true, JSON.stringify(type));
  }
});
