mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
00d00be1c0
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.
54 lines
2.6 KiB
TypeScript
54 lines
2.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { chargingRepo } from './chargingRepo'
|
|
import { isEffectivelyOffline } from '../sync/networkMode'
|
|
import { apiClient } from '../api/client'
|
|
|
|
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn(() => false) }))
|
|
vi.mock('../api/client', () => ({ apiClient: { get: vi.fn(), post: vi.fn() } }))
|
|
|
|
const info = {
|
|
checkedAt: new Date().toISOString(), status: 'ok' as const, station: 'Ladepark Nord',
|
|
source: 'Operator', sourceUrl: 'https://example.com', license: 'CC-0',
|
|
updatedAt: new Date().toISOString(), stale: false, available: 2, total: 4, unknown: 0,
|
|
tariffs: [], pricesUnavailable: false,
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
vi.mocked(isEffectivelyOffline).mockReturnValue(false)
|
|
vi.mocked(apiClient.post).mockResolvedValue({ data: info })
|
|
})
|
|
|
|
describe('charging data for a station that is not a stop yet', () => {
|
|
it('FE-ROADTRIP-CHARGEREPO-001: asks the trip-scoped route with the coordinate and the name', async () => {
|
|
expect(await chargingRepo.readAt(1, 48.137, 11.575, 'Ladepark Nord')).toEqual(info)
|
|
expect(apiClient.post).toHaveBeenCalledWith('/trips/1/roadtrip/charging-lookup', { lat: 48.137, lng: 11.575, name: 'Ladepark Nord' })
|
|
// Never the saved-stop route: that one takes a place id, which a hit found along
|
|
// the route does not have.
|
|
expect(apiClient.get).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('FE-ROADTRIP-CHARGEREPO-002: the same station twice is one request, a different one is another', async () => {
|
|
const first = chargingRepo.readAt(2, 48.2, 11.2, 'Ladepark')
|
|
const again = chargingRepo.readAt(2, 48.2, 11.2, 'Ladepark')
|
|
expect(await first).toEqual(await again)
|
|
expect(apiClient.post).toHaveBeenCalledTimes(1)
|
|
// A charger 200 m down the road is a different charger, cache or no cache.
|
|
await chargingRepo.readAt(2, 48.202, 11.2, 'Ladepark')
|
|
expect(apiClient.post).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
it('FE-ROADTRIP-CHARGEREPO-003: offline it refuses rather than queueing a read', async () => {
|
|
vi.mocked(isEffectivelyOffline).mockReturnValue(true)
|
|
await expect(chargingRepo.readAt(3, 48.3, 11.3, 'Ladepark')).rejects.toThrow('Offline')
|
|
expect(apiClient.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('FE-ROADTRIP-CHARGEREPO-004: an answer that is not the contract is rejected, not rendered', async () => {
|
|
// Availability is nullable on purpose and the panel branches on it; a string where
|
|
// a count belongs must not reach it.
|
|
vi.mocked(apiClient.post).mockResolvedValue({ data: { ...info, available: 'lots' } })
|
|
await expect(chargingRepo.readAt(4, 48.4, 11.4, 'Ladepark')).rejects.toThrow()
|
|
})
|
|
})
|