|
| 1 | +import { describe, it, expect } from 'bun:test'; |
| 2 | +import { |
| 3 | + T2A_FORMATS, |
| 4 | + MUSIC_FORMATS, |
| 5 | + formatList, |
| 6 | + validateAudioFormat, |
| 7 | + validateT2AStreaming, |
| 8 | +} from '../../src/utils/audio-formats'; |
| 9 | + |
| 10 | +describe('audio-formats', () => { |
| 11 | + describe('T2A_FORMATS', () => { |
| 12 | + it.each(['mp3', 'pcm', 'flac', 'wav', 'pcmu_raw', 'pcmu_wav', 'opus'] as const)( |
| 13 | + 'accepts %s', |
| 14 | + (fmt) => expect(() => validateAudioFormat(fmt, T2A_FORMATS)).not.toThrow(), |
| 15 | + ); |
| 16 | + |
| 17 | + it.each(['aac', 'ogg', 'wma', 'mp4', ''])( |
| 18 | + 'rejects %s', |
| 19 | + (fmt) => expect(() => validateAudioFormat(fmt, T2A_FORMATS)).toThrow(/Invalid audio format/), |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('MUSIC_FORMATS', () => { |
| 24 | + it.each(['mp3', 'wav', 'pcm', 'flac'] as const)( |
| 25 | + 'accepts %s', |
| 26 | + (fmt) => expect(() => validateAudioFormat(fmt, MUSIC_FORMATS)).not.toThrow(), |
| 27 | + ); |
| 28 | + |
| 29 | + it.each(['opus', 'pcmu_raw', 'pcmu_wav', 'aac'])( |
| 30 | + 'rejects %s', |
| 31 | + (fmt) => expect(() => validateAudioFormat(fmt, MUSIC_FORMATS)).toThrow(/Invalid audio format/), |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('validateT2AStreaming', () => { |
| 36 | + it('rejects wav in streaming mode', () => { |
| 37 | + expect(() => validateT2AStreaming('wav', true)).toThrow(/wav format is not supported in streaming/); |
| 38 | + }); |
| 39 | + |
| 40 | + it('allows wav in non-streaming mode', () => { |
| 41 | + expect(() => validateT2AStreaming('wav', false)).not.toThrow(); |
| 42 | + }); |
| 43 | + |
| 44 | + it.each(['mp3', 'pcm', 'flac', 'pcmu_raw', 'pcmu_wav', 'opus'])( |
| 45 | + 'allows %s in streaming mode', |
| 46 | + (fmt) => expect(() => validateT2AStreaming(fmt, true)).not.toThrow(), |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('formatList', () => { |
| 51 | + it('joins formats with comma-space', () => { |
| 52 | + expect(formatList(['a', 'b', 'c'])).toBe('a, b, c'); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments