Files
Nodecast/test/liveChannelProjection.test.js
blomios 63a5946e75 fix(live): prevent analysis crash on large catalogs (#26)
Bound synchronous live channel enrichment and tolerate minimal projection payloads so analysis and listings do not blank the UI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-06 15:13:48 +02:00

36 lines
1.8 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const projection = require('../public/js/services/liveChannelProjection.js');
test('maps projected logical channels to the frontend variant format', () => {
const response = {
projection: { status: 'success', stale: false },
channels: [{
id: 'logical:one', fingerprint: 'news', displayName: 'News',
variants: [{
id: 42, sourceId: 7, name: 'News HD', categoryId: 'News',
streamIcon: 'logo.png', streamUrl: 'https://stream.test/live',
tvgId: 'news.fr', isFavorite: true, isHidden: true
}]
}]
};
const mapped = projection.mapResponse(response, [{ id: 7, type: 'm3u', name: 'Local' }]);
assert.deepEqual(mapped.channels[0], {
id: '42', sourceId: 7, name: 'News HD', categoryId: 'News',
streamIcon: 'logo.png', streamUrl: 'https://stream.test/live', tvgId: 'news.fr',
isFavorite: true, isHidden: true, logicalId: 'logical:one',
logicalFingerprint: 'news', logicalDisplayName: 'News',
streamId: '42', tvgLogo: 'logo.png',
url: 'https://stream.test/live', groupTitle: 'News', sourceType: 'm3u', sourceName: 'Local',
language: { code: 'und', short: 'UND', label: 'Unknown', confidence: 0 }
});
assert.equal(mapped.favorites.has('7:42'), true);
assert.equal(mapped.hiddenItems.has('channel:7:42'), true);
});
test('rejects stale projections so ChannelList can use its legacy fallback', () => {
assert.equal(projection.canUse({ projection: { stale: true }, channels: [] }), false);
assert.equal(projection.canUse({ projection: { stale: false }, channels: [] }), true);
assert.equal(projection.canUse(null), false);
});