Files
co-lite/solvway-admin-portal/app/lib/services/adminPromotions.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

72 lines
2.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({ apiGet: vi.fn() }));
vi.mock("@/app/lib/clientApi", () => ({
apiGet: (...a: unknown[]) => mocks.apiGet(...a),
apiPost: vi.fn(),
apiPut: vi.fn(),
}));
import { listCampaigns, listRedemptions, listVouchers } from "./adminPromotions";
const lastUrl = () => new URL(String(mocks.apiGet.mock.calls.at(-1)?.[0]), "http://x");
describe("BABYBOO-59 service filter params", () => {
beforeEach(() => {
mocks.apiGet.mockReset();
mocks.apiGet.mockResolvedValue({ content: [] });
});
it("listCampaigns sends q, benefitType, claimType, channel, from, to when set", async () => {
await listCampaigns(0, 20, {
q: "summer sale",
benefitType: "GIFT",
claimType: "UNIQUE_CODE",
channel: "EVENT",
from: "2026-01-01",
to: "2026-02-01",
} as never);
const u = lastUrl();
expect(u.pathname).toBe("/api/promotions/campaigns");
expect(Object.fromEntries(u.searchParams)).toMatchObject({
q: "summer sale",
benefitType: "GIFT",
claimType: "UNIQUE_CODE",
channel: "EVENT",
from: "2026-01-01",
to: "2026-02-01",
});
});
it("listCampaigns omits the new params when unset or empty", async () => {
await listCampaigns(0, 20, { status: "ACTIVE", q: "", benefitType: undefined } as never);
const u = lastUrl();
for (const k of ["q", "benefitType", "claimType", "channel", "from", "to"]) expect(u.searchParams.has(k)).toBe(false);
expect(u.searchParams.get("status")).toBe("ACTIVE");
});
it("listRedemptions sends invoiceNo, member and channel when set", async () => {
await listRedemptions(0, 20, { invoiceNo: "IN0001", member: "MY1", channel: "OUTLET" } as never);
expect(Object.fromEntries(lastUrl().searchParams)).toMatchObject({ invoiceNo: "IN0001", member: "MY1", channel: "OUTLET" });
});
it("listRedemptions omits the new params when unset", async () => {
await listRedemptions(0, 20, { status: "COMMITTED" });
const u = lastUrl();
for (const k of ["invoiceNo", "member", "channel"]) expect(u.searchParams.has(k)).toBe(false);
});
it("listVouchers sends member, code and invoiceNo when set", async () => {
await listVouchers("C-1", 0, 20, { member: "Irene", code: "AB12", invoiceNo: "IN2" } as never);
const u = lastUrl();
expect(u.pathname).toBe("/api/promotions/campaigns/C-1/vouchers");
expect(Object.fromEntries(u.searchParams)).toMatchObject({ member: "Irene", code: "AB12", invoiceNo: "IN2" });
});
it("listVouchers omits the new params when unset", async () => {
await listVouchers("C-1", 0, 20, { status: "USED" });
const u = lastUrl();
for (const k of ["member", "code", "invoiceNo"]) expect(u.searchParams.has(k)).toBe(false);
});
});