60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { buildPlaylist } = require('../src/playlist');
|
|
|
|
function fakeRequest() {
|
|
return { headers: { host: 'example.test:8080' }, socket: {} };
|
|
}
|
|
|
|
const event = {
|
|
key: 'a',
|
|
title: 'Standard de Liège - SK Beveren',
|
|
startAt: new Date('2026-11-06T18:25:00Z'),
|
|
endAt: new Date('2026-11-06T20:55:00Z'),
|
|
};
|
|
|
|
test('playlist always contains three fixed channels', () => {
|
|
const scheduler = {
|
|
getSlotCount: () => 3,
|
|
getSlotEvent: (index) => (index === 0 ? event : null),
|
|
};
|
|
const body = buildPlaylist(fakeRequest(), scheduler);
|
|
const lines = body.trim().split('\n');
|
|
|
|
assert.equal(lines[0], '#EXTM3U');
|
|
assert.equal(
|
|
lines[1],
|
|
'#EXTINF:-1 tvg-id="jupiler-1" tvg-name="Jupiler 1" tvg-chno="1",Jupiler 1'
|
|
);
|
|
assert.equal(lines[2], 'http://example.test:8080/stream/1');
|
|
assert.ok(body.includes('#EXTINF:-1 tvg-id="jupiler-2" tvg-name="Jupiler 2" tvg-chno="2",Jupiler 2'));
|
|
assert.ok(body.includes('#EXTINF:-1 tvg-id="jupiler-3" tvg-name="Jupiler 3" tvg-chno="3",Jupiler 3'));
|
|
assert.ok(body.includes('http://example.test:8080/stream/3'));
|
|
});
|
|
|
|
test('channel metadata stays identical when the assigned event changes', () => {
|
|
const first = {
|
|
getSlotCount: () => 3,
|
|
getSlotEvent: (index) => (index === 0 ? event : null),
|
|
};
|
|
const second = {
|
|
getSlotCount: () => 3,
|
|
getSlotEvent: (index) =>
|
|
index === 0
|
|
? {
|
|
key: 'b',
|
|
title: 'Anderlecht - Genk',
|
|
startAt: new Date('2026-11-06T21:00:00Z'),
|
|
endAt: new Date('2026-11-06T23:30:00Z'),
|
|
}
|
|
: null,
|
|
};
|
|
const channelLines = (body) => body.split('\n').filter((line) => line.startsWith('#EXTINF'));
|
|
assert.deepEqual(
|
|
channelLines(buildPlaylist(fakeRequest(), first)),
|
|
channelLines(buildPlaylist(fakeRequest(), second))
|
|
);
|
|
});
|