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

44 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { COUNTRY_CALLING_CODES, countryCodeOptions, matchesCountryQuery } from "./countryCallingCodes";
describe("countryCallingCodes", () => {
it("covers every region once, with MY 60 and SG 65", () => {
expect(COUNTRY_CALLING_CODES.length).toBeGreaterThanOrEqual(240);
const isos = COUNTRY_CALLING_CODES.map((c) => c.iso2);
expect(new Set(isos).size).toBe(isos.length);
expect(COUNTRY_CALLING_CODES).toContainEqual({ iso2: "MY", dial: "60" });
expect(COUNTRY_CALLING_CODES).toContainEqual({ iso2: "SG", dial: "65" });
expect(COUNTRY_CALLING_CODES.every((c) => /^\d+$/.test(c.dial))).toBe(true);
});
it("lists Malaysia then Singapore first, the rest by name", () => {
const options = countryCodeOptions();
expect(options.slice(0, 2).map((o) => `${o.name} +${o.dial}`)).toEqual(["Malaysia +60", "Singapore +65"]);
const rest = options.slice(2).map((o) => o.name);
expect(rest).toEqual([...rest].sort((a, b) => a.localeCompare(b, "en")));
});
it("matches by name, ISO code and dial code with or without +", () => {
const options = countryCodeOptions();
const names = (q: string) => options.filter((o) => matchesCountryQuery(o, q)).map((o) => o.name);
expect(names("indo")).toContain("Indonesia");
expect(names("+44")).toContain("United Kingdom");
expect(names("44")).toContain("United Kingdom");
expect(names("sg")).toContain("Singapore");
expect(names("")).toHaveLength(options.length);
expect(names("zzzz")).toEqual([]);
});
});
describe("countryCodeOptions locale", () => {
it("names countries in the portal locale (en_US / zh_CN style), MY and SG still first", () => {
const zh = countryCodeOptions("zh_CN");
expect(zh.slice(0, 2).map((o) => o.name)).toEqual(["马来西亚", "新加坡"]);
expect(countryCodeOptions("ms_MY")[0].name).toBe("Malaysia");
});
it("falls back to English for a locale Intl cannot parse", () => {
expect(countryCodeOptions("not a locale!")[0].name).toBe("Malaysia");
});
});