Skip to content
File

Blob: worker/tests/bundle.test.mjs

javascript44 lines
1import assert from 'node:assert/strict';
2import { test } from 'node:test';
3import { createHarness } from './helpers/sfu.mjs';
4 
5test(
6 'production bundle authenticates, expires leases and replaces obsolete sessions independently',
7 { timeout: 60000 },
8 async (t) => {
9 let expired = false;
10 const h = await createHarness(t, ({ path }) => {
11 if (expired && /\/sessions\/session-[12](?:\/|$)/.test(path))
12 return Response.json({ errorCode: 'internal_error' }, { status: 503 });
13 });
14 assert.equal((await h.call('/status')).status, 401);
15 await h.login();
16 await h.start();
17 const viewer = await h.viewer();
18 assert.equal((await h.call(`/viewers/${viewer.id}/claim`, {}, viewer.owner)).status, 200);
19 const deadline = Date.now() + 28000;
20 while (Date.now() < deadline) {
21 await h.status();
22 await new Promise((resolve) => setTimeout(resolve, 500));
23 }
24 assert.equal((await h.status()).controller, null);
25 assert.ok(
26 h.calls.some(
27 (call) =>
28 call.path.endsWith('/datachannels/update') &&
29 call.input.dataChannels[0].canReply === false,
30 ),
31 );
32 expired = true;
33 const before = h.calls.length;
34 await h.start({ bootId: 'b'.repeat(32) });
35 const status = await h.status();
36 assert.equal(status.viewers, 0);
37 assert.equal(status.online, true);
38 assert.equal(
39 h.calls.slice(before).some((call) => /\/sessions\/session-[12](?:\/|$)/.test(call.path)),
40 false,
41 );
42 },
43);