style: adopt formatting for CCTV and radio provider modules

This commit is contained in:
Sameh Khamis committed 2026-09-12 12:09:04 -07:00
1 parent 79b4929b88
commit c69416ff6b
13 files changed
+862 -364

No files matched your search

+44 -11
View File
@@ -9,11 +9,21 @@ import { localProviderPlugins } from '../../server/providers/local.js';
function install(plugin) {
let handler;
plugin.configureServer({ middlewares: { use(_route, fn) { handler = fn; } } });
plugin.configureServer({
middlewares: {
use(_route, fn) {
handler = fn;
},
},
});
return async (url) => {
const res = {
writeHead(status, headers) { Object.assign(this, { status, headers }); },
end(body) { this.body = body; },
writeHead(status, headers) {
Object.assign(this, { status, headers });
},
end(body) {
this.body = body;
},
};
await handler({ url, method: 'GET' }, res);
return res;
@@ -24,14 +34,29 @@ function fixture(t, id) {
const root = mkdtempSync(path.join(tmpdir(), 'gev-cctv-'));
t.after(() => rmSync(root, { recursive: true, force: true }));
mkdirSync(path.join(root, 'config'));
writeFileSync(path.join(root, 'config/cctv_sources.austin.json'), JSON.stringify([
{ id, name: '<Camera & test>', lat: 30.27, lon: -97.74, feedType: 'video' },
]));
writeFileSync(
path.join(root, 'config/cctv_sources.austin.json'),
JSON.stringify([
{
id,
name: '<Camera & test>',
lat: 30.27,
lon: -97.74,
feedType: 'video',
},
]),
);
return root;
}
function isolate(t) {
for (const name of ['CCTV_SOURCES_FILE', 'CCTV_SOURCES_JSON', 'CCTV_FORCE_AUSTIN', 'GOOGLE_MAPS_SERVER_API_KEY', 'GOOGLE_MAPS_API_KEY']) {
for (const name of [
'CCTV_SOURCES_FILE',
'CCTV_SOURCES_JSON',
'CCTV_FORCE_AUSTIN',
'GOOGLE_MAPS_SERVER_API_KEY',
'GOOGLE_MAPS_API_KEY',
]) {
const previous = process.env[name];
delete process.env[name];
t.after(() => {
@@ -39,7 +64,9 @@ function isolate(t) {
else process.env[name] = previous;
});
}
t.mock.method(globalThis, 'fetch', () => { throw Error('fixture must not fetch'); });
t.mock.method(globalThis, 'fetch', () => {
throw Error('fixture must not fetch');
});
}
test('CCTV instances resolve their own application source root and isolate catalogs and health', async (t) => {
@@ -49,8 +76,14 @@ test('CCTV instances resolve their own application source root and isolate catal
const [a, b] = await Promise.all([first('/sources'), second('/sources')]);
assert.equal(a.status, 200);
assert.equal(b.status, 200);
assert.deepEqual(JSON.parse(a.body).sources.map(s => s.id), ['first']);
assert.deepEqual(JSON.parse(b.body).sources.map(s => s.id), ['second']);
assert.deepEqual(
JSON.parse(a.body).sources.map((s) => s.id),
['first'],
);
assert.deepEqual(
JSON.parse(b.body).sources.map((s) => s.id),
['second'],
);
const stream = JSON.parse((await first('/stream/first')).body);
assert.equal(stream.feedType, 'mp4');
assert.equal(stream.mediaUrl, '/api/cctv/media/first');
@@ -66,6 +99,6 @@ test('composition creates exactly one CCTV and radio provider without acquisitio
isolate(t);
const plugins = localProviderPlugins();
for (const factory of [cctvProxy, radioBrowserProxy]) {
assert.equal(plugins.filter(p => p.name === factory().name).length, 1);
assert.equal(plugins.filter((p) => p.name === factory().name).length, 1);
}
});