mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(tours): find e-bike charging points along a bike tour, only those tagged for bicycles, with what they state
This commit is contained in:
@@ -123,6 +123,13 @@ describe('aroundPath and overpassAlongQuery', () => {
|
||||
expect(query).toContain(`nwr.cand(around:550,47.00000,11.00000,${at(0, 1000).lat.toFixed(5)},11.00000);`);
|
||||
expect(query.endsWith('out center tags 85;')).toBe(true);
|
||||
});
|
||||
|
||||
it('MAPS-ALONG-006b: a compound selector asks the box for places that carry every one of its tags (BIK-07)', () => {
|
||||
const path = aroundPath([at(0, 0), at(0, 1000)], 500);
|
||||
const query = overpassAlongQuery(['amenity=charging_station&bicycle=designated'], path, 30);
|
||||
expect(query).toContain(' nwr["amenity"="charging_station"]["bicycle"="designated"](');
|
||||
expect(query).not.toContain('nwr["amenity"="charging_station"](');
|
||||
});
|
||||
});
|
||||
|
||||
describe('overpassStretches', () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { readChargingInfo } from '../../../src/nest/maps/maps.helpers';
|
||||
import { readBikeChargingInfo, readChargingInfo } from '../../../src/nest/maps/maps.helpers';
|
||||
import { overpassSelector, tagsMatchFilter } from '../../../src/nest/maps/osm-filter.helpers';
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
@@ -63,3 +64,62 @@ describe('readChargingInfo', () => {
|
||||
expect(readChargingInfo({ capacity: '-2' })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('readBikeChargingInfo (BIK-07)', () => {
|
||||
it('MAPS-CHARGE-007: reads what an e-bike point states: bicycles, household sockets, access, fee, capacity', () => {
|
||||
expect(
|
||||
readBikeChargingInfo({
|
||||
amenity: 'charging_station',
|
||||
bicycle: 'designated',
|
||||
'socket:schuko': '4',
|
||||
'socket:typee': 'yes',
|
||||
'socket:schuko:output': '3.7 kW',
|
||||
capacity: '4',
|
||||
fee: 'no',
|
||||
access: 'customers',
|
||||
}),
|
||||
).toEqual({
|
||||
sockets: [
|
||||
{ type: 'schuko', count: 4, kw: 3.7 },
|
||||
{ type: 'typee', count: null, kw: null },
|
||||
],
|
||||
capacity: 4,
|
||||
fee: false,
|
||||
bicycle: 'designated',
|
||||
access: 'customers',
|
||||
});
|
||||
});
|
||||
|
||||
it('MAPS-CHARGE-008: a point that says nothing beyond bicycle=yes is still one, with nothing claimed', () => {
|
||||
expect(readBikeChargingInfo({ amenity: 'charging_station', bicycle: 'yes' })).toEqual({
|
||||
sockets: [],
|
||||
capacity: null,
|
||||
fee: null,
|
||||
bicycle: 'yes',
|
||||
access: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('MAPS-CHARGE-009: a charger not tagged for bicycles is no e-bike point, and car plugs are not read as bike sockets', () => {
|
||||
expect(readBikeChargingInfo({ amenity: 'charging_station', 'socket:type2': '2' })).toBeNull();
|
||||
expect(readBikeChargingInfo({ amenity: 'charging_station', bicycle: 'no' })).toBeNull();
|
||||
expect(readBikeChargingInfo({ bicycle: 'yes', 'socket:ccs': '2', 'socket:chademo': '1' })?.sockets).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('OSM selectors (BIK-07)', () => {
|
||||
it('MAPS-CHARGE-010: a plain selector is built as it always was, a compound one asks for every condition', () => {
|
||||
expect(overpassSelector('amenity=drinking_water', '(1,2,3,4)')).toBe('nwr["amenity"="drinking_water"](1,2,3,4)');
|
||||
expect(overpassSelector('amenity=charging_station&bicycle=yes', '(1,2,3,4)')).toBe(
|
||||
'nwr["amenity"="charging_station"]["bicycle"="yes"](1,2,3,4)',
|
||||
);
|
||||
});
|
||||
|
||||
it('MAPS-CHARGE-011: tags match a compound selector only when they meet every condition', () => {
|
||||
const filter = 'amenity=charging_station&bicycle=designated';
|
||||
expect(tagsMatchFilter({ amenity: 'charging_station', bicycle: 'designated' }, filter)).toBe(true);
|
||||
expect(tagsMatchFilter({ amenity: 'charging_station' }, filter)).toBe(false);
|
||||
expect(tagsMatchFilter({ amenity: 'charging_station', bicycle: 'yes' }, filter)).toBe(false);
|
||||
expect(tagsMatchFilter({ amenity: 'cafe' }, 'amenity=cafe')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* MAPS-ALONG-020..029, 032..034: the Overpass query near a line (PLN-02). One
|
||||
* MAPS-ALONG-020..029, 032..034, 039: the Overpass query near a line (PLN-02). One
|
||||
* query for every kind the index does not know, the candidates of the line's
|
||||
* box kept within reach of the line itself, and unnamed taps and huts kept,
|
||||
* because they are what a hike looks for, while an unnamed garden or cafe is
|
||||
@@ -415,6 +415,48 @@ describe('OsmClient.searchOverpassPoisAlong', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('MAPS-ALONG-039: e-bike charging asks for bicycle tags, keeps an unnamed point with its facts, never a car charger', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(
|
||||
answer([
|
||||
{
|
||||
type: 'node',
|
||||
id: 1,
|
||||
lat: 47.475,
|
||||
lon: 11.1,
|
||||
tags: { amenity: 'charging_station', bicycle: 'designated', 'socket:schuko': '2', fee: 'no' },
|
||||
},
|
||||
{ type: 'node', id: 2, lat: 47.476, lon: 11.1, tags: { amenity: 'charging_station', name: 'Ionity' } },
|
||||
{
|
||||
type: 'node',
|
||||
id: 3,
|
||||
lat: 47.477,
|
||||
lon: 11.1,
|
||||
tags: { amenity: 'charging_station', bicycle: 'yes', operator: 'Stadtwerke', access: 'customers' },
|
||||
},
|
||||
]),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
const out = await osm.searchOverpassPoisAlong('ebike_charging', line(7), 1000);
|
||||
|
||||
const query = queryOf(fetchMock.mock.calls[0]);
|
||||
expect(query).toContain('nwr["amenity"="charging_station"]["bicycle"="designated"](');
|
||||
expect(query).toContain('nwr["amenity"="charging_station"]["bicycle"="yes"](');
|
||||
expect(query).not.toContain('nwr["amenity"="charging_station"](');
|
||||
expect(out.pois.map((poi) => [poi.osm_id, poi.name, poi.category, poi.poi_type])).toEqual([
|
||||
['node:1', '', 'ebike_charging', 'amenity=charging_station&bicycle=designated'],
|
||||
['node:3', 'Stadtwerke', 'ebike_charging', 'amenity=charging_station&bicycle=yes'],
|
||||
]);
|
||||
expect(out.pois[0]?.charging).toEqual({
|
||||
sockets: [{ type: 'schuko', count: 2, kw: null }],
|
||||
capacity: null,
|
||||
fee: false,
|
||||
bicycle: 'designated',
|
||||
access: null,
|
||||
});
|
||||
expect(out.pois[1]?.charging).toMatchObject({ bicycle: 'yes', access: 'customers', sockets: [] });
|
||||
});
|
||||
|
||||
it('MAPS-ALONG-024: more places than the budget are cut to it and said to be', async () => {
|
||||
const many = Array.from({ length: 40 }, (_, i) => ({
|
||||
type: 'node',
|
||||
|
||||
@@ -215,6 +215,45 @@ describe('TourPoiSearchService', () => {
|
||||
expect(plain).not.toHaveProperty('retry_after_s');
|
||||
});
|
||||
|
||||
it('TOUR-POI-018: e-bike charging asks the map search for its own kind and carries what the point states', async () => {
|
||||
const charging = {
|
||||
sockets: [{ type: 'schuko', count: 2, kw: null }],
|
||||
capacity: 2,
|
||||
fee: false,
|
||||
bicycle: 'designated',
|
||||
access: null,
|
||||
};
|
||||
poisAlong.mockResolvedValue(
|
||||
answer([
|
||||
poi('node:1', 47.41, 11.1003, 'ebike_charging', {
|
||||
name: '',
|
||||
poi_type: 'amenity=charging_station&bicycle=designated',
|
||||
charging,
|
||||
}),
|
||||
// A car charger's facts carry no bicycle tag and are never passed on as an e-bike's.
|
||||
poi('node:2', 47.412, 11.1003, 'ebike_charging', {
|
||||
charging: { sockets: [{ type: 'type2', count: 2, kw: 22 }], capacity: null, fee: null },
|
||||
}),
|
||||
poi('node:3', 47.414, 11.1003, 'drinking_water', { name: '' }),
|
||||
]),
|
||||
);
|
||||
const result = await service.search({
|
||||
tour_type: 'bike',
|
||||
categories: ['ebike_charging', 'drinking_water'],
|
||||
corridor_m: 1000,
|
||||
line: LINE,
|
||||
});
|
||||
expect(poisAlong.mock.calls[0]?.[0]).toEqual(['ebike_charging', 'drinking_water']);
|
||||
expect(result.pois.map((found) => [found.id, found.category, found.kind])).toEqual([
|
||||
['node:1', 'ebike_charging', 'amenity=charging_station&bicycle=designated'],
|
||||
['node:2', 'ebike_charging', 'tourism=ebike_charging'],
|
||||
['node:3', 'drinking_water', 'tourism=drinking_water'],
|
||||
]);
|
||||
expect(result.pois[0]?.charging).toEqual(charging);
|
||||
expect(result.pois[1]).not.toHaveProperty('charging');
|
||||
expect(result.pois[2]).not.toHaveProperty('charging');
|
||||
});
|
||||
|
||||
it('TOUR-POI-008: an unnamed place is kept and never merged with another unnamed one nearby', async () => {
|
||||
poisAlong.mockResolvedValue(
|
||||
answer([
|
||||
|
||||
@@ -407,6 +407,9 @@ describe('ToursMcp', () => {
|
||||
expect(description(ToursMcp, 'searchTourPois')).toMatch(/best known places.*highlight: true/);
|
||||
expect(description(ToursMcp, 'searchTourPois')).toContain('a ride, a bike tour');
|
||||
expect(description(ToursMcp, 'searchTourPois')).toContain('a ski and winter tour or a city walk');
|
||||
// BIK-07: e-bike charging only where OpenStreetMap tags it for bicycles, with what it states.
|
||||
expect(description(ToursMcp, 'searchTourPois')).toMatch(/ebike_charging.*bicycle=designated or yes/);
|
||||
expect(description(ToursMcp, 'searchTourPois')).toContain('charging: bicycle, sockets');
|
||||
expect(description(TourLibraryMcp, 'takeOverTour')).toContain('protection');
|
||||
for (const method of ['deletePlace', 'bulkDeletePlaces']) {
|
||||
expect(description(PlacesMcp, method)).toContain(
|
||||
|
||||
Reference in New Issue
Block a user