Files
usenet-indexer/tests/unit/chunks/codec.spec.ts
T
Daan MeijerandClaude Opus 5.5 d773c91ad0
Test and deploy / test (push) Successful in 29s
Test and deploy / deploy (push) Skipped
Rebuild: phase 1 modules from the current app, ordered by pipeline stage
lib/nntp (XOVER client, Xref, GROUP), lib/headers (subjects, file keys,
segments from overview lines; the yEnc path stays behind for phase 2),
lib/release (identity, random names, now in lib), lib/files (aggregator,
volume names), lib/rules (posting tools, owner by priority, release
verdicts), lib/chunks (release chunk codec). Their unit tests came along;
new ones for codec, rules and volumes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 00:08:44 +02:00

19 lines
951 B
TypeScript

import { test } from '@japa/runner'
import { decodeChunk, encodeChunk, type ChunkFile } from '#lib/chunks/index'
test.group('chunks / codec', () => {
test('round-trips files with their segments, part numbers when not 1..N', ({ assert }) => {
const files: ChunkFile[] = [
{ name: 'a.part1.rar', poster: 'p <p@x>', subject: 'A [1/2] - "a.part1.rar" yEnc', postedAt: 1_700_000_000_000, groups: ['alt.binaries.test'], segments: [[1, 'one@x', 700_000], [2, 'two@x', 1234]] },
{ name: 'a.par2', poster: 'p <p@x>', subject: 'A [2/2] - "a.par2" yEnc', postedAt: null, groups: ['alt.binaries.test', 'alt.binaries.x'], segments: [[2, 'gap@x', 10], [5, 'gap2@x', 11]] },
]
const data = encodeChunk(files)
assert.equal(data[0], 1)
assert.deepEqual(decodeChunk(data), files)
})
test('refuses an unknown version', ({ assert }) => {
assert.throws(() => decodeChunk(Buffer.from([9, 0])), /Unknown chunk version 9/)
})
})