Files
website/src/lib/world-opinions/data.test.ts
2026-10-25 22:16:25 +00:00

51 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest';
import world from 'world-atlas/countries-110m.json';
import seed from '../../../scripts/stats/world-opinions-seed.json';
import { buildWorldOpinions, type WorldOpinionsData } from './data';
// The guide's content lives in stats.wo_*; this checks the snapshot the stats_wo_seed migration
// was generated from (scripts/stats/world-opinions-seed.json).
const { countries, countryById, narratives, parties, partyCountries, profiles } =
buildWorldOpinions(seed as WorldOpinionsData);
describe('world opinions seed', () => {
it('has unique country ids and ISO codes', () => {
expect(new Set(countries.map((country) => country.id)).size).toBe(countries.length);
expect(new Set(countries.map((country) => country.iso)).size).toBe(countries.length);
});
it('matches every country to a shape on the map', () => {
const shapes = new Set(
world.objects.countries.geometries.map((shape: { id?: string }) => String(shape.id))
);
for (const country of countries) expect(shapes.has(country.iso), country.name).toBe(true);
});
it('only references known countries', () => {
const referenced = [
...profiles.map((profile) => profile.id),
...partyCountries,
...parties.map((party) => party.country),
...narratives.flatMap((narrative) => narrative.views.map((view) => view.country))
];
for (const id of referenced) expect(countryById.has(id), id).toBe(true);
});
it('keeps party positions on the 0–10 scale with unique keys', () => {
const keys = new Set(parties.map((party) => `${party.country}-${party.short}`));
expect(keys.size).toBe(parties.length);
for (const party of parties) {
for (const value of [party.econ, party.social]) {
expect(value).toBeGreaterThanOrEqual(0);
expect(value).toBeLessThanOrEqual(10);
}
}
for (const id of partyCountries) {
expect(
parties.some((party) => party.country === id),
id
).toBe(true);
}
});
});