Files
gods-eye-view/src/layers/bikeshare/source.test.mjs
T
Bilawal SidhuandMiguelGFerreira 2b0fcd4595 fix(bikeshare): address the GBFS proxy by path, not query string (#569)
Supersedes #441 by @MiguelGFerreira, ported onto the current component layout with fixes from review.

Verified before merge: format, package boundaries, unit suite, build, and the browser tracking suite; a browser harness for the change where one applies; adversarial review applied.

Co-authored-by: MiguelGFerreira <[email protected]>
2026-09-14 21:08:12 -05:00

45 lines
1.4 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createBikeshareSource } from './source.js';
test('station source keeps upstream URLs behind the fixed GBFS endpoint', async () => {
const calls = [];
const source = createBikeshareSource({
fetchImpl: async (...args) => {
calls.push(args);
return new Response('{"data":{"stations":[]}}');
},
});
for (const url of [
'file:///etc/passwd',
'http://example.test/stations',
'https://user:[email protected]/stations',
])
await assert.rejects(source.getStations(url), /HTTPS GBFS/);
assert.equal(calls.length, 0);
await source.getStations('https://example.test/stations.json');
const url = new URL(calls[0][0], 'https://app.example');
assert.equal(url.search, '');
assert.equal(
decodeURIComponent(url.pathname.replace(/^\/api\/gbfs\//, '')),
'https://example.test/stations.json',
);
});
test('cancelled station parsing never publishes the response', async () => {
const controller = new AbortController();
const source = createBikeshareSource({
fetchImpl: async () => ({
ok: true,
json: async () => {
controller.abort();
return { data: { stations: [] } };
},
}),
});
await assert.rejects(
source.getStations('https://example.test/stations', {
signal: controller.signal,
}),
{ name: 'AbortError' },
);
});