mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
fix: keep a named place's own point in situation briefs
Brief sections received a named place as its bounding box, so they centered on the box's middle: Tokyo's aircraft were sorted from a point in the Pacific. Sections now receive the place name and resolve it like a direct query, and place lookups are cached briefly so a brief resolves it once.
This commit is contained in:
1 parent
1b3aa8de8b
commit
4af15aa6a9
5 files changed
+137
-21
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGeocodePlaceService } from './places.js';
|
||||
|
||||
const answer = {
|
||||
results: [
|
||||
{
|
||||
formatted_address: 'Tokyo, Japan',
|
||||
geometry: { location: { lat: 35.68, lng: 139.76 } },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
test('place lookups are cached by name for a while, and failures are not', async () => {
|
||||
let clock = 0;
|
||||
const requests = [];
|
||||
let fail = true;
|
||||
const places = createGeocodePlaceService({
|
||||
now: () => clock,
|
||||
cacheMs: 1000,
|
||||
fetchImpl: async (url) => {
|
||||
requests.push(url);
|
||||
if (fail) return new Response(null, { status: 503 });
|
||||
return Response.json(answer);
|
||||
},
|
||||
});
|
||||
await assert.rejects(places.resolve('Tokyo'), /Geocode HTTP 503/);
|
||||
fail = false;
|
||||
const first = await places.resolve('Tokyo');
|
||||
assert.deepEqual(first.point, { lat: 35.68, lon: 139.76 });
|
||||
assert.equal(await places.resolve(' tokyo '), first);
|
||||
assert.equal(requests.length, 2);
|
||||
clock = 2000;
|
||||
await places.resolve('Tokyo');
|
||||
assert.equal(requests.length, 3);
|
||||
const aborted = new AbortController();
|
||||
aborted.abort();
|
||||
await assert.rejects(places.resolve('Tokyo', { signal: aborted.signal }));
|
||||
});
|
||||
Reference in new issue
Block a user