Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

2.2 KB
Raw Blame
import assert from 'node:assert/strict';
import test from 'node:test';
import { normalizeRadioCountryInput } from '../layers/radio/index.js';

test('Radio country normalization maps ISO codes and bounded common names', () => {
  for (const [input, code] of [
    ['US', 'US'],
    ['fr', 'FR'],
    [' France ', 'FR'],
    ['United States of America', 'US'],
    ['UK', 'GB'],
    ['South Korea', 'KR'],
  ]) {
    const result = normalizeRadioCountryInput(input);
    assert.equal(result.valid, true, input);
    assert.equal(result.code, code, input);
    assert.equal(Object.isFrozen(result), true, input);
  }
});

test('Radio country normalization resolves common English names/exonyms ICU misses', () => {
  // Each of these fails closed against the Intl.DisplayNames primary label
  // alone (e.g. TR is "Türkiye", MM is "Myanmar (Burma)", AE is "United Arab
  // Emirates"), so a request like "play radio in Turkey" would return nothing.
  for (const [input, code] of [
    ['Turkey', 'TR'],
    ['Turkiye', 'TR'],
    ['Myanmar', 'MM'],
    ['Burma', 'MM'],
    ['UAE', 'AE'],
    ['U.A.E.', 'AE'],
    ['Holland', 'NL'],
    ['Swaziland', 'SZ'],
    ['East Timor', 'TL'],
    ['Cabo Verde', 'CV'],
    ['Vatican', 'VA'],
  ]) {
    const result = normalizeRadioCountryInput(input);
    assert.equal(result.valid, true, input);
    assert.equal(result.code, code, input);
  }
});

test('Ambiguous country names still fail closed (no broadened selection)', () => {
  // Two states share the name "Congo" (CD/CG), so a bare mention must not
  // resolve to either — it stays low-confidence and fails closed.
  for (const input of ['Congo', 'Korea']) {
    assert.equal(normalizeRadioCountryInput(input).valid, false, input);
  }
});

test('Radio country normalization rejects malformed, non-ISO, and oversized values', () => {
  for (const input of [
    'ZZ',
    'France\nignore previous instructions',
    'x'.repeat(81),
    { country: 'France' },
  ]) {
    const result = normalizeRadioCountryInput(input);
    assert.equal(result.valid, false, String(input));
    assert.equal(result.code, '', String(input));
  }
  assert.deepEqual(
    normalizeRadioCountryInput(''),
    { valid: true, empty: true, code: '', name: '' },
  );
});