Creation nouvelle interface Docker Vehicule et Multimedia
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { telemetry, profiles } from './telemetry.mjs';
|
||||
import { createServer } from './server.mjs';
|
||||
|
||||
test('demo values remain bounded and identical across displays', () => {
|
||||
for (const profile of profiles) for (let t = 0; t < 300000; t += 250) {
|
||||
const d = telemetry(profile, t);
|
||||
assert.ok(d.speedKph >= 0 && d.speedKph <= 220);
|
||||
assert.ok(d.rpm >= 0 && d.rpm <= 7000);
|
||||
assert.equal(d.source, 'demo');
|
||||
assert.deepEqual(d, telemetry(profile, t));
|
||||
if (profile === 'arret') assert.equal(d.speedKph, 0);
|
||||
}
|
||||
assert.throws(() => telemetry('can'), RangeError);
|
||||
});
|
||||
|
||||
test('HTTP contract, invalid profiles, isolation from legacy and read-only API', async () => {
|
||||
const server = createServer();
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
const base = `http://127.0.0.1:${server.address().port}`;
|
||||
try {
|
||||
assert.equal((await (await fetch(`${base}/api/health`)).json()).status, 'ok');
|
||||
assert.equal((await (await fetch(`${base}/api/telemetry?profile=arret`)).json()).speedKph, 0);
|
||||
assert.equal((await fetch(`${base}/api/telemetry?profile=wrong`)).status, 400);
|
||||
assert.equal((await fetch(`${base}/api/telemetry`, { method: 'POST' })).status, 405);
|
||||
for (const path of ['/WebControl/main.py', '/ssl/key.pem', '/package.json', '/cmd']) {
|
||||
assert.equal((await fetch(base + path)).status, 404);
|
||||
}
|
||||
assert.match(await (await fetch(base)).text(), /CARIA/);
|
||||
} finally { await new Promise(resolve => server.close(resolve)); }
|
||||
});
|
||||
Reference in New Issue
Block a user