test(places): pin the pack build-date rule and a nearer village beating a namesake inside a wide search

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 22:54:53 -08:00
1 parent 75e345aa07
commit 50824c9a65
4 files changed
+66 -19

No files matched your search

+29
View File
@@ -9,6 +9,7 @@ import { readdir, readFile } from 'node:fs/promises';
import test from 'node:test';
import {
keepBuiltIfUnchanged,
keepPackBuiltIfUnchanged,
placeTileFiles,
tileKey,
withoutCities,
@@ -114,3 +115,31 @@ test('a rebuild of unchanged rows keeps the earlier build stamp', () => {
assert.equal(keepBuiltIfUnchanged(same, undefined), same);
assert.equal(keepBuiltIfUnchanged(same, 'not json'), same);
});
test('the places index keeps its build stamp only when no tile changed', () => {
const rows = [
['Aa', 31, -98, 2000, 'US', 'Q1'],
['Bb', 41, -88, 1500, 'US', 'Q2'],
];
const meta = (built) => ({
source: 's',
license: 'l',
built,
minPopulation: 1000,
maxPopulation: 15000,
columns: [],
});
const earlier = placeTileFiles(rows, meta('2026-01-01T00:00:00.000Z'));
const built = (files) => JSON.parse(files.get('index.json')).meta.built;
const rebuild = (newRows) =>
keepPackBuiltIfUnchanged(
placeTileFiles(newRows, meta('2026-11-18T00:00:00.000Z')),
earlier,
);
assert.equal(built(rebuild(rows)), '2026-01-01T00:00:00.000Z');
// Same row count in every tile, new population: a new stamp.
const changed = [['Aa', 31, -98, 2100, 'US', 'Q1'], rows[1]];
assert.equal(built(rebuild(changed)), '2026-11-18T00:00:00.000Z');
// A tile of the earlier build left out: a new stamp.
assert.equal(built(rebuild([rows[0]])), '2026-11-18T00:00:00.000Z');
});