maps: validate the community values and OSM elements the TREK Places API answers

Both answers were taken as typed. A value outside the published shape, such
as hours that are no text, reached the hours parser and failed the details
request. A place outside the shape is now left out of /v1/community, and an
element outside it sends the lookup to Overpass.
This commit is contained in:
Maurice
2026-10-30 23:14:32 +00:00
parent 6945b53c10
commit 41edbcf67a
6 changed files with 61 additions and 23 deletions
@@ -300,6 +300,15 @@ it('OSM-PHOTON-009: a lookup by id is Overpass for the tags and the place, Photo
expect(hosts).toEqual(['places.liketrek.com', 'overpass-api.de', 'photon.liketrek.com']);
});
it('OSM-PHOTON-022: an answer of the details layer outside its shape is no element, and Overpass is asked', async () => {
const place = { name: 'Brandenburger Tor', lat: 52.5163, lng: 13.3777, tags: { level: 2 } };
placesReply = () =>
new Response(JSON.stringify({ place }), { status: 200, headers: { 'content-type': 'application/json' } });
const details = await osm.elementDetails('way:518071791', 'en');
expect(details).toMatchObject({ name: 'Brandenburg Gate', website: 'https://example.org' });
expect(hosts).toEqual(['places.liketrek.com', 'overpass-api.de', 'photon.liketrek.com']);
});
it("OSM-PHOTON-021: an element in TREK's own details layer asks no Overpass, and carries the community values", async () => {
placesReply = (url) => {
expect(url.pathname).toBe('/v1/osm/way/518071791');
@@ -1219,6 +1219,14 @@ describe('trekCommunityByKeys', () => {
expect(url.searchParams.get('keys')).toBe('osm:relation/3389505,osm:node/1');
});
it('leaves out a place whose values are not in the published shape, and keeps the others', async () => {
const good = { contact: { phone: '+49 30 1' }, community: { version: 1 } };
stubFetch({ places: { 'osm:node/1': good, 'osm:node/2': { hours: { osm: 7 } } } });
expect(await trekCommunityByKeys(['osm:node/1', 'osm:node/2'])).toEqual({ 'osm:node/1': good });
stubFetch({ places: ['not', 'a', 'map'] });
expect(await trekCommunityByKeys(['osm:node/1'])).toEqual({});
});
it('asks nothing without keys, and a failing service is an empty map', async () => {
stubFetch({ places: {} });
expect(await trekCommunityByKeys([])).toEqual({});