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

85 lines
3.6 KiB
TypeScript

import { describe, it, expect } from "vitest";
import * as XLSX from "xlsx";
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
import { m, tCode } from "@/test/i18nCatalog";
import {
COLLECTION_STATUS_FILTER_OPTIONS,
DELIVERY_STATUSES,
WMS_STATUSES,
collectionStatusLabel,
deliveryStatusLabel,
wmsStatusLabel,
} from "@/app/inventory/delivery-orders/deliveryStatus";
import { counterChannelLabel } from "@/app/inventory/delivery-orders/counterChannel";
import {
FULFILMENT_MODE_OPTIONS,
STATUS_OPTIONS,
TYPE_OPTIONS,
warehouseStatusLabel,
warehouseTypeLabel,
} from "@/app/components/warehouses/warehouseLabels";
import { STOCK_COUNT_STATUS_LABEL } from "./stockCountStatus";
import { parseRateSheet, validateRates } from "./shipping/rateCardWorkbook";
import { parseStockInWorkbook } from "./inventory/stockInWorkbook";
// localise-admin-stock: the stock 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([
["DELIVERY_STATUSES", DELIVERY_STATUSES],
["WMS_STATUSES", WMS_STATUSES],
["COLLECTION_STATUS_FILTER_OPTIONS", COLLECTION_STATUS_FILTER_OPTIONS],
["TYPE_OPTIONS", TYPE_OPTIONS],
["STATUS_OPTIONS", STATUS_OPTIONS],
["FULFILMENT_MODE_OPTIONS", FULFILMENT_MODE_OPTIONS],
])("%s", (_name, options) => {
for (const option of options) expect(isCode(option.label), option.label).toBe(true);
});
it("STOCK_COUNT_STATUS_LABEL", () => {
for (const code of Object.values(STOCK_COUNT_STATUS_LABEL)) expect(isCode(code), code).toBe(true);
});
});
describe("label helpers translate through t and keep unknown codes", () => {
it("delivery, WMS and collection status", () => {
expect(deliveryStatusLabel("SH", tCode)).toBe(m("DoStatusShipped"));
expect(deliveryStatusLabel("XX", tCode)).toBe("XX");
expect(deliveryStatusLabel(null, tCode)).toBe("—");
expect(wmsStatusLabel("PP", tCode)).toBe(m("DoWmsPendingPost"));
expect(collectionStatusLabel("READY", tCode)).toBe(m("DoCollectionReady"));
});
it("counter channel", () => {
expect(counterChannelLabel("EVENT", tCode)).toBe(m("DoChannelEventPos"));
expect(counterChannelLabel(null, tCode)).toBe(m("DoChannelCounter"));
});
it("warehouse type and status", () => {
expect(warehouseTypeLabel("ONLINE", tCode)).toBe(m("WhTypeOnline"));
expect(warehouseTypeLabel("EVENT", tCode)).toBe(m("WhTypeEvent"));
expect(warehouseTypeLabel("X", tCode)).toBe("X");
expect(warehouseStatusLabel("Y", tCode)).toBe(m("CatActive"));
});
});
describe("parsers name the row through t", () => {
it("validateRates", () => {
const errors = validateRates([{ zoneCode: "", type: "BRACKET", fromKg: 0, toKg: 1, stepKg: null, fee: 1, maxLengthCm: 20, maxWidthCm: 15, maxHeightCm: 10 }], [2], ["WM"], tCode);
expect(errors).toContain(m("ShipRateErrZoneRequired", 2));
});
it("parseRateSheet refuses formulas", () => {
const sheet = XLSX.utils.aoa_to_sheet([["Zone code", "Type", "Up to kg", "Max L cm", "Max W cm", "Max H cm", "Step kg", "Fee RM"], ["WM", "BRACKET", 1, 20, 15, 10, null, 8]]);
sheet["H2"] = { t: "n", v: 8, f: "4*2" };
expect(parseRateSheet(sheet, ["WM"], tCode).errors).toContain(m("ShipRateErrFormula", 2));
});
it("parseStockInWorkbook", () => {
const { errors } = parseStockInWorkbook([{ "SKU Variation ID": "", Quantity: "1" }], tCode);
expect(errors.some((e) => e.startsWith("«StockInRow"))).toBe(true);
});
});