mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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]>
45 lines
1.4 KiB
JavaScript
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' },
|
|
);
|
|
});
|