| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { test } from 'node:test';
- import assert from 'node:assert/strict';
- import { applyTestConfig } from './helpers/testConfig.js';
- import {
- currencyMeta,
- isSupportedCurrency,
- resolveCurrency,
- resolveLocale,
- } from '../src/domain/storeLocales.js';
- test('language maps to its natural currency when the shop sells in it', () => {
- applyTestConfig();
- assert.equal(resolveLocale('pl').currency, 'PLN');
- assert.equal(resolveLocale('cs').currency, 'CZK');
- assert.equal(resolveLocale('de').currency, 'EUR');
- });
- test('unsupported natural currency falls back to EUR with a note', () => {
- applyTestConfig();
- const locale = resolveLocale('tr');
- assert.equal(locale.currency, 'EUR');
- assert.equal(locale.fallback, true);
- assert.equal(locale.reason, 'unsupported_currency');
- assert.equal(locale.naturalCurrency, 'TRY');
- assert.match(String(currencyMeta(locale, 'tr').currency_note), /TRY/);
- });
- test('an unknown language code falls back to EUR', () => {
- applyTestConfig();
- const locale = resolveLocale('xx');
- assert.equal(locale.currency, 'EUR');
- assert.equal(locale.reason, 'unknown_language');
- });
- test('no language at all is EUR without a fallback flag', () => {
- applyTestConfig();
- const locale = resolveLocale(null);
- assert.equal(locale.currency, 'EUR');
- assert.equal(locale.fallback, false);
- });
- test('an explicit supported currency override wins over the language', () => {
- applyTestConfig();
- assert.equal(resolveCurrency('pl', 'CZK').currency, 'CZK');
- });
- test('an unsupported currency override is ignored, language mapping applies', () => {
- applyTestConfig();
- assert.equal(resolveCurrency('pl', 'JPY').currency, 'PLN');
- });
- test('STORE_CURRENCIES drives what counts as supported', () => {
- applyTestConfig({ STORE_CURRENCIES: 'PLN,EUR' });
- assert.equal(isSupportedCurrency('CZK'), false);
- assert.equal(resolveLocale('cs').currency, 'EUR');
- assert.equal(resolveLocale('cs').fallback, true);
- });
- test('currencyMeta omits the fallback fields on a clean resolution', () => {
- applyTestConfig();
- const meta = currencyMeta(resolveLocale('pl'), 'pl');
- assert.deepEqual(meta, { currency: 'PLN' });
- });
|