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
129 lines
4.2 KiB
TypeScript
129 lines
4.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
apiGet: vi.fn(),
|
|
apiPost: vi.fn(),
|
|
}));
|
|
vi.mock("@/app/lib/clientApi", () => ({
|
|
apiGet: mocks.apiGet,
|
|
apiPost: mocks.apiPost,
|
|
}));
|
|
|
|
import {
|
|
listKyc,
|
|
getKycCounts,
|
|
getKycDetail,
|
|
kycDocUrl,
|
|
actOnKyc,
|
|
exportKyc,
|
|
uploadKycDocForMember,
|
|
submitKycForMember,
|
|
} from "./adminKyc";
|
|
import type { AdminKycFilters } from "@/app/lib/types";
|
|
|
|
beforeEach(() => {
|
|
mocks.apiGet.mockReset();
|
|
mocks.apiPost.mockReset();
|
|
});
|
|
|
|
describe("listKyc", () => {
|
|
it("calls GET /api/admin/kyc with 0-based page and forwards filters", async () => {
|
|
mocks.apiGet.mockResolvedValue({ content: [], totalElements: 0, page: 0, size: 20 });
|
|
|
|
const filters: AdminKycFilters = { status: "P", q: "ahmad", from: "2025-01-01", to: "2025-12-31", channel: "MEMBER" };
|
|
|
|
await listKyc(filters, 1, 20);
|
|
|
|
expect(mocks.apiGet).toHaveBeenCalledWith(
|
|
"/api/admin/kyc?status=P&q=ahmad&from=2025-01-01&to=2025-12-31&channel=MEMBER&page=0&size=20",
|
|
);
|
|
});
|
|
|
|
it("converts 1-based UI page to 0-based (page=2 → page=1)", async () => {
|
|
await listKyc({ status: "ALL", q: "", from: "", to: "", channel: "" }, 2, 10);
|
|
|
|
const [path] = mocks.apiGet.mock.calls[0];
|
|
expect(path).toContain("page=1");
|
|
expect(path).toContain("size=10");
|
|
});
|
|
});
|
|
|
|
describe("getKycCounts", () => {
|
|
it("calls GET /api/admin/kyc/counts", async () => {
|
|
mocks.apiGet.mockResolvedValue({ P: 5, A: 10, R: 2, V: 1, ALL: 18 });
|
|
await getKycCounts();
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/admin/kyc/counts");
|
|
});
|
|
});
|
|
|
|
describe("getKycDetail", () => {
|
|
it("calls GET /api/admin/kyc/<uuid>", async () => {
|
|
mocks.apiGet.mockResolvedValue({ record: {} as any, docTypes: [], member: {} as any, history: [], warnings: [] });
|
|
await getKycDetail("12345");
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/admin/kyc/12345");
|
|
});
|
|
});
|
|
|
|
describe("kycDocUrl", () => {
|
|
it("returns the correct URL path", () => {
|
|
expect(kycDocUrl("12345", "ID_FRONT")).toBe("/api/admin/kyc/12345/doc/ID_FRONT");
|
|
expect(kycDocUrl("99", "SELFIE")).toBe("/api/admin/kyc/99/doc/SELFIE");
|
|
});
|
|
});
|
|
|
|
describe("actOnKyc", () => {
|
|
it("calls POST /api/admin/kyc/<uuid>/action with action and remarks", async () => {
|
|
mocks.apiPost.mockResolvedValue({ uuid: "12345" } as any);
|
|
await actOnKyc("12345", "approve", "");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/admin/kyc/12345/action", { action: "approve", remarks: "" });
|
|
});
|
|
|
|
it("reject uses action=reject", async () => {
|
|
await actOnKyc("12345", "reject", "Document expired");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/admin/kyc/12345/action", { action: "reject", remarks: "Document expired" });
|
|
});
|
|
});
|
|
|
|
describe("exportKyc", () => {
|
|
it("calls GET /api/admin/kyc/export with filter params", async () => {
|
|
mocks.apiGet.mockResolvedValue([]);
|
|
await exportKyc({ status: "A", q: "", from: "", to: "", channel: "" });
|
|
const [path] = mocks.apiGet.mock.calls[0];
|
|
expect(path).toContain("/api/admin/kyc/export");
|
|
expect(path).toContain("status=A");
|
|
});
|
|
});
|
|
|
|
describe("uploadKycDocForMember", () => {
|
|
it("calls POST /api/admin/kyc/upload", async () => {
|
|
mocks.apiPost.mockResolvedValue({ reference: "ref-123" });
|
|
await uploadKycDocForMember("BB0100", "ID_FRONT", "jpg", "base64data");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/admin/kyc/upload", {
|
|
memberCode: "BB0100",
|
|
docType: "ID_FRONT",
|
|
fileType: "jpg",
|
|
base: "base64data",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("submitKycForMember", () => {
|
|
it("calls POST /api/admin/kyc/submit with the full body", async () => {
|
|
mocks.apiPost.mockResolvedValue({ uuid: "999" } as any);
|
|
await submitKycForMember({
|
|
memberCode: "BB0100",
|
|
submitName: "Ahmad",
|
|
identityType: "MYKAD",
|
|
identityNo: "880101-01-1234",
|
|
docs: { ID_FRONT: "kyc/BB0100/a.jpg", ID_BACK: "kyc/BB0100/b.jpg" },
|
|
});
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/admin/kyc/submit", {
|
|
memberCode: "BB0100",
|
|
submitName: "Ahmad",
|
|
identityType: "MYKAD",
|
|
identityNo: "880101-01-1234",
|
|
docs: { ID_FRONT: "kyc/BB0100/a.jpg", ID_BACK: "kyc/BB0100/b.jpg" },
|
|
});
|
|
});
|
|
});
|