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
57 lines
3.7 KiB
TypeScript
57 lines
3.7 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { m, tCode } from "@/test/i18nCatalog";
|
|
import { dayMonth, eventKind, eventState } from "./eventState";
|
|
import { TAKE_NOW_FULFILMENT, collectionLabel, fulfilmentBlocker, type PosFulfilment } from "@/app/pos/fulfilment";
|
|
|
|
// localise-admin-pos-events: the POS and event helpers 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 at = (iso: string) => new Date(`${iso}+08:00`);
|
|
const ev = { salesFrom: "2026-10-04T10:00", salesTo: "2026-10-07T22:00" };
|
|
|
|
describe("eventState renders catalog codes", () => {
|
|
it("live, upcoming, ended, closed and deactivated", () => {
|
|
expect(eventState(ev, tCode, at("2026-10-06T12:00")).line).toBe(m("EvtLive", 3, 4));
|
|
expect(eventState({ salesFrom: "2026-10-16T10:00", salesTo: "2026-10-18T22:00" }, tCode, at("2026-10-06T12:00")).line)
|
|
.toBe(m("EvtStarts", m("EvtDayMonth", 16, m("EvtMonth10"))));
|
|
expect(eventState(ev, tCode, at("2026-10-08T00:00")).line).toBe(m("EvtStateEnded"));
|
|
expect(eventState({ ...ev, status: "C" }, tCode).line).toBe(m("EvtStateClosed"));
|
|
expect(eventState({ ...ev, status: "N" }, tCode).line).toBe(m("EvtStateDeactivated"));
|
|
});
|
|
|
|
it("eventKind needs no t (an effect picks the default event with it)", () => {
|
|
expect(eventKind(ev, at("2026-10-06T12:00"))).toBe("live");
|
|
expect(eventKind({ ...ev, status: "C" }, at("2026-10-06T12:00"))).toBe("ended");
|
|
});
|
|
|
|
it("dayMonth names the month through the catalog", () => {
|
|
expect(dayMonth("2026-01-05T10:00", tCode)).toBe(m("EvtDayMonth", 5, m("EvtMonth1")));
|
|
expect(dayMonth("2026-12-31", tCode)).toBe(m("EvtDayMonth", 31, m("EvtMonth12")));
|
|
});
|
|
});
|
|
|
|
describe("fulfilment helpers render catalog codes", () => {
|
|
const member = { walkInPhone: null, soldOutInCart: false };
|
|
const pickup: PosFulfilment = { ...TAKE_NOW_FULFILMENT, mode: "PICKUP", pickupBranchCode: "PJ" };
|
|
const delivery: PosFulfilment = { ...TAKE_NOW_FULFILMENT, mode: "DELIVERY", addressDetails: "7 Jalan A", postcode: "40100" };
|
|
|
|
it("blockers", () => {
|
|
expect(fulfilmentBlocker(TAKE_NOW_FULFILMENT, { ...member, notHereLabels: ["Wipes"] }, tCode)).toBe(m("PosNotInStockOne", "Wipes"));
|
|
expect(fulfilmentBlocker(TAKE_NOW_FULFILMENT, { ...member, notHereLabels: ["Wipes", "Pram"] }, tCode)).toBe(m("PosNotInStockMany", "Wipes, Pram"));
|
|
expect(fulfilmentBlocker(TAKE_NOW_FULFILMENT, { ...member, short: [{ label: "Cake", available: 1 }] }, tCode))
|
|
.toBe(m("PosShortStockOne", m("PosShortItem", 1, "Cake")));
|
|
expect(fulfilmentBlocker(TAKE_NOW_FULFILMENT, { ...member, short: [{ label: "Cake", available: 1 }, { label: "Tea", available: 2 }] }, tCode))
|
|
.toBe(m("PosShortStockMany", `${m("PosShortItem", 1, "Cake")}, ${m("PosShortItem", 2, "Tea")}`));
|
|
expect(fulfilmentBlocker({ ...pickup, pickupBranchCode: "" }, member, tCode)).toBe(m("PosChoosePickupOutlet"));
|
|
expect(fulfilmentBlocker(pickup, { walkInPhone: null, soldOutInCart: true, localBranchCode: "PJ" }, tCode)).toBe(m("PosOutletNoStock"));
|
|
expect(fulfilmentBlocker(pickup, { walkInPhone: "", soldOutInCart: false }, tCode)).toBe(m("PosWalkInPhoneNeeded"));
|
|
expect(fulfilmentBlocker({ ...delivery, receiver: "" }, member, tCode)).toBe(m("PosDeliveryFieldsNeeded"));
|
|
});
|
|
|
|
it("collection label", () => {
|
|
const outlets = [{ branchCode: "PJ", name: "Petaling Jaya outlet", warehouseId: "5" }];
|
|
expect(collectionLabel(TAKE_NOW_FULFILMENT, outlets, tCode)).toBe(m("PosTakenInStore"));
|
|
expect(collectionLabel(pickup, outlets, tCode)).toBe(m("PosPickUpAt", "Petaling Jaya outlet"));
|
|
expect(collectionLabel(delivery, outlets, tCode)).toBe(m("PosDeliveryTo", "7 Jalan A", "40100"));
|
|
});
|
|
});
|