49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
DEFAULT_MINIMAX_TTS_API_HOST,
|
|
getMiniMaxTtsHttpStatus,
|
|
resolveMiniMaxTtsConfig,
|
|
} from './minimaxTts';
|
|
|
|
describe('resolveMiniMaxTtsConfig', () => {
|
|
it('defaults to the official MiniMax TTS host', () => {
|
|
const config = resolveMiniMaxTtsConfig({
|
|
MINIMAX_API_KEY: 'secret-key',
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
apiKey: 'secret-key',
|
|
apiHost: DEFAULT_MINIMAX_TTS_API_HOST,
|
|
});
|
|
});
|
|
|
|
it('uses the configured MiniMax host when provided', () => {
|
|
const config = resolveMiniMaxTtsConfig({
|
|
MINIMAX_API_KEY: 'secret-key',
|
|
MINIMAX_API_HOST: ' https://api.example.com/tts/ ',
|
|
});
|
|
|
|
expect(config.apiHost).toBe('https://api.example.com/tts');
|
|
});
|
|
});
|
|
|
|
describe('getMiniMaxTtsHttpStatus', () => {
|
|
it('maps login failures to 401 so the client can fallback immediately', () => {
|
|
expect(
|
|
getMiniMaxTtsHttpStatus({
|
|
status_code: 1004,
|
|
status_msg: "login fail: Please carry the API secret key in the 'Authorization' field of the request header",
|
|
}),
|
|
).toBe(401);
|
|
});
|
|
|
|
it('preserves rate limit style failures as 429', () => {
|
|
expect(
|
|
getMiniMaxTtsHttpStatus({
|
|
status_code: 429,
|
|
status_msg: 'too many requests',
|
|
}),
|
|
).toBe(429);
|
|
});
|
|
});
|