41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { test } from 'node:test';
|
|||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { resolveCallPageUrl } from './callPageUrl';
|
||
|
|
|
||
|
|
const URL_OK = 'https://call.chat.example.org/public/element-call/index.html';
|
||
|
|
|
||
|
|
test('uses an absolute https URL on the web', () => {
|
||
|
|
assert.equal(resolveCallPageUrl(URL_OK, false), URL_OK);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('strips a query or hash (the app adds its own parameters)', () => {
|
||
|
|
assert.equal(resolveCallPageUrl(`${URL_OK}?x=1#y`, false), URL_OK);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('allows http only on localhost (development)', () => {
|
||
|
|
assert.equal(
|
||
|
|
resolveCallPageUrl('http://127.0.0.1:5174/public/element-call/index.html', false),
|
||
|
|
'http://127.0.0.1:5174/public/element-call/index.html',
|
||
|
|
);
|
||
|
|
assert.equal(resolveCallPageUrl('http://call.example.org/index.html', false), undefined);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('desktop keeps the bundled page', () => {
|
||
|
|
assert.equal(resolveCallPageUrl(URL_OK, true), undefined);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('anything else falls back to the bundled page', () => {
|
||
|
|
[
|
||
|
|
undefined,
|
||
|
|
null,
|
||
|
|
42,
|
||
|
|
'',
|
||
|
|
' ',
|
||
|
|
'not a url',
|
||
|
|
'/public/element-call/index.html',
|
||
|
|
'http://call.chat.example.org/index.html',
|
||
|
|
['javascript', 'alert(1)'].join(':'),
|
||
|
|
'data:text/html,x',
|
||
|
|
].forEach((v) => assert.equal(resolveCallPageUrl(v, false), undefined, String(v)));
|
||
|
|
});
|