Files
co-lite/solvway-admin-portal/app/lib/services/adminDashboard.actions.test.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
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
2026-11-26 15:55:45 +08:00

75 lines
3.6 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const m = vi.hoisted(() => ({
getKycCounts: vi.fn(),
listRefunds: vi.fn(),
listWarrantyClaims: vi.fn(),
listReviews: vi.fn(),
getPendingWithdrawals: vi.fn(),
listWebOrders: vi.fn(),
}));
vi.mock("./adminKyc", () => ({ getKycCounts: m.getKycCounts }));
vi.mock("./adminRefunds", () => ({ listRefunds: m.listRefunds }));
vi.mock("./adminWarranty", () => ({ listWarrantyClaims: m.listWarrantyClaims }));
vi.mock("./adminProductReviews", () => ({ listReviews: m.listReviews }));
vi.mock("./adminWithdrawals", () => ({ getPendingWithdrawals: m.getPendingWithdrawals }));
vi.mock("./adminWebOrders", () => ({ listWebOrders: m.listWebOrders }));
import * as dash from "./adminDashboard";
const getActionCounts = (dash as unknown as {
getActionCounts: (can: (r: string) => boolean) => Promise<{ key: string; href: string; labelCode: string; count: number }[]>;
}).getActionCounts;
beforeEach(() => {
Object.values(m).forEach(f => f.mockReset());
m.getKycCounts.mockResolvedValue({ P: 3 });
m.listRefunds.mockResolvedValue({ pendingCount: 4 });
m.listWarrantyClaims.mockResolvedValue({ totalElements: 2 });
m.listReviews.mockResolvedValue({ totalElements: 5 });
m.getPendingWithdrawals.mockResolvedValue({ totalElements: 6 });
m.listWebOrders.mockResolvedValue({ totalElements: 7 });
});
describe("getActionCounts", () => {
it("returns every item in table order with href, label code and count", async () => {
expect(await getActionCounts(() => true)).toEqual([
{ key: "kyc", href: "/members/knowYourCustomer", labelCode: "DashActKyc", count: 3 },
{ key: "refunds", href: "/orders/refunds", labelCode: "DashActRefunds", count: 4 },
{ key: "warranty", href: "/orders/warranty-claims", labelCode: "DashActWarranty", count: 2 },
{ key: "reviews", href: "/product-reviews", labelCode: "DashActReviews", count: 5 },
{ key: "withdrawals", href: "/wallet/withdrawals", labelCode: "DashActWithdrawals", count: 6 },
{ key: "staleOrders", href: "/orders/web?status=STALE", labelCode: "DashActStaleOrders", count: 7 },
]);
});
it("asks each source for pending, one row", async () => {
await getActionCounts(() => true);
expect(m.listRefunds).toHaveBeenCalledWith(expect.objectContaining({ status: "P", size: 1 }));
expect(m.listWarrantyClaims).toHaveBeenCalledWith(expect.objectContaining({ status: "P", size: 1 }));
expect(m.listReviews).toHaveBeenCalledWith(expect.objectContaining({ status: "P", size: 1 }));
expect(m.getPendingWithdrawals.mock.calls[0][1]).toBe(1);
expect(m.listWebOrders).toHaveBeenCalledWith(expect.objectContaining({ stalePending: true, size: 1 }));
});
it("calls only the sources whose route is allowed", async () => {
const res = await getActionCounts(r => r === "/orders/refunds" || r === "/orders/web");
expect(res.map(i => i.key)).toEqual(["refunds", "staleOrders"]);
expect(m.getKycCounts).not.toHaveBeenCalled();
expect(m.listWarrantyClaims).not.toHaveBeenCalled();
expect(m.listReviews).not.toHaveBeenCalled();
expect(m.getPendingWithdrawals).not.toHaveBeenCalled();
});
it("makes no request when nothing is allowed", async () => {
expect(await getActionCounts(() => false)).toEqual([]);
Object.values(m).forEach(f => expect(f).not.toHaveBeenCalled());
});
it("leaves out a rejected source and keeps the rest in order", async () => {
m.listRefunds.mockRejectedValue(new Error("boom"));
const res = await getActionCounts(() => true);
expect(res.map(i => i.key)).toEqual(["kyc", "warranty", "reviews", "withdrawals", "staleOrders"]);
});
});