import assert from 'node:assert/strict' import test from 'node:test' import { getRoomLinks } from './roomLinks.js' test('production links target the PC routes, not the administration path', () => { assert.deepEqual(getRoomLinks(2, { origin: 'https://live.example.com', development: false }), { viewer: 'https://live.example.com/#/live/2', studio: 'https://live.example.com/#/studio/2', }) }) test('custom client origins and base paths discard unrelated query and hash state', () => { assert.deepEqual(getRoomLinks('12', { origin: 'https://admin.example.com', clientBaseUrl: 'https://client.example.com/player?token=unused#/old', }), { viewer: 'https://client.example.com/player/#/live/12', studio: 'https://client.example.com/player/#/studio/12', }) }) test('development links use the PC dev server and support an explicit port override', () => { assert.equal(getRoomLinks(1, { origin: 'http://localhost:8080', development: true }).viewer, 'http://localhost:5173/#/live/1') assert.equal(getRoomLinks(1, { origin: 'http://localhost:8080', development: true, clientBaseUrl: 'http://localhost:5174/', }).studio, 'http://localhost:5174/#/studio/1') }) test('client base supports a relative path and a static HTML entrypoint', () => { assert.equal(getRoomLinks(3, { origin: 'https://live.example.com', clientBaseUrl: '/pc/index.html', }).viewer, 'https://live.example.com/pc/index.html#/live/3') }) test('invalid room IDs, executable schemes and URL credentials are rejected', () => { for (const id of [0, -1, 1.2, '2/other', undefined]) { assert.throws(() => getRoomLinks(id, { origin: 'https://live.example.com' })) } for (const clientBaseUrl of ['javascript:alert(1)', 'https://user:password@example.com/']) { assert.throws(() => getRoomLinks(2, { origin: 'https://live.example.com', clientBaseUrl })) } })