Files
minimax-ai__cli/test/errors/api.test.ts
tars90percent b540ee49f4 Initial commit: minimax-cli
CLI for the MiniMax API Platform (Token Plan). Supports 16 commands
across 10 resource groups: text chat, speech synthesis, image generation,
video generation, music generation, web search, image understanding,
quota management, auth, and config.

Features:
- Resource-verb grammar (minimax <resource> <command>)
- Auto-detects API region (global/cn) on first run
- Structured output (text, json, yaml)
- SSE streaming for chat
- Async polling for video generation
- Cross-compiles to standalone binaries via Bun
- Works with Node 18+ via npm install
2026-03-26 17:37:11 +08:00

47 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'bun:test';
import { mapApiError } from '../../src/errors/api';
import { ExitCode } from '../../src/errors/codes';
describe('mapApiError', () => {
it('maps 401 to AUTH exit code', () => {
const err = mapApiError(401, {});
expect(err.exitCode).toBe(ExitCode.AUTH);
expect(err.message).toContain('401');
});
it('maps 403 to AUTH exit code', () => {
const err = mapApiError(403, {});
expect(err.exitCode).toBe(ExitCode.AUTH);
});
it('maps 429 to QUOTA exit code', () => {
const err = mapApiError(429, { base_resp: { status_code: 0, status_msg: 'rate limited' } });
expect(err.exitCode).toBe(ExitCode.QUOTA);
});
it('maps 408 to TIMEOUT exit code', () => {
const err = mapApiError(408, {});
expect(err.exitCode).toBe(ExitCode.TIMEOUT);
});
it('maps MiniMax content filter code 1002', () => {
const err = mapApiError(400, { base_resp: { status_code: 1002, status_msg: 'content filtered' } });
expect(err.exitCode).toBe(ExitCode.CONTENT_FILTER);
});
it('maps MiniMax quota code 1028', () => {
const err = mapApiError(400, { base_resp: { status_code: 1028, status_msg: 'quota exhausted' } });
expect(err.exitCode).toBe(ExitCode.QUOTA);
});
it('maps unknown errors to GENERAL', () => {
const err = mapApiError(500, { base_resp: { status_code: 0, status_msg: 'internal error' } });
expect(err.exitCode).toBe(ExitCode.GENERAL);
});
it('includes API message in error', () => {
const err = mapApiError(500, { base_resp: { status_code: 0, status_msg: 'something broke' } });
expect(err.message).toContain('something broke');
});
});