'use strict'; const test = require('node:test'); const assert = require('node:assert'); const V = require('../src/engine/validate'); const base = (over = {}) => ({ name: 'Canal', slug: 'c1', cfg: { input: { kind: 'srt', mode: 'caller', host: '192.168.10.40', port: 10013, latency_ms: 200 }, asr: { lang: 'es' }, tr: { langs: ['en'] }, hls: { enabled: true }, srt: { enabled: true, mode: 'listener', port: 9002, delay_s: 24, cc608: { es: 'CC1', en: 'CC3' }, cc708: { es: 1, en: 2 } }, ...over, }, }); test('canal válido se normaliza', () => { const c = V.channel(base()); assert.strictEqual(c.cfg.srt.port, 9002); assert.deepStrictEqual(c.cfg.srt.cc608, { es: 'CC1', en: 'CC3' }); assert.strictEqual(c.cfg.asr.url, 'http://192.168.2.10:8004'); }); test('dos canales con el mismo puerto SRT no se pueden guardar', () => { const a = V.channel(base()); const b = V.channel({ ...base(), slug: 'c2' }); assert.throws(() => V.conflicts(b, [{ name: 'Canal', ...a }]), /9002/); // El siguiente también está tomado (prueba interna de la 078). const c = V.channel({ ...base({ srt: { ...base().cfg.srt, port: 9003 } }), slug: 'c3' }); assert.throws(() => V.conflicts(c, [{ name: 'Canal', ...a }]), /9003/); // Entrada SRT listener contra salida de otro canal. const d = V.channel({ ...base({ input: { kind: 'srt', mode: 'listener', port: 9002 }, srt: { enabled: false } }), slug: 'c4' }); assert.throws(() => V.conflicts(d, [{ name: 'Canal', ...a }]), /9002/); }); test('id repetido', () => { const a = V.channel(base()); assert.throws(() => V.conflicts(V.channel({ ...base(), cfg: { ...base().cfg, srt: { enabled: false } } }), [{ name: 'Canal', ...a }]), /id corto/); }); test('URL de entrada mal armada', () => { assert.throws(() => V.channel(base({ input: { kind: 'hls', url: 'htp:/x' } })), /http/); assert.throws(() => V.channel(base({ input: { kind: 'hls', url: 'https://cdn/x.mp4' } })), /m3u8/); assert.throws(() => V.channel(base({ input: { kind: 'udp', url: 'udp://239.1.1.1' } })), /UDP/); assert.throws(() => V.channel(base({ input: { kind: 'srt', mode: 'caller', host: '', port: 1 } })), /host/); assert.throws(() => V.channel(base({ input: { kind: 'srt', mode: 'caller', host: 'a', port: 1, passphrase: 'corta' } })), /passphrase/); }); test('608 repetido entre idiomas y puertos del sistema', () => { assert.throws(() => V.channel(base({ srt: { ...base().cfg.srt, cc608: { es: 'CC1', en: 'CC1' } } })), /repetido/); assert.throws(() => V.channel(base({ srt: { ...base().cfg.srt, port: 4699 } })), /sistema/); assert.throws(() => V.channel({ ...base(), slug: 't13-cc' }), /-cc/); });