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

import { getDefaultProfileImage } from "@/lib/helpers";

const MALE = "/assets/profile/male_profile.svg";
const FEMALE = "/assets/profile/female_profile.svg";
const ORG = "/assets/profile/org_profile.svg";

const pick = (gender: string | null | undefined) =>
  getDefaultProfileImage(gender, MALE, FEMALE, ORG);

test("the values production actually returns", () => {
  // Verified live against /api/choices/gender/ on 2026-10-05.
  assert.equal(pick("Male"), MALE);
  assert.equal(pick("Female"), FEMALE);
});

test("case and surrounding space do not decide the avatar", () => {
  for (const value of ["male", "MALE", " Male ", "mAlE"]) {
    assert.equal(pick(value), MALE, JSON.stringify(value));
  }
  for (const value of ["female", "FEMALE", " Female "]) {
    assert.equal(pick(value), FEMALE, JSON.stringify(value));
  }
});

test("an unknown, missing or empty gender falls back", () => {
  // Which is also the correct mark for an organization: gender hangs off the
  // volunteer profile, so an organization has none.
  for (const value of [undefined, null, "", "   ", "Other", "ذكر"]) {
    assert.equal(pick(value), ORG, JSON.stringify(value));
  }
});

test("'female' is not matched by the 'male' branch", () => {
  // Guards against a future `includes`/`startsWith` rewrite: "female"
  // contains "male".
  assert.notEqual(pick("female"), MALE);
});
