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

+11
View File
@@ -115,6 +115,17 @@ test('a small place in view comes before a far bigger city of its name', async (
const austin = { latitude: 30.27, longitude: -97.74 };
assert.equal((await find('Paris', austin)).wikidata, 'Q-village');
assert.ok((await find('Paris', austin)).distanceKm < 20);
// A bigger namesake inside a wider search: the nearer village still wins.
assert.equal(
(
await module.findPlace(
'Paris',
{ near: austin, radiusKm: 600, includeSmallPlaces: true },
fetchImpl,
)
).wikidata,
'Q-village',
);
// Only when small places are asked for.
assert.equal(
(await module.findPlace('Paris', { near: austin }, fetchImpl)).wikidata,
+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');
});