Support script and URL sources, automatic Sessionize polling, staff-linked service sessions, chronological agenda blocks, and inline Placeholders. Fix demo mode to use the active event date and document deployed behavior with regression coverage.
46 lines
3.1 KiB
JavaScript
46 lines
3.1 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { normalizeSessionizeSource, parseGridSmart, readSessionizeSource } = require('../src/sessionize-source');
|
|
const url = 'https://sessionize.com/api/v2/z0s5f2j2/view/GridSmart';
|
|
const card = (id, title, classes = '') => `<div class="sz-session ${classes}" data-sessionid="${id}">
|
|
<div class="sz-session__room">Main Stage</div>
|
|
<div class="sz-session__time" data-sztz="TimeWithDuration|en-US|2026-10-23T06:30:00.0000000Z|2026-10-23T07:00:00.0000000Z"></div>
|
|
<h3 class="sz-session__title">${title}</h3></div>`;
|
|
|
|
test('normalizes URL and script tag without executing code', () => {
|
|
assert.equal(normalizeSessionizeSource(url), url);
|
|
assert.equal(normalizeSessionizeSource(`<script type="text/javascript" src='${url}'></script>`), url);
|
|
for (const input of ['https://example.org/a', 'http://sessionize.com/api/v2/test/view/All',
|
|
'https://sessionize.com@localhost/api/v2/test/view/All', '<script>alert(1)</script>',
|
|
'https://sessionize.com:4430/api/v2/test/view/All']) assert.throws(() => normalizeSessionizeSource(input));
|
|
});
|
|
test('extracts service identity, entities, room, local time and deduplicates cards', () => {
|
|
const html = card('service-id', 'Arrival & Coffee', 'sz-session--service') + card('service-id', 'Arrival & Coffee', 'sz-session--service') + card('talk-id', 'Talk');
|
|
const result = parseGridSmart(html, 120);
|
|
assert.equal(result.sessions.length, 2);
|
|
assert.deepEqual(result.sessions[0], { external_id: 'service-id', title: 'Arrival & Coffee', description: null,
|
|
room: 'Main Stage', date: '2026-10-23', start_time: '08:30:00', end_time: '09:00:00',
|
|
is_service_session: true, speakers: [], level: null, area: null });
|
|
assert.equal(result.sessions[1].is_service_session, false);
|
|
});
|
|
test('rejects empty, malformed and conflicting schedules', () => {
|
|
assert.throws(() => parseGridSmart('', 120));
|
|
assert.throws(() => parseGridSmart(card('id', 'Talk').replace('2026-10-23T06:30:00.0000000Z', 'bad'), 120));
|
|
assert.throws(() => parseGridSmart(card('id', 'Talk') + card('id', 'Different'), 120));
|
|
assert.throws(() => parseGridSmart(card('id', 'Talk')));
|
|
});
|
|
test('reads loader and HTML without executing embed JavaScript', async () => {
|
|
const calls = [];
|
|
const result = await readSessionizeSource(`<script src="${url}"></script>`, { fetchImpl: async source => {
|
|
calls.push(source);
|
|
return { ok: true, text: async () => source.includes('under=True') ? card('id', 'Lunch', 'sz-session--plenum') : "sessionize.eventTimezone = 'UTC+02';" };
|
|
} });
|
|
assert.equal(result.format, 'gridsmart');
|
|
assert.equal(result.payload.sessions[0].is_service_session, true);
|
|
assert.deepEqual(calls, [url, `${url}?under=True`]);
|
|
});
|
|
test('retains JSON API compatibility and fails on upstream errors', async () => {
|
|
const result = await readSessionizeSource(url.replace('GridSmart', 'All'), { fetchImpl: async () => ({ ok: true, text: async () => '{"sessions":[]}' }) });
|
|
assert.equal(result.format, 'json');
|
|
await assert.rejects(readSessionizeSource(url, { fetchImpl: async () => ({ ok: false, status: 503 }) }), /503/);
|
|
}); |