-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathaudio-formats.test.ts
More file actions
55 lines (47 loc) · 1.68 KB
/
Copy pathaudio-formats.test.ts
File metadata and controls
55 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, it, expect } from 'bun:test';
import {
T2A_FORMATS,
MUSIC_FORMATS,
formatList,
validateAudioFormat,
validateT2AStreaming,
} from '../../src/utils/audio-formats';
describe('audio-formats', () => {
describe('T2A_FORMATS', () => {
it.each(['mp3', 'pcm', 'flac', 'wav', 'pcmu_raw', 'pcmu_wav', 'opus'] as const)(
'accepts %s',
(fmt) => expect(() => validateAudioFormat(fmt, T2A_FORMATS)).not.toThrow(),
);
it.each(['aac', 'ogg', 'wma', 'mp4', ''])(
'rejects %s',
(fmt) => expect(() => validateAudioFormat(fmt, T2A_FORMATS)).toThrow(/Invalid audio format/),
);
});
describe('MUSIC_FORMATS', () => {
it.each(['mp3', 'wav', 'pcm', 'flac'] as const)(
'accepts %s',
(fmt) => expect(() => validateAudioFormat(fmt, MUSIC_FORMATS)).not.toThrow(),
);
it.each(['opus', 'pcmu_raw', 'pcmu_wav', 'aac'])(
'rejects %s',
(fmt) => expect(() => validateAudioFormat(fmt, MUSIC_FORMATS)).toThrow(/Invalid audio format/),
);
});
describe('validateT2AStreaming', () => {
it('rejects wav in streaming mode', () => {
expect(() => validateT2AStreaming('wav', true)).toThrow(/wav format is not supported in streaming/);
});
it('allows wav in non-streaming mode', () => {
expect(() => validateT2AStreaming('wav', false)).not.toThrow();
});
it.each(['mp3', 'pcm', 'flac', 'pcmu_raw', 'pcmu_wav', 'opus'])(
'allows %s in streaming mode',
(fmt) => expect(() => validateT2AStreaming(fmt, true)).not.toThrow(),
);
});
describe('formatList', () => {
it('joins formats with comma-space', () => {
expect(formatList(['a', 'b', 'c'])).toBe('a, b, c');
});
});
});