The country wall passed no records, so each of its 175 cards offered only the poster and said the prayer list was "coming soon", while the people groups were one request away. library/lists/ peopleGroupRecords.js is the records half of the print standard: one people-groups fetch per language (normalised the way the prints read rows, list membership applied), then a SELECTOR picks the set — a country by ISO3, explicit slugs, any field, or a host's own selector language. A selector nobody understands selects nothing rather than every group on earth, and a failed fetch is not cached. The country wall uses it by ISO3, so every country now prints the list, the deck (all five stocks) and the full or lightweight packet. The packet's page 1 is, for now, the country's stored poster when it is really there; the in-browser map generator will replace that. check:people-group-records asserts the selection two-sided with an injected fetch; registered in gates:pre.
43 lines
2.8 KiB
JavaScript
43 lines
2.8 KiB
JavaScript
#!/usr/bin/env bun
|
|
/**
|
|
* check-people-group-records — the records half of the print standard (library/lists/peopleGroupRecords.js)
|
|
* selects EXACTLY the set it is asked for, two-sided: a country selector returns that country's groups and
|
|
* not another's, an unknown selector returns nothing (never everything), one fetch serves a language, and
|
|
* a failed fetch is not cached. Headless, with an injected fetch. Runs under bun (lists.json is imported
|
|
* without an import attribute, as it is inside the bundles).
|
|
*/
|
|
const { createPeopleGroupRecords, selectRecords } = await import(new URL('../library/lists/peopleGroupRecords.js', import.meta.url).href)
|
|
const rows = [
|
|
{ slug: 'a', name: 'Zeta', country_code: { value: 'TCD', label: 'Chad' }, wagf_region: { value: 'africa', label: 'Africa' } },
|
|
{ slug: 'b', name: 'Alpha', country_code: { value: 'TCD', label: 'Chad' }, wagf_region: { value: 'africa', label: 'Africa' } },
|
|
{ slug: 'c', name: 'Mid', country_code: { value: 'IND', label: 'India' }, wagf_region: { value: 'asia', label: 'Asia' } },
|
|
]
|
|
let calls = 0, fail = false
|
|
const fetchImpl = async (url) => { calls++; if (fail) return { ok: false, status: 503 }; return { ok: true, json: async () => ({ posts: rows }) } }
|
|
const R = createPeopleGroupRecords({ apiBase: () => 'http://api', lang: () => 'es', fetchImpl })
|
|
const chad = await R({ type: 'country', values: ['tcd'] })
|
|
const bySlug = await R({ type: 'pg_slugs', values: ['c'] })
|
|
const byField = await R({ type: 'field', field: 'wagf_region', values: ['asia'] })
|
|
const unknown = await R({ type: 'rop3', values: ['x'] })
|
|
const r = {
|
|
country: chad.map((x) => x.slug).join(',') === 'b,a', // Chad only, sorted by name
|
|
countryExcludesIndia: !chad.some((x) => x.slug === 'c'),
|
|
normalized: chad[0].country_code === 'TCD' && chad[0].country_code_label === 'Chad',
|
|
slugs: bySlug.length === 1 && bySlug[0].slug === 'c',
|
|
field: byField.length === 1 && byField[0].slug === 'c',
|
|
unknownSelectsNothing: unknown.length === 0,
|
|
oneFetchPerLanguage: calls === 1,
|
|
evaluateHook: selectRecords(rows.map((x) => ({ ...x, country_code: 'X' })), { type: 'custom' }, () => new Set(['a'])).length === 1,
|
|
}
|
|
fail = true
|
|
const R2 = createPeopleGroupRecords({ apiBase: () => 'http://api', fetchImpl })
|
|
let threw = false; try { await R2({ type: 'country', values: ['TCD'] }) } catch { threw = true }
|
|
fail = false
|
|
const retried = (await R2({ type: 'country', values: ['TCD'] })).length === 2
|
|
r.failureNotCached = threw && retried
|
|
const R3 = createPeopleGroupRecords({ apiBase: () => '', fetchImpl })
|
|
let noApi = false; try { await R3({ type: 'country', values: ['TCD'] }) } catch { noApi = true }
|
|
r.noApiRejects = noApi
|
|
console.log(r)
|
|
const pass = Object.values(r).every(Boolean)
|
|
console.log(pass ? 'PG-RECORDS: PASS' : 'PG-RECORDS: FAIL'); process.exit(pass ? 0 : 1)
|