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
144 lines
6.3 KiB
TypeScript
144 lines
6.3 KiB
TypeScript
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
import * as XLSX from "xlsx";
|
|
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
|
|
import { m, tCode } from "@/test/i18nCatalog";
|
|
import type { CampaignInput, OnlinePaymentRow } from "@/app/lib/types";
|
|
import { PAYMENT_TYPE_OPTIONS, paymentTypeLabel } from "./paymentTypes";
|
|
import { CAMPAIGN_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_LABEL, formatStatus } from "./promotionStatus";
|
|
import { ORDER_STATUS_FILTER_OPTIONS, ORDER_STATUS_LABEL, ORDER_TYPE_OPTIONS, downloadInvoice, orderTypeLabel } from "./services/adminWebOrders";
|
|
import { ONLINE_PAYMENT_STATUS_FILTER_OPTIONS, ONLINE_PAYMENT_STATUS_LABEL, buildOnlinePaymentsWorkbook } from "./onlinePayments/onlinePaymentsExport";
|
|
import { SOURCE_LABEL, STATUS_LABEL, TRXN_LABEL } from "@/app/gift-cards/giftCardLabels";
|
|
import { campaignSummary } from "@/app/promotions/campaignSummary";
|
|
|
|
// localise-admin-sales: the sales helpers hold message codes or translate through the caller's t, so no
|
|
// English is baked into module state. tCode renders every code as «Code», so English left over fails.
|
|
const isCode = (code: string) => Object.prototype.hasOwnProperty.call(DEFAULT_MESSAGES, code);
|
|
|
|
describe("label lists hold codes", () => {
|
|
it.each([
|
|
["ORDER_TYPE_OPTIONS", ORDER_TYPE_OPTIONS],
|
|
["ORDER_STATUS_FILTER_OPTIONS", ORDER_STATUS_FILTER_OPTIONS],
|
|
["ONLINE_PAYMENT_STATUS_FILTER_OPTIONS", ONLINE_PAYMENT_STATUS_FILTER_OPTIONS],
|
|
["PAYMENT_TYPE_OPTIONS", PAYMENT_TYPE_OPTIONS],
|
|
["CAMPAIGN_STATUS_FILTER_OPTIONS", CAMPAIGN_STATUS_FILTER_OPTIONS],
|
|
["REDEMPTION_STATUS_FILTER_OPTIONS", REDEMPTION_STATUS_FILTER_OPTIONS],
|
|
])("%s", (_name, options) => {
|
|
for (const option of options) expect(isCode(option.label), option.label).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
["ORDER_STATUS_LABEL", ORDER_STATUS_LABEL],
|
|
["ONLINE_PAYMENT_STATUS_LABEL", ONLINE_PAYMENT_STATUS_LABEL],
|
|
["REDEMPTION_STATUS_LABEL", REDEMPTION_STATUS_LABEL],
|
|
["gift card STATUS_LABEL", STATUS_LABEL],
|
|
["gift card SOURCE_LABEL", SOURCE_LABEL],
|
|
["gift card TRXN_LABEL", TRXN_LABEL],
|
|
])("%s", (_name, labels) => {
|
|
for (const code of Object.values(labels)) expect(isCode(code), code).toBe(true);
|
|
});
|
|
});
|
|
|
|
// An order is not "enabled": the shared CatActive / CatInactive read 启用 / 停用, wrong for a sale.
|
|
it("order statuses have their own active / inactive wording", () => {
|
|
expect(ORDER_STATUS_LABEL.Y).toBe("WebOrdStatusActive");
|
|
expect(ORDER_STATUS_LABEL.N).toBe("WebOrdStatusInactive");
|
|
});
|
|
|
|
describe("label helpers translate through t and keep unknown codes", () => {
|
|
it("payment type", () => {
|
|
expect(paymentTypeLabel("PC", tCode)).toBe(m("PayMethTypePc"));
|
|
expect(paymentTypeLabel("DWG", tCode)).toBe(m("PayMethTypeDwg"));
|
|
expect(paymentTypeLabel("ZZZ", tCode)).toBe("ZZZ");
|
|
});
|
|
|
|
it("order type", () => {
|
|
expect(orderTypeLabel("NORMAL", "CP", tCode)).toBe(m("WebOrdTypeWeb"));
|
|
expect(orderTypeLabel("NORMAL", "BO", tCode)).toBe(m("WebOrdTypeCounter"));
|
|
expect(orderTypeLabel("EVENT", null, tCode)).toBe(m("WebOrdTypeEvent"));
|
|
expect(orderTypeLabel("OUTLET", null, tCode)).toBe(m("Outlet"));
|
|
expect(orderTypeLabel("WEIRD", "XX", tCode)).toBe("WEIRD");
|
|
expect(orderTypeLabel(null, null, tCode)).toBe("—");
|
|
});
|
|
|
|
it("campaign status", () => {
|
|
expect(formatStatus("PAUSED", tCode)).toBe(m("PromoStatusPaused"));
|
|
});
|
|
});
|
|
|
|
describe("invoice download errors are codes the page translates", () => {
|
|
const realFetch = global.fetch;
|
|
afterEach(() => {
|
|
global.fetch = realFetch;
|
|
});
|
|
|
|
it.each([
|
|
[404, "WebOrdInvoiceNotFound"],
|
|
[500, "WebOrdInvoiceDownloadRetry"],
|
|
])("HTTP %i", async (status, code) => {
|
|
global.fetch = vi.fn().mockResolvedValue(new Response("", { status })) as unknown as typeof fetch;
|
|
await expect(downloadInvoice("X")).rejects.toMatchObject({ status, message: code });
|
|
});
|
|
});
|
|
|
|
describe("online payments export", () => {
|
|
it("translates the status cell and keeps the English column titles (file format)", async () => {
|
|
const row = { id: 1, orderDateTime: "2026-09-26T14:49:49", type: "IPAY88", refId: "REF-1", status: "Y", amount: 1 } as OnlinePaymentRow;
|
|
const wb = XLSX.read(await buildOnlinePaymentsWorkbook([row, { ...row, status: "ZZ" }], tCode), { type: "array" });
|
|
expect(wb.SheetNames).toEqual(["Online payments"]);
|
|
const rows = XLSX.utils.sheet_to_json<(string | number)[]>(wb.Sheets["Online payments"], { header: 1 });
|
|
expect(rows[0][13]).toBe("Status");
|
|
expect(rows[1][13]).toBe(m("OnlPayStatusSuccess"));
|
|
expect(rows[2][13]).toBe("ZZ");
|
|
});
|
|
});
|
|
|
|
describe("campaign summary is built from catalog messages", () => {
|
|
const base: CampaignInput = {
|
|
name: "Raya sale",
|
|
customerLabel: "RAYA 20%",
|
|
benefitType: "PERCENT_OFF",
|
|
benefitValue: 20,
|
|
maxDiscountCap: 30,
|
|
claimType: "SHARED_CODE",
|
|
sharedCode: "RAYA15",
|
|
channelOnline: true,
|
|
channelOutlet: true,
|
|
channelEvent: false,
|
|
allProducts: true,
|
|
products: [],
|
|
ranks: ["SQUIRREL", "GIRAFFE"],
|
|
minSpend: 100,
|
|
minQuantity: 2,
|
|
maxUsesTotal: 500,
|
|
maxUsesPerMember: 1,
|
|
budgetAmount: 900,
|
|
effectiveFrom: "",
|
|
effectiveTo: "",
|
|
};
|
|
|
|
it("uses a message for every fragment, with values passed as params", () => {
|
|
const summary = campaignSummary(base, tCode);
|
|
for (const piece of [
|
|
m("PromoBenefitPercentOff", 20),
|
|
m("PromoSumAllProducts"),
|
|
m("PromoSumMaxCap", "RM30.00"),
|
|
m("PromoSumMinSpend", "RM100.00"),
|
|
m("PromoSumMinItemMany", 2),
|
|
m("PromoSumRanksTwo", m("MemberRankSquirrel"), m("MemberRankGiraffe")),
|
|
m("PromoChannelOnline"),
|
|
m("PromoChannelBranchCounter"),
|
|
m("PromoUsesMany", 500),
|
|
m("PromoSumPerMember", 1),
|
|
m("PromoSumBudget", "RM900.00"),
|
|
m("PromoSumClaimCode", "RAYA15"),
|
|
]) expect(summary).toContain(piece);
|
|
expect(summary).not.toMatch(/\b(off|min|spend|uses|per member|budget|code|Squirrel|Online)\b/);
|
|
});
|
|
|
|
it("no ranks means everyone; unique and automatic claims are messages", () => {
|
|
expect(campaignSummary({ ...base, ranks: [], claimType: "UNIQUE_CODE" }, tCode)).toContain(m("PromoSumEveryone"));
|
|
expect(campaignSummary({ ...base, claimType: "UNIQUE_CODE" }, tCode)).toContain(m("PromoSumClaimUnique"));
|
|
expect(campaignSummary({ ...base, claimType: "AUTO" }, tCode)).toContain(m("PromoSumClaimAuto"));
|
|
});
|
|
});
|