/**
 * PDF p.12 — the development «النوع» filter. On the mixed /opportunities page
 * the dropdown is the `filter-type` catalog, which the development endpoint
 * ignores (except «Volunteer»), so it is translated to `learning_type_id`.
 */
import { test } from "node:test";
import assert from "node:assert/strict";

import { learningTypeIdForFilterType } from "@/features/opportunities/components/opportunityTypeOptions";

const choice = (id: number, value_en: string) => ({ id, value_en, value_ar: value_en });
const filterTypes = [
  choice(1, "Volunteer"),
  choice(2, "Course"),
  choice(3, "Class"),
  choice(4, "Internship"),
  choice(5, "Consultation"),
];
const learningTypes = [
  choice(40, "Course"),
  choice(41, "Class/Workshop"),
  choice(42, "Consultation"),
  choice(43, "Internship"),
];

test("each development filter-type maps to its learning type id", () => {
  assert.equal(learningTypeIdForFilterType("2", filterTypes, learningTypes), "40");
  assert.equal(learningTypeIdForFilterType(3, filterTypes, learningTypes), "41");
  assert.equal(learningTypeIdForFilterType("4", filterTypes, learningTypes), "43");
  assert.equal(learningTypeIdForFilterType("5", filterTypes, learningTypes), "42");
});

test("«Volunteer», no choice, or unloaded lists send nothing", () => {
  assert.equal(learningTypeIdForFilterType("1", filterTypes, learningTypes), undefined);
  assert.equal(learningTypeIdForFilterType(undefined, filterTypes, learningTypes), undefined);
  assert.equal(learningTypeIdForFilterType("2", undefined, learningTypes), undefined);
  assert.equal(learningTypeIdForFilterType("2", filterTypes, undefined), undefined);
});
