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

50 lines
2.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { FALLBACK_LOCALES, DEFAULT_LOCALE, resolveLocale } from "./locales";
const FIVE = ["en_US", "zh_CN", "zh_TW", "in_ID", "ms_MY"];
describe("FALLBACK_LOCALES", () => {
it("is exactly the two registry locales and defaults to en_US", () => {
expect(DEFAULT_LOCALE).toBe("en_US");
expect(FALLBACK_LOCALES).toEqual([
{ code: "en_US", label: "English" },
{ code: "zh_CN", label: "简体中文" },
]);
});
});
describe("resolveLocale", () => {
it("maps Accept-Language to a code present in the runtime list", () => {
expect(resolveLocale("en-US,en;q=0.9", FIVE)).toBe("en_US");
expect(resolveLocale("zh-CN", FIVE)).toBe("zh_CN");
expect(resolveLocale("zh-HK", FIVE)).toBe("zh_TW");
expect(resolveLocale("zh-TW", FIVE)).toBe("zh_TW");
expect(resolveLocale("id-ID", FIVE)).toBe("in_ID");
expect(resolveLocale("in-ID", FIVE)).toBe("in_ID");
expect(resolveLocale("ms-MY", FIVE)).toBe("ms_MY");
});
it("never resolves to a code outside the runtime list", () => {
// Runtime set has no zh_*: a zh request must fall to DEFAULT_LOCALE, not a hardcoded zh code.
expect(resolveLocale("zh-CN", ["en_US", "ms_MY"])).toBe("en_US");
expect(resolveLocale("zh-HK", ["en_US", "zh_CN"])).toBe("zh_CN");
// No in_ID in the set: id/in must not resolve to it.
expect(resolveLocale("id-ID", ["en_US", "ms_MY"])).toBe("en_US");
// No ms_MY in the set: ms must not resolve to it.
expect(resolveLocale("ms-MY", ["en_US"])).toBe("en_US");
});
it("resolves a family to whatever family code the runtime list actually has", () => {
expect(resolveLocale("zh-TW", ["en_US", "zh_CN"])).toBe("zh_CN");
expect(resolveLocale("ms-MY", ["en_US", "ms_MY", "zh_CN"])).toBe("ms_MY");
});
it("falls back to en_US for unknown or missing headers", () => {
expect(resolveLocale("fr-FR", FIVE)).toBe("en_US");
expect(resolveLocale(null, FIVE)).toBe("en_US");
expect(resolveLocale("", FIVE)).toBe("en_US");
expect(resolveLocale(undefined, FIVE)).toBe("en_US");
expect(resolveLocale("de-DE", [])).toBe("en_US");
});
});