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
63 lines
2.8 KiB
TypeScript
63 lines
2.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { malaysiaInstant, malaysiaToday, periodRange } from "./malaysiaPeriod";
|
|
|
|
// 2026-09-28T18:39Z is 02:39 on the 29th in Malaysia (UTC+8): the UTC date and the Malaysia date differ.
|
|
const NOW = new Date("2026-09-28T18:39:00Z");
|
|
|
|
describe("malaysiaToday", () => {
|
|
it("is the Malaysia calendar date, not the UTC date", () => {
|
|
expect(malaysiaToday(NOW)).toBe("2026-09-29");
|
|
});
|
|
});
|
|
|
|
describe("periodRange (Malaysia time)", () => {
|
|
it("all time has no bounds", () => {
|
|
expect(periodRange("all", NOW)).toEqual({ from: "", to: "" });
|
|
});
|
|
|
|
it("this month runs from the 1st to the last day of the Malaysia month", () => {
|
|
expect(periodRange("month", NOW)).toEqual({ from: "2026-09-01", to: "2026-09-30" });
|
|
});
|
|
|
|
it("last 30 days ends today (Malaysia) and starts 30 days earlier", () => {
|
|
expect(periodRange("30d", NOW)).toEqual({ from: "2026-08-30", to: "2026-09-29" });
|
|
});
|
|
|
|
it("this year runs from 1 January to today (Malaysia)", () => {
|
|
expect(periodRange("year", NOW)).toEqual({ from: "2026-01-01", to: "2026-09-29" });
|
|
});
|
|
|
|
it("rolls into the next Malaysia year while UTC is still on the old one", () => {
|
|
const newYear = new Date("2026-12-31T17:00:00Z"); // 01:00 on 1 Jan 2027 in Malaysia
|
|
expect(periodRange("month", newYear)).toEqual({ from: "2027-01-01", to: "2027-01-31" });
|
|
expect(periodRange("year", newYear)).toEqual({ from: "2027-01-01", to: "2027-01-01" });
|
|
});
|
|
|
|
it("lastMonth is the whole previous Malaysia month, across a year boundary", () => {
|
|
expect(periodRange("lastMonth", new Date("2026-01-10T04:00:00Z"))).toEqual({ from: "2025-12-01", to: "2025-12-31" });
|
|
// 04:00 on 1 Oct in Malaysia is still 30 Sep in UTC: last month is September.
|
|
expect(periodRange("lastMonth", new Date("2026-09-30T20:00:00Z"))).toEqual({ from: "2026-09-01", to: "2026-09-30" });
|
|
});
|
|
|
|
it("handles a leap-year February", () => {
|
|
expect(periodRange("month", new Date("2028-02-10T04:00:00Z"))).toEqual({ from: "2028-02-01", to: "2028-02-29" });
|
|
});
|
|
});
|
|
|
|
describe("malaysiaInstant", () => {
|
|
it("reads a zone-less date-time as Malaysia time", () => {
|
|
expect(malaysiaInstant("2026-10-27T00:15:00").toISOString()).toBe("2026-10-26T16:15:00.000Z");
|
|
expect(malaysiaInstant("2026-10-27T00:15").toISOString()).toBe("2026-10-26T16:15:00.000Z");
|
|
expect(malaysiaInstant("2026-10-27 00:15:00").toISOString()).toBe("2026-10-26T16:15:00.000Z");
|
|
});
|
|
|
|
it("reads a date-only value as Malaysia midnight", () => {
|
|
expect(malaysiaInstant("2026-10-27").toISOString()).toBe("2026-10-26T16:00:00.000Z");
|
|
});
|
|
|
|
it("keeps an explicit zone", () => {
|
|
expect(malaysiaInstant("2026-10-27T00:15:00Z").toISOString()).toBe("2026-10-27T00:15:00.000Z");
|
|
expect(malaysiaInstant("2026-10-27T00:15:00+00:00").toISOString()).toBe("2026-10-27T00:15:00.000Z");
|
|
});
|
|
});
|