Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
169 lines
5.6 KiB
TypeScript
169 lines
5.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import * as XLSX from "xlsx";
|
|
import { buildKycWorkbook, kycExportFileName } from "./kycExport";
|
|
import type { AdminKycRow } from "@/app/lib/types";
|
|
|
|
const ROWS: AdminKycRow[] = [
|
|
{
|
|
uuid: "1001",
|
|
memberCode: "BB0100",
|
|
submitName: "Ahmad bin Ali",
|
|
identityType: "MYKAD",
|
|
identityNo: "880101-01-1234",
|
|
status: "A",
|
|
submitChannel: "MEMBER",
|
|
submittedBy: "BB0100",
|
|
createDateTime: "2025-06-01T10:30:00",
|
|
actionBy: "admin01",
|
|
actionAt: "2025-06-02T09:00:00",
|
|
actionRemarks: "Verified OK",
|
|
},
|
|
{
|
|
uuid: "1002",
|
|
memberCode: "BB0200",
|
|
submitName: "Lee Wei Ming",
|
|
identityType: "PASSPORT",
|
|
identityNo: "E12345678",
|
|
status: "P",
|
|
submitChannel: "ADMIN",
|
|
submittedBy: "admin02",
|
|
createDateTime: "2025-06-03T14:00:00",
|
|
actionBy: null,
|
|
actionAt: null,
|
|
actionRemarks: null,
|
|
},
|
|
{
|
|
uuid: "1003",
|
|
memberCode: "BB0300",
|
|
submitName: "Siti binti Abu",
|
|
identityType: "MYKAD",
|
|
identityNo: "900202-02-5678",
|
|
status: "R",
|
|
submitChannel: "MEMBER",
|
|
submittedBy: "BB0300",
|
|
createDateTime: "2025-06-04T08:00:00",
|
|
actionBy: "admin01",
|
|
actionAt: "2025-06-05T11:00:00",
|
|
actionRemarks: "Document unclear",
|
|
},
|
|
];
|
|
|
|
describe("buildKycWorkbook", () => {
|
|
it("creates a workbook with a 'KYC' sheet", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
expect(wb.SheetNames).toContain("KYC");
|
|
});
|
|
|
|
it("has the correct header row in the correct order", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
const rows = XLSX.utils.sheet_to_json<string[]>(wb.Sheets["KYC"], { header: 1 });
|
|
expect(rows[0]).toEqual([
|
|
"Member",
|
|
"Name on ID",
|
|
"ID type",
|
|
"ID number",
|
|
"Status",
|
|
"Channel",
|
|
"Submitted by",
|
|
"Submitted at",
|
|
"Actioned by",
|
|
"Actioned at",
|
|
"Remarks",
|
|
]);
|
|
});
|
|
|
|
it("renders status codes as human-readable labels", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
const rows = XLSX.utils.sheet_to_json<Record<string, unknown>>(wb.Sheets["KYC"]);
|
|
expect(rows[0]["Status"]).toBe("Approved");
|
|
expect(rows[1]["Status"]).toBe("Pending");
|
|
expect(rows[2]["Status"]).toBe("Rejected");
|
|
});
|
|
|
|
it("populates data rows correctly", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
const rows = XLSX.utils.sheet_to_json<Record<string, unknown>>(wb.Sheets["KYC"]);
|
|
expect(rows).toHaveLength(ROWS.length);
|
|
expect(rows[0]["Member"]).toBe("BB0100");
|
|
expect(rows[0]["Name on ID"]).toBe("Ahmad bin Ali");
|
|
expect(rows[0]["ID type"]).toBe("MYKAD");
|
|
expect(rows[0]["ID number"]).toBe("880101-01-1234");
|
|
expect(rows[0]["Channel"]).toBe("MEMBER");
|
|
expect(rows[0]["Submitted by"]).toBe("BB0100");
|
|
});
|
|
|
|
it("renders null action fields as blank cells", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
const rows = XLSX.utils.sheet_to_json<Record<string, unknown>>(wb.Sheets["KYC"], { defval: "" });
|
|
// Row 2 (Lee Wei Ming) has no action fields
|
|
expect(rows[1]["Actioned by"]).toBe("");
|
|
expect(rows[1]["Actioned at"]).toBe("");
|
|
expect(rows[1]["Remarks"]).toBe("");
|
|
});
|
|
|
|
it("returns a valid Uint8Array that forms a proper xlsx file", async () => {
|
|
const bytes = await buildKycWorkbook(ROWS);
|
|
expect(bytes).toBeInstanceOf(Uint8Array);
|
|
expect(bytes.byteLength).toBeGreaterThan(50);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
expect(wb.SheetNames).toContain("KYC");
|
|
});
|
|
|
|
it("returns an empty workbook when rows is empty", async () => {
|
|
const bytes = await buildKycWorkbook([]);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
expect(wb.SheetNames).toContain("KYC");
|
|
const rows = XLSX.utils.sheet_to_json<Record<string, unknown>>(wb.Sheets["KYC"]);
|
|
expect(rows).toHaveLength(0);
|
|
});
|
|
|
|
it("includes Revoked status mapping", async () => {
|
|
const revokedRow: AdminKycRow = {
|
|
uuid: "1004",
|
|
memberCode: "BB0400",
|
|
submitName: "Tan Mei Ling",
|
|
identityType: "MYKAD",
|
|
identityNo: "950303-03-9999",
|
|
status: "V",
|
|
submitChannel: "MEMBER",
|
|
submittedBy: "BB0400",
|
|
createDateTime: "2025-06-06T10:00:00",
|
|
actionBy: "admin01",
|
|
actionAt: "2025-06-07T12:00:00",
|
|
actionRemarks: "Revoke test",
|
|
};
|
|
const bytes = await buildKycWorkbook([revokedRow]);
|
|
const wb = XLSX.read(bytes, { type: "array" });
|
|
const rows = XLSX.utils.sheet_to_json<Record<string, unknown>>(wb.Sheets["KYC"]);
|
|
expect(rows[0]["Status"]).toBe("Revoked");
|
|
});
|
|
});
|
|
|
|
describe("kycExportFileName", () => {
|
|
it("returns kyc-YYYYMMDD-HHmm.xlsx", () => {
|
|
const date = new Date(2025, 5, 15, 14, 30);
|
|
expect(kycExportFileName(date)).toBe("kyc-20250615-1430.xlsx");
|
|
});
|
|
|
|
it("zero-pads month, day, hour, minute correctly", () => {
|
|
const date = new Date(2025, 0, 1, 9, 5);
|
|
expect(kycExportFileName(date)).toBe("kyc-20250101-0905.xlsx");
|
|
});
|
|
|
|
it("uses the current date when now is a Date instance", () => {
|
|
const now = new Date();
|
|
const result = kycExportFileName(now);
|
|
const year = now.getFullYear();
|
|
const mm = String(now.getMonth() + 1).padStart(2, "0");
|
|
const dd = String(now.getDate()).padStart(2, "0");
|
|
const HH = String(now.getHours()).padStart(2, "0");
|
|
const MM = String(now.getMinutes()).padStart(2, "0");
|
|
expect(result).toBe(`kyc-${year}${mm}${dd}-${HH}${MM}.xlsx`);
|
|
});
|
|
});
|