071faa482c
纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口 完成项目 TypeScript/Prettier 与 Rust 全量格式化 修复 Pingora expected executable 门禁的空白敏感误报 同步开发运维文档与 AGC skill pack 格式化忽略规则
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { parseApiErrorMessage } from './jsonClient';
|
|
|
|
describe('parseApiErrorMessage', () => {
|
|
it('prefers api error detail messages for business failures', () => {
|
|
expect(
|
|
parseApiErrorMessage(
|
|
JSON.stringify({
|
|
ok: false,
|
|
data: null,
|
|
error: {
|
|
code: 'BAD_REQUEST',
|
|
message: '请求参数不合法',
|
|
details: {
|
|
message: 'big_fish 发布校验未通过:还缺少 16 个基础动作',
|
|
provider: 'spacetimedb',
|
|
},
|
|
},
|
|
meta: {
|
|
apiVersion: '2026-06-16',
|
|
},
|
|
}),
|
|
'Fallback failure',
|
|
),
|
|
).toBe('big_fish 发布校验未通过:还缺少 16 个基础动作');
|
|
});
|
|
|
|
it('prefers nested api error messages', () => {
|
|
expect(
|
|
parseApiErrorMessage(
|
|
JSON.stringify({
|
|
error: {
|
|
message: 'Detailed failure',
|
|
},
|
|
}),
|
|
'Fallback failure',
|
|
),
|
|
).toBe('Detailed failure');
|
|
});
|
|
|
|
it('falls back to the raw response text when the payload is not json', () => {
|
|
expect(parseApiErrorMessage('Plain text failure', 'Fallback failure')).toBe(
|
|
'Plain text failure',
|
|
);
|
|
});
|
|
|
|
it('uses the fallback when the response body is empty', () => {
|
|
expect(parseApiErrorMessage('', 'Fallback failure')).toBe(
|
|
'Fallback failure',
|
|
);
|
|
});
|
|
});
|