import { test } from '@japa/runner' import { buildNzb } from '#lib/nzb/index' test.group('nzb / buildNzb', () => { test('writes files, groups and ordered segments', ({ assert }) => { const xml = buildNzb( [ { name: 'Some.Show.S01E01.mkv', poster: 'poster@example.invalid', date: 1_790_000_000_000, groups: ['alt.binaries.test'], segments: { '2': { id: 'b@x', size: 700 }, '1': { id: 'a@x', size: 800 } }, }, ], { title: 'Some.Show.S01E01' } ) assert.include(xml, 'Some.Show.S01E01') assert.include(xml, 'subject=""Some.Show.S01E01.mkv" yEnc (1/2)"') assert.include(xml, 'date="1790000000"') assert.include(xml, 'alt.binaries.test') assert.isBelow(xml.indexOf('>a@x<'), xml.indexOf('>b@x<')) assert.include(xml, 'a@x') }) }) test.group('nzb / parseNzb', () => { test('reads meta, files, groups and segments, decoding entities', async ({ assert }) => { const { parseNzb } = await import('#lib/nzb/index') const xml = ` Some.Show.S01E01s3cr&t alt.binaries.bloaf b@x.local <a@x.local> ` const nzb = parseNzb(xml)! assert.deepEqual(nzb.meta, { name: 'Some.Show.S01E01', password: 's3cr&t' }) assert.lengthOf(nzb.files, 1) assert.equal(nzb.files[0].subject, 'Wond40 "Nachbe" x.part1.rar" yEnc (0001/2)') assert.deepEqual(nzb.files[0].groups, ['alt.binaries.bloaf']) assert.deepEqual(nzb.files[0].segments, [ { number: 1, bytes: 2000, id: 'a@x.local' }, { number: 2, bytes: 1000, id: 'b@x.local' }, ]) assert.isNull(parseNzb('not an nzb')) }) })