// API/Mainapi/utils/__tests__/daddylive.test.js const { test } = require('node:test'); const assert = require('node:assert/strict'); const { DADDYLIVE_COUNTRIES, detectCountry, parseChannelsHtml, parsePlayersHtml, buildDeterministicPlayers, extractM3u8FromPlayerHtml, extractIframeSrc, } = require('../daddylive'); test('DADDYLIVE_COUNTRIES is keyed by ISO codes incl. fr, us, gb, plus buckets', () => { assert.equal(DADDYLIVE_COUNTRIES.fr.name, 'France'); assert.equal(DADDYLIVE_COUNTRIES.us.name, 'USA'); assert.equal(DADDYLIVE_COUNTRIES.gb.name, 'UK'); assert.ok(DADDYLIVE_COUNTRIES.other); assert.ok(DADDYLIVE_COUNTRIES.arabic); }); test('detectCountry: explicit country words -> ISO codes', () => { assert.equal(detectCountry('Canal+ France'), 'fr'); assert.equal(detectCountry('ABC USA'), 'us'); assert.equal(detectCountry('Sky Sports Football UK'), 'gb'); assert.equal(detectCountry('Rai 1 Italy'), 'it'); assert.equal(detectCountry('Antena 3 Spain'), 'es'); assert.equal(detectCountry('Star Sports 1 IN'), 'in'); assert.equal(detectCountry('Arte DE'), 'de'); assert.equal(detectCountry('CBC CA'), 'ca'); assert.equal(detectCountry('Azteca 7 MX'), 'mx'); }); test('detectCountry: disambiguation', () => { assert.equal(detectCountry('Movistar Liga de Campeones'), 'es'); assert.equal(detectCountry('beIN Sports MENA English 1'), 'arabic'); }); test('detectCountry: US-network allowlist (no country token) -> us', () => { assert.equal(detectCountry('Cartoon Network'), 'us'); assert.equal(detectCountry('Discovery Channel'), 'us'); assert.equal(detectCountry('Nick JR'), 'us'); }); test('detectCountry: unknown -> other', () => { assert.equal(detectCountry('Astro SuperSport 1'), 'other'); assert.equal(detectCountry('Some Random Channel 123'), 'other'); }); test('detectCountry: bosnia / new zealand / colombia', () => { assert.equal(detectCountry('BHT 1 Bosnia'), 'ba'); assert.equal(detectCountry('New Zealand Rugby'), 'nz'); assert.equal(detectCountry('Win Sports+ Columbia'), 'co'); }); test('parseChannelsHtml: extracts id+name, tags ISO country, drops 18+', () => { const html = `
`; const rows = parseChannelsHtml(html); assert.equal(rows.length, 3); const abc = rows.find((r) => r.rawId === '51'); assert.equal(abc.name, 'ABC USA'); assert.equal(abc.country, 'us'); assert.equal(rows.find((r) => r.rawId === '121').country, 'fr'); assert.equal(rows.find((r) => r.rawId === '304').country, 'us'); assert.equal(rows.find((r) => r.rawId === '501'), undefined); }); test('parseChannelsHtml: drops 18+ by name even when id is outside 501-520', () => { const html = ``; assert.deepEqual(parseChannelsHtml(html), []); }); test('parseChannelsHtml: empty / garbage html -> []', () => { assert.deepEqual(parseChannelsHtml(''), []); assert.deepEqual(parseChannelsHtml('