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

import { getCdcIssueMatrixIssues } from "./cdc-issue-matrix-service";

test("maps the CDC remark into the frontend row", async () => {
  const originalFetch = globalThis.fetch;

  globalThis.fetch = async () =>
    new Response(
      JSON.stringify({
        success: true,
        statusCode: 200,
        message: "OK",
        data: [
          {
            issueId: 1,
            issueResolveId: 2,
            meetingSummaryId: 3,
            title: "Issue",
            description: "Description",
            recommendation: "Recommendation",
            category: { id: 1, name: "Category" },
            status: { id: 1, code: "IN_PROGRESS", name: "In Progress" },
            workingGroup: { id: 1, name: "Working Group" },
            primaryAgency: null,
            rgcDecision: null,
            nextStep: null,
            remark: "Follow up with the ministry",
            submittedAt: "2026-07-06T00:00:00.000Z",
          },
        ],
        meta: { page: 1, limit: 50, total: 1, totalPages: 1 },
      }),
      { status: 200, headers: { "Content-Type": "application/json" } },
    );

  try {
    const rows = await getCdcIssueMatrixIssues();

    assert.equal(
      (rows[0] as unknown as { remark?: string }).remark,
      "Follow up with the ministry",
    );
  } finally {
    globalThis.fetch = originalFetch;
  }
});
