mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +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:
@@ -19,6 +19,7 @@ export const TOUR_POI_CATEGORIES = [
|
||||
'cafe',
|
||||
'restaurant',
|
||||
'market',
|
||||
'ebike_charging',
|
||||
] as const;
|
||||
export const tourPoiCategorySchema = z.enum(TOUR_POI_CATEGORIES);
|
||||
export type TourPoiCategory = z.infer<typeof tourPoiCategorySchema>;
|
||||
|
||||
@@ -107,6 +107,52 @@ describe('tour POI search contracts (PLN-02)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('e-bike charging along a bike tour (BIK-07)', () => {
|
||||
const charger = {
|
||||
id: 'node:7',
|
||||
name: '',
|
||||
lat: 47.4,
|
||||
lng: 11.1,
|
||||
category: 'ebike_charging',
|
||||
kind: 'amenity=charging_station&bicycle=designated',
|
||||
source: 'openstreetmap',
|
||||
address: null,
|
||||
website: null,
|
||||
phone: null,
|
||||
opening_hours: null,
|
||||
distance_m: 80,
|
||||
along_m: 5200,
|
||||
};
|
||||
const answer = { truncated: false, partial: false, capped: false, unavailable: [] };
|
||||
|
||||
it('is offered to a bike tour after its first three, and to no other tour', () => {
|
||||
expect(TOUR_POI_CATEGORIES_BY_TYPE.bike.slice(0, 3)).toEqual(['drinking_water', 'bike_repair', 'food']);
|
||||
expect(TOUR_POI_CATEGORIES_BY_TYPE.bike).toContain('ebike_charging');
|
||||
for (const [type, categories] of Object.entries(TOUR_POI_CATEGORIES_BY_TYPE))
|
||||
if (type !== 'bike') expect(categories).not.toContain('ebike_charging');
|
||||
const search = { tour_type: 'bike', categories: ['ebike_charging'], corridor_m: 1000, line };
|
||||
expect(tourPoiSearchRequestSchema.safeParse(search).success).toBe(true);
|
||||
});
|
||||
|
||||
it('carries what the point states, and leaves the field off a place that is no charger', () => {
|
||||
const charging = {
|
||||
bicycle: 'designated',
|
||||
sockets: [{ type: 'schuko', count: 2, kw: null }],
|
||||
capacity: null,
|
||||
fee: false,
|
||||
access: null,
|
||||
};
|
||||
const parsed = tourPoiSearchResponseSchema.parse({ ...answer, pois: [{ ...charger, charging }, charger] });
|
||||
expect(parsed.pois[0]?.charging).toEqual(charging);
|
||||
expect(parsed.pois[1]).not.toHaveProperty('charging');
|
||||
});
|
||||
|
||||
it('refuses a charger that does not say it is for bicycles', () => {
|
||||
const charging = { bicycle: 'no', sockets: [], capacity: null, fee: null, access: null };
|
||||
expect(tourPoiSearchResponseSchema.safeParse({ ...answer, pois: [{ ...charger, charging }] }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('city walk themes (CW-05)', () => {
|
||||
it('offers four themes, each a search a walk may ask for', () => {
|
||||
expect(WALK_THEME_KEYS).toEqual(['culture', 'parks', 'food', 'mixed']);
|
||||
|
||||
@@ -23,7 +23,19 @@ export {
|
||||
/** The categories each planned tour type offers, the most asked first. */
|
||||
export const TOUR_POI_CATEGORIES_BY_TYPE: Record<PlannableTourType, readonly TourPoiCategory[]> = {
|
||||
hike: ['viewpoint', 'shelter', 'drinking_water', 'food', 'peak', 'toilets', 'picnic', 'campsite', 'sights'],
|
||||
bike: ['drinking_water', 'bike_repair', 'food', 'viewpoint', 'toilets', 'shelter', 'picnic', 'campsite', 'sights'],
|
||||
// BIK-07: e-bike charging after the first three, so a new bike tour still starts on those.
|
||||
bike: [
|
||||
'drinking_water',
|
||||
'bike_repair',
|
||||
'food',
|
||||
'ebike_charging',
|
||||
'viewpoint',
|
||||
'toilets',
|
||||
'shelter',
|
||||
'picnic',
|
||||
'campsite',
|
||||
'sights',
|
||||
],
|
||||
kayak: ['slipway', 'boat_rental', 'drinking_water', 'food', 'toilets', 'picnic', 'campsite', 'shelter'],
|
||||
walk: ['sights', 'museum', 'park', 'viewpoint', 'cafe', 'restaurant', 'market', 'toilets', 'drinking_water'],
|
||||
run: ['drinking_water', 'toilets', 'park', 'viewpoint', 'cafe', 'food', 'shelter', 'sights'],
|
||||
@@ -71,6 +83,28 @@ export const tourPoiSearchRequestSchema = z
|
||||
.strict();
|
||||
export type TourPoiSearchRequest = z.infer<typeof tourPoiSearchRequestSchema>;
|
||||
|
||||
/**
|
||||
* BIK-07: what a charging point for e-bikes says about itself, each field only
|
||||
* as OpenStreetMap states it. The search keeps only points tagged for bicycles,
|
||||
* so `bicycle` is always one of the two; a socket, fee or access left unsaid is
|
||||
* null or missing, never a yes.
|
||||
*/
|
||||
const tourPoiChargingSchema = z.object({
|
||||
/** `designated` is made for bikes, `yes` lets them charge. */
|
||||
bicycle: z.enum(['yes', 'designated']),
|
||||
/** One entry per socket family stated, with how many and how fast where said. */
|
||||
sockets: z.array(
|
||||
z.object({ type: z.string(), count: z.number().int().positive().nullable(), kw: z.number().positive().nullable() }),
|
||||
),
|
||||
/** How many bikes can charge at once. */
|
||||
capacity: z.number().int().positive().nullable(),
|
||||
/** true costs money, false is free, null is not said. */
|
||||
fee: z.boolean().nullable(),
|
||||
/** OpenStreetMap's own access value, `customers` or `private` style. */
|
||||
access: z.string().nullable(),
|
||||
});
|
||||
export type TourPoiCharging = z.infer<typeof tourPoiChargingSchema>;
|
||||
|
||||
/** One place found: what the source says about it, and where it lies against the line. */
|
||||
export const tourPoiSchema = z.object({
|
||||
/** The source's own id, `node:123` style for OpenStreetMap. */
|
||||
@@ -94,6 +128,8 @@ export const tourPoiSchema = z.object({
|
||||
along_m: z.number().nonnegative(),
|
||||
/** One of the best known places along the line (tour-highlights); absent means not one. */
|
||||
highlight: z.boolean().optional(),
|
||||
/** BIK-07: what an e-bike charging point states; absent on every other kind. */
|
||||
charging: tourPoiChargingSchema.optional(),
|
||||
});
|
||||
export type TourPoi = z.infer<typeof tourPoiSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user