maps: OSM details carry the values installations published for the element

A place found through Photon or Overpass, a relation or a way, is no row of the
TREK index, so the community values the index lays over its own rows never
reached it. Opening its details now asks /v1/community for the element and
lays what is published over the record, with the version, where the TREK index
is in use. No answer leaves the details as they were.
This commit is contained in:
Maurice
2026-10-30 20:16:18 +01:00
parent b64f4535fd
commit 59154b34c9
5 changed files with 170 additions and 1 deletions
@@ -0,0 +1,75 @@
/**
* Community values for places outside the index: the key a details id maps to,
* what is laid over the record, and that a place without published values, or
* a service that does not answer, leaves the details as they were.
*/
import { communityKeyOf, osmDetailsWithCommunity, withCommunityValues } from '../../../src/nest/maps/community-overlay';
import { trekCommunityByKeys } from '../../../src/nest/maps/trek-places.client';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('../../../src/nest/maps/trek-places.client', () => ({ trekCommunityByKeys: vi.fn() }));
const ask = vi.mocked(trekCommunityByKeys);
const DETAILS = {
name: 'Umeda Sky Building',
website: null,
phone: null,
opening_hours: null,
osm_id: 'relation:3389505',
};
beforeEach(() => ask.mockReset());
describe('community values on OSM details', () => {
it('COMOV-001: maps an OSM details id onto the service key, and nothing else', () => {
expect(communityKeyOf('relation:3389505')).toBe('osm:relation/3389505');
expect(communityKeyOf('node:1')).toBe('osm:node/1');
expect(communityKeyOf('way:22')).toBe('osm:way/22');
expect(communityKeyOf('gers:abc')).toBeNull();
expect(communityKeyOf('relation:12;out')).toBeNull();
});
it('COMOV-002: lays the published values over the record, with the version', () => {
const got = withCommunityValues(DETAILS, {
contact: { website: 'www.skybldg.co.jp', phone: '+81 6 6440 3855', email: null },
hours: { osm: 'Mo-Su 09:30-22:30' },
description: { text: 'A tower of two linked blocks.' },
community: { version: 3, fields: ['website', 'phone', 'opening_hours', 'description'] },
});
expect(got.website).toMatch(/^https:\/\/www\.skybldg\.co\.jp\/?$/);
expect(got).toMatchObject({
phone: '+81 6 6440 3855',
opening_hours: 'Mo-Su 09:30-22:30',
description: 'A tower of two linked blocks.',
community_version: 3,
name: 'Umeda Sky Building',
});
expect(got.email).toBeUndefined();
});
it('COMOV-003: a place without published values keeps its record as it was', () => {
expect(withCommunityValues(DETAILS, undefined)).toBe(DETAILS);
expect(withCommunityValues(DETAILS, { contact: { website: 'https://x.example' } })).toBe(DETAILS);
});
it('COMOV-004: asks the service once for the element and merges its answer', async () => {
ask.mockResolvedValueOnce({
'osm:relation/3389505': {
contact: { website: 'https://www.skybldg.co.jp/' },
community: { version: 1, fields: ['website'] },
},
});
const got = await osmDetailsWithCommunity('relation:3389505', DETAILS);
expect(ask).toHaveBeenCalledWith(['osm:relation/3389505']);
expect(got?.website).toBe('https://www.skybldg.co.jp/');
});
it('COMOV-005: no details, an id without a key, or an empty answer ask nothing more', async () => {
expect(await osmDetailsWithCommunity('relation:3389505', null)).toBeNull();
expect(await osmDetailsWithCommunity('gers:abc', DETAILS)).toBe(DETAILS);
expect(ask).not.toHaveBeenCalled();
ask.mockResolvedValueOnce({});
expect(await osmDetailsWithCommunity('node:7', DETAILS)).toEqual(DETAILS);
});
});
@@ -13,6 +13,7 @@ import {
trekPlacesArea,
trekPlacesBaseUrl,
trekPlacesById,
trekCommunityByKeys,
trekPlacesHighlights,
trekPlacesMiss,
trekPlacesNearby,
@@ -1207,3 +1208,22 @@ describe('the layers breaker', () => {
expect(calls).toHaveLength(0);
});
});
describe('trekCommunityByKeys', () => {
it('asks /v1/community for the keys and answers its places', async () => {
const places = { 'osm:relation/3389505': { contact: { website: 'https://www.skybldg.co.jp/' } } };
stubFetch({ places });
expect(await trekCommunityByKeys(['osm:relation/3389505', 'osm:node/1'])).toEqual(places);
const url = new URL(calls[0]?.url ?? 'http://missing');
expect(url.pathname).toBe('/v1/community');
expect(url.searchParams.get('keys')).toBe('osm:relation/3389505,osm:node/1');
});
it('asks nothing without keys, and a failing service is an empty map', async () => {
stubFetch({ places: {} });
expect(await trekCommunityByKeys([])).toEqual({});
expect(calls).toHaveLength(0);
stubFetch({ error: 'down' }, 503);
expect(await trekCommunityByKeys(['osm:node/1'])).toEqual({});
});
});