feat(roadtrip): what a charger costs, before it is a stop

A tester found the charging panel once a station was on the trip and asked
for it while still deciding. The availability and the published tariffs were
reachable only for a saved place: the route takes a places id, and a hit
found along the route has no row yet.

ChargingService.load already needed nothing but a coordinate and a name, so
it now has a public method that says so, behind a trip-scoped route with the
same guard stack, a Zod contract in shared, and the parallel MCP tool in this
same change. Same service, same caches, so a station looked at in the dialog
and then added keys the entry already fetched. Trip-scoped even though the
trip is not part of the question: without :tripId the trip access guard goes
too, and what is left is an open proxy in front of somebody else's public API.

It renders in the add dialog, and only while the selected kind is charging,
so a fuel or food stop costs nothing and one opened dialog is one lookup.
Deliberately not per result row: the corridor search publishes box by box,
every mounted panel owns a refresh timer, a cache miss can cost seven
upstream requests, and a station in a dense charging park is the case the
upstream matcher refuses as ambiguous.

Power and socket counts are not in this answer and were not asked of it.
They are OSM tag data and already ride along on the corridor row for free.
This commit is contained in:
Maurice
2026-09-14 12:28:47 +02:00
parent accdd5905e
commit 00d00be1c0
37 changed files with 507 additions and 21 deletions
+20
View File
@@ -146,6 +146,26 @@ describe('Roadtrip e2e (real guard chain + temp SQLite)', () => {
expect(read).toHaveBeenCalledTimes(1);
} finally { read.mockRestore(); }
});
it('gates the coordinate lookup like the saved stop and validates before fetching', async () => {
const lookup = vi.spyOn(app.get(ChargingService), 'lookup').mockResolvedValue({} as never);
const body = { lat: 48.137, lng: 11.575, name: 'Ladepark Nord' };
const post = () => request(server).post('/api/trips/5/roadtrip/charging-lookup').set('Cookie', cookie());
try {
await request(server).post('/api/trips/5/roadtrip/charging-lookup').send(body).expect(401);
await request(server).post('/api/trips/6/roadtrip/charging-lookup').set('Cookie', cookie()).send(body).expect(404);
await post().send({ ...body, lat: 91 }).expect(400);
// A list is the shape a caller would reach for to fan a whole corridor out in one
// request. There is no rate limiter here and each miss costs the upstream registry
// several requests, so the contract refuses it before anything leaves the server.
await post().send([body]).expect(400);
expect(lookup).not.toHaveBeenCalled();
await post().send(body).expect(200);
expect(lookup).toHaveBeenCalledWith(48.137, 11.575, 'Ladepark Nord');
setAddon(false);
await post().send(body).expect(404);
expect(lookup).toHaveBeenCalledTimes(1);
} finally { lookup.mockRestore(); }
});
it('validates Google route preview and import before executing either service', async () => {
const routes = app.get(GoogleRouteService);
const preview = vi.spyOn(routes, 'preview').mockResolvedValue({ stops: [] });