import { test } from '@japa/runner' import { TEXT_KINDS, TEXTS_PER_KIND, TEXT_MAX, textKindCode, textKindName, textsToStore, } from '#lib/release/text_kind' test.group('release text kinds', () => { test('names and codes map both ways; the codes are fixed', ({ assert }) => { assert.deepEqual(TEXT_KINDS, { name: 1, file: 2, nfo: 3, par2: 4, media: 5, member: 6 }) for (const [name, code] of Object.entries(TEXT_KINDS)) { assert.equal(textKindCode(name), code) assert.equal(textKindName(code), name) assert.equal(textKindName(String(code)), name) } }) test('an unknown name throws, an unknown code reads as unknown', ({ assert }) => { assert.throws(() => textKindCode('title'), /Unknown release text kind/) assert.equal(textKindName(99), 'unknown') assert.equal(textKindName(null), 'unknown') }) test('textsToStore trims, cuts, drops empties and repeats, keeps the first TEXTS_PER_KIND', ({ assert, }) => { const long = 'x'.repeat(TEXT_MAX + 10) assert.deepEqual(textsToStore([' a.mkv ', '', null, 'a.mkv', 'b.mkv', long]), [ 'a.mkv', 'b.mkv', 'x'.repeat(TEXT_MAX), ]) const many = Array.from({ length: TEXTS_PER_KIND + 5 }, (_, i) => `file${i}.rar`) const kept = textsToStore(many) assert.lengthOf(kept, TEXTS_PER_KIND) assert.equal(kept[0], 'file0.rar') assert.equal(kept[TEXTS_PER_KIND - 1], `file${TEXTS_PER_KIND - 1}.rar`) }) })