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
202 lines
9.3 KiB
TypeScript
202 lines
9.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
|
|
import { KycReviewDrawer } from "./KycReviewDrawer";
|
|
import { actOnKyc, getKycDetail, kycDocUrl } from "@/app/lib/services/adminKyc";
|
|
import { ApiError } from "@/app/lib/clientApi";
|
|
import type { AdminKycDetail, AdminKycRow } from "@/app/lib/types";
|
|
|
|
vi.mock("@/app/lib/services/adminKyc");
|
|
|
|
const record = (over: Partial<AdminKycRow> = {}): AdminKycRow => ({
|
|
uuid: "111",
|
|
memberCode: "MY3619941",
|
|
submitName: "TAN MEI LING",
|
|
identityType: "MYKAD",
|
|
identityNo: "900101145678",
|
|
status: "P",
|
|
submitChannel: "MEMBER",
|
|
submittedBy: "MY3619941",
|
|
createDateTime: "2026-09-22T10:14:00",
|
|
actionBy: null,
|
|
actionAt: null,
|
|
actionRemarks: null,
|
|
...over,
|
|
});
|
|
|
|
const detail = (over: Partial<AdminKycRow> = {}, warnings: string[] = []): AdminKycDetail => ({
|
|
record: record(over),
|
|
docTypes: ["ID_FRONT", "ID_BACK", "SELFIE"],
|
|
member: {
|
|
memberCode: "MY3619941",
|
|
name: "Tan Mei Ling",
|
|
email: "meiling@example.com",
|
|
phoneNoPrefix: "+60",
|
|
phoneNo: "123456789",
|
|
identityType: null,
|
|
identityNo: null,
|
|
passportNo: null,
|
|
kycFlag: "N",
|
|
},
|
|
history: [record(over)],
|
|
warnings,
|
|
});
|
|
|
|
const props = () => ({ uuid: "111", onClose: vi.fn(), onChanged: vi.fn(), onNavigate: vi.fn() });
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(getKycDetail).mockReset();
|
|
vi.mocked(actOnKyc).mockReset();
|
|
vi.mocked(kycDocUrl).mockImplementation((uuid, doc) => `/api/admin/kyc/${uuid}/doc/${doc}`);
|
|
});
|
|
|
|
describe("KycReviewDrawer", () => {
|
|
it("renders documents, the submitted-vs-profile comparison and warnings for a pending record", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(
|
|
detail({}, ["ID_IN_USE_BY:MY1200087", "PREVIOUSLY_REJECTED:2026-09-20:Selfie is blurry"]),
|
|
);
|
|
render(<KycReviewDrawer {...props()} />);
|
|
const front = await screen.findByRole("button", { name: "ID front" });
|
|
expect(front.querySelector("img")).toHaveAttribute("src", "/api/admin/kyc/111/doc/ID_FRONT");
|
|
expect(screen.getByRole("button", { name: "ID back" })).toBeInTheDocument();
|
|
expect(screen.getByText("900101-14-5678")).toBeInTheDocument();
|
|
expect(screen.getAllByText(/22 Sep 2026, 10:14/).length).toBeGreaterThan(0);
|
|
expect(screen.getByText("This ID number is also used by MY1200087.")).toBeInTheDocument();
|
|
expect(screen.getByText("Rejected on 20 Sep 2026 — “Selfie is blurry”")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the member's phone as +prefix number, whether the prefix is stored with or without +", async () => {
|
|
// Live members store the bare "60"; the drawer showed it as "60 123456789".
|
|
for (const phoneNoPrefix of ["60", "+60"]) {
|
|
const d = detail();
|
|
d.member.phoneNoPrefix = phoneNoPrefix;
|
|
vi.mocked(getKycDetail).mockResolvedValue(d);
|
|
const { unmount } = render(<KycReviewDrawer {...props()} />);
|
|
expect(await screen.findByText("+60 123456789")).toBeInTheDocument();
|
|
unmount();
|
|
}
|
|
});
|
|
|
|
it("refuses to reject without remarks and never calls the API", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
render(<KycReviewDrawer {...props()} />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Reject" }));
|
|
expect(await screen.findByText("Please enter a reason.")).toBeInTheDocument();
|
|
expect(actOnKyc).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("approves without remarks, tells the page to reload, and shows the new state", async () => {
|
|
const p = props();
|
|
vi.mocked(getKycDetail).mockResolvedValueOnce(detail()).mockResolvedValue(detail({ status: "A", actionBy: "admin" }));
|
|
vi.mocked(actOnKyc).mockResolvedValue(record({ status: "A" }));
|
|
render(<KycReviewDrawer {...p} />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Approve" }));
|
|
await waitFor(() => expect(actOnKyc).toHaveBeenCalledWith("111", "approve", ""));
|
|
expect(p.onChanged).toHaveBeenCalled();
|
|
expect(await screen.findByRole("button", { name: "Revoke…" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("rejects with trimmed remarks", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
vi.mocked(actOnKyc).mockResolvedValue(record({ status: "R" }));
|
|
render(<KycReviewDrawer {...props()} />);
|
|
fireEvent.change(await screen.findByLabelText(/Remarks/), { target: { value: " Selfie is blurry " } });
|
|
fireEvent.click(screen.getByRole("button", { name: "Reject" }));
|
|
await waitFor(() => expect(actOnKyc).toHaveBeenCalledWith("111", "reject", "Selfie is blurry"));
|
|
});
|
|
|
|
it("a 409 says another admin already acted and reloads the record", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValueOnce(detail()).mockResolvedValue(detail({ status: "R", actionBy: "ops.lee" }));
|
|
vi.mocked(actOnKyc).mockRejectedValue(new ApiError("KYC_ALREADY_ACTIONED", 409));
|
|
render(<KycReviewDrawer {...props()} />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Approve" }));
|
|
expect(await screen.findByText(/Someone already actioned this record/)).toBeInTheDocument();
|
|
expect(getKycDetail).toHaveBeenCalledTimes(2);
|
|
expect(screen.queryByRole("button", { name: "Approve" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("an approved record offers only revoke, which requires a reason", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail({ status: "A", actionBy: "admin" }));
|
|
render(<KycReviewDrawer {...props()} />);
|
|
const toggle = await screen.findByRole("button", { name: "Revoke…" });
|
|
expect(toggle).toHaveAttribute("aria-expanded", "false");
|
|
expect(screen.queryByLabelText("Reason (required)")).not.toBeInTheDocument();
|
|
fireEvent.click(toggle);
|
|
expect(toggle).toHaveAttribute("aria-expanded", "true");
|
|
fireEvent.click(screen.getByRole("button", { name: "Revoke" }));
|
|
expect(await screen.findByText("Please enter a reason.")).toBeInTheDocument();
|
|
expect(actOnKyc).not.toHaveBeenCalled();
|
|
expect(screen.queryByRole("button", { name: "Approve" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("rejected and revoked records are read-only", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail({ status: "R", actionRemarks: "blurry" }));
|
|
render(<KycReviewDrawer {...props()} />);
|
|
await screen.findByRole("button", { name: "ID front" });
|
|
for (const name of ["Approve", "Reject", "Revoke", "Revoke…"]) {
|
|
expect(screen.queryByRole("button", { name })).not.toBeInTheDocument();
|
|
}
|
|
});
|
|
|
|
it("opens the document viewer, which zooms and rotates", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
render(<KycReviewDrawer {...props()} />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "ID front" }));
|
|
const full = await screen.findByTestId("kyc-doc-full");
|
|
fireEvent.click(screen.getByRole("button", { name: "Rotate" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Zoom in" }));
|
|
expect(full.style.transform).toBe("scale(1.5) rotate(90deg)");
|
|
});
|
|
|
|
it("prev/next ask the page to move through the queue", async () => {
|
|
const p = props();
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
render(<KycReviewDrawer {...p} />);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Next" }));
|
|
expect(p.onNavigate).toHaveBeenCalledWith(1);
|
|
});
|
|
|
|
it("renders exactly two document tiles and no selfie when docTypes include SELFIE", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
const { container } = render(<KycReviewDrawer {...props()} />);
|
|
const front = await screen.findByRole("button", { name: "ID front" });
|
|
const tiles = front.parentElement!.querySelectorAll("button");
|
|
expect([...tiles].map(b => b.textContent)).toEqual(["ID front", "ID back"]);
|
|
expect(container.ownerDocument.querySelector('img[src$="/SELFIE"]')).toBeNull();
|
|
});
|
|
|
|
it("shows detail rows in order: Name on ID, ID type, ID number, Email, Phone, with Phone last", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
render(<KycReviewDrawer {...props()} />);
|
|
// DrawerSection: <section> → <h3>Submitted details</h3> → <div.border>DetailRows</div>
|
|
const h3 = await screen.findByText("Submitted details");
|
|
const section = h3.closest("section")!;
|
|
const borderDiv = section.querySelector<HTMLElement>("[class*=border]")!;
|
|
const text = borderDiv.textContent!;
|
|
const labels = ["Name on ID", "ID type", "ID number", "Email", "Phone"];
|
|
let lastIdx = -1;
|
|
for (const label of labels) {
|
|
const idx = text.indexOf(label);
|
|
expect(idx).toBeGreaterThan(lastIdx);
|
|
lastIdx = idx;
|
|
}
|
|
const rows = [...borderDiv.children];
|
|
expect(rows.map(r => r.children.length)).toEqual([2, 2, 2, 2, 2]);
|
|
expect(rows.at(-1)!.firstElementChild!.textContent).toBe("Phone");
|
|
});
|
|
|
|
it("renders email in lowercase", async () => {
|
|
const d = detail();
|
|
d.member.email = "TESTING123@GMAIL.COM";
|
|
vi.mocked(getKycDetail).mockResolvedValue(d);
|
|
render(<KycReviewDrawer {...props()} />);
|
|
expect(await screen.findByText("testing123@gmail.com")).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render a member-profile column", async () => {
|
|
vi.mocked(getKycDetail).mockResolvedValue(detail());
|
|
render(<KycReviewDrawer {...props()} />);
|
|
await screen.findByText("Submitted details");
|
|
expect(screen.queryByText(/Member profile|KycProfile$/)).not.toBeInTheDocument();
|
|
});
|
|
});
|