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
74 lines
2.5 KiB
TypeScript
74 lines
2.5 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 {
|
|
getNetworkTree,
|
|
getMemberUpline,
|
|
getPlacementHistory,
|
|
changeSponsor,
|
|
directDownline,
|
|
totalDownline,
|
|
} from "./network";
|
|
import type { AdminTreeNode } from "@/app/lib/types";
|
|
|
|
const root: AdminTreeNode = {
|
|
mbid: "BB0100",
|
|
member: { memberCode: "BB0100", name: "AINA TAN", rank: "OTTER", status: "Y" },
|
|
children: [
|
|
{
|
|
mbid: "BB0101",
|
|
member: { memberCode: "BB0101", name: "WEI MING LEE", rank: "SQUIRREL", status: "Y" },
|
|
children: [{ mbid: "BB0110", member: { memberCode: "BB0110", name: "NURUL" } }],
|
|
},
|
|
{ mbid: "BB0102", member: { memberCode: "BB0102", name: "SITI AMINAH", rank: "M", status: "S" } },
|
|
],
|
|
};
|
|
|
|
beforeEach(() => {
|
|
mocks.apiGet.mockReset();
|
|
mocks.apiPost.mockReset();
|
|
});
|
|
|
|
describe("network tree reads", () => {
|
|
it("fetches the tree rooted at the member code", async () => {
|
|
mocks.apiGet.mockResolvedValue(root);
|
|
const tree = await getNetworkTree("BB0100");
|
|
expect(tree.mbid).toBe("BB0100");
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/admin/network/BB0100?level=99");
|
|
});
|
|
|
|
it("fetches the upline chain", async () => {
|
|
mocks.apiGet.mockResolvedValue([]);
|
|
await getMemberUpline("BB0100");
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/admin/network/BB0100/upline");
|
|
});
|
|
|
|
it("fetches the placement history", async () => {
|
|
mocks.apiGet.mockResolvedValue({ content: [], totalElements: 0 });
|
|
await getPlacementHistory("BB0100");
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/admin/members/BB0100/placement-history");
|
|
});
|
|
});
|
|
|
|
describe("changeSponsor", () => {
|
|
it("posts the new sponsor code and the reason, and never an actor", async () => {
|
|
mocks.apiPost.mockResolvedValue({ success: true });
|
|
await changeSponsor("BB0100", "BB0001", "Wrong referral code");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/admin/members/BB0100/change-sponsor", {
|
|
newSponsorCode: "BB0001",
|
|
reason: "Wrong referral code",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("downline counts", () => {
|
|
it("direct = children; total = everyone beneath at any depth", () => {
|
|
expect(directDownline(root)).toBe(2);
|
|
expect(totalDownline(root)).toBe(3);
|
|
expect(directDownline(root.children![0])).toBe(1);
|
|
expect(totalDownline(root.children![0])).toBe(1);
|
|
});
|
|
});
|