Files
netfelix-audio-fix/server/lib/__tests__/validate.test.ts
Felix Förtsch f11861658e add bun:test coverage for analyzer + ffmpeg + validate, emit ffmpeg progress sse
- analyzer.test.ts: audio keep rules (OG + configured langs, unknown OG, undetermined lang, iso alias), ordering (OG first, reorder noop), subtitle forced-remove, transcode targets
- ffmpeg.test.ts: shellQuote, sortKeptStreams canonical order, buildCommand tmp+mv, type-relative maps (0:a:N), disposition, buildPipelineCommand sub extraction + transcode bitrate, predictExtractedFiles dedup
- validate.test.ts: parseId bounds + isOneOf narrowing
- execute: parse ffmpeg Duration + time, emit job_progress SSE events throttled at 500ms so ProcessingColumn progress bar fills in (it already listened)
- package: switch test script from placeholder echo to 'bun test'
2026-04-13 07:35:24 +02:00

35 lines
1.1 KiB
TypeScript

import { describe, test, expect } from 'bun:test';
import { parseId, isOneOf } from '../validate';
describe('parseId', () => {
test('returns the integer for valid numeric strings', () => {
expect(parseId('42')).toBe(42);
expect(parseId('1')).toBe(1);
});
test('returns null for invalid, negative, zero, or missing ids', () => {
expect(parseId('0')).toBe(null);
expect(parseId('-1')).toBe(null);
expect(parseId('abc')).toBe(null);
expect(parseId('')).toBe(null);
expect(parseId(undefined)).toBe(null);
});
test('parses leading integer from mixed strings (parseInt semantics)', () => {
expect(parseId('42abc')).toBe(42);
});
});
describe('isOneOf', () => {
test('narrows to allowed string literals', () => {
expect(isOneOf('keep', ['keep', 'remove'] as const)).toBe(true);
expect(isOneOf('remove', ['keep', 'remove'] as const)).toBe(true);
});
test('rejects disallowed values and non-strings', () => {
expect(isOneOf('delete', ['keep', 'remove'] as const)).toBe(false);
expect(isOneOf(null, ['keep', 'remove'] as const)).toBe(false);
expect(isOneOf(42, ['keep', 'remove'] as const)).toBe(false);
});
});