SPB Git forge

spb/cancerindex

Public
37commits 1branches 0releases
2.9 MBsize
maindefault branch
10 days agolast push
TypeScript 97.2% SQL 1.5% CSS 0.6% JavaScript 0.5%
2.0 KB · 40 lines typescript
Raw Blame History
1import { createRequire } from 'node:module';2import { describe, expect, it } from 'vitest';3import { ATLAS_NAME_TO_ALPHA3, ISO_NUMERIC_TO_ALPHA3, atlasGeometryIso3 } from '@/lib/iso-numeric';45const require = createRequire(import.meta.url);6const atlas = require('world-atlas/countries-110m.json') as { objects: { countries: { geometries: Array<{ id?: string; properties: { name: string } }> } } };78describe('ISO numeric → alpha-3', () => {9  it('has well-formed keys and values', () => {10    for (const [k, v] of Object.entries(ISO_NUMERIC_TO_ALPHA3)) {11      expect(k).toMatch(/^\d{3}$/);12      expect(v).toMatch(/^[A-Z]{3}$/);13    }14    const values = Object.values(ISO_NUMERIC_TO_ALPHA3);15    expect(new Set(values).size).toBe(values.length);16  });17  it('resolves a few well-known codes', () => {18    expect(atlasGeometryIso3('840')).toBe('USA');19    expect(atlasGeometryIso3(840)).toBe('USA');20    expect(atlasGeometryIso3('004')).toBe('AFG');21    expect(atlasGeometryIso3(4)).toBe('AFG');22    expect(atlasGeometryIso3('410')).toBe('KOR');23    expect(atlasGeometryIso3('158')).toBe('TWN');24    expect(atlasGeometryIso3('275')).toBe('PSE');25    expect(atlasGeometryIso3(undefined, 'Kosovo')).toBe('XKX');26    expect(atlasGeometryIso3(undefined, 'N. Cyprus')).toBeNull();27    expect(atlasGeometryIso3(undefined, 'Somaliland')).toBeNull();28    expect(atlasGeometryIso3(undefined, 'Nowhere')).toBeNull();29    expect(atlasGeometryIso3('999')).toBeNull();30  });31  it('covers every geometry in world-atlas countries-110m (id or name fallback)', () => {32    const geoms = atlas.objects.countries.geometries;33    expect(geoms.length).toBeGreaterThan(170);34    const unresolved = geoms.filter((g) => g.id != null && atlasGeometryIso3(g.id, g.properties.name) === null).map((g) => `${g.id} ${g.properties.name}`);35    expect(unresolved).toEqual([]);36    const idless = geoms.filter((g) => g.id == null).map((g) => g.properties.name);37    for (const n of idless) expect(n in ATLAS_NAME_TO_ALPHA3).toBe(true);38  });39});40