Files
Genarrative/apps/ai-game-creator-shell/tests/clientAuthError.test.ts
T
k88936 b561db9249 删除认证失败上报的派生分类层,改为调用方按具体变体分流
- 删除 clientAuthErrorKind / clientAuthErrorNotice,clientAuthError.ts 只留 isClientAuthError 形状读取
- 删除 resolveClientAuthFailure 与 ClientAuthFailureResolution,AuthenticatedClient 直接 switch 具体变体名
- 同步重写相关单测与 ADR 第 3 节前端分流描述
2026-10-01 17:55:54 +08:00

40 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { isClientAuthError } from '../src/services/clientAuthError';
describe('AGC 认证命令错误的形状读取', () => {
it('只按形状读取 Rust 的结构化拒绝,裸字符串与 Error 都不算', () => {
expect(
isClientAuthError({
type: 'phoneOrPasswordMismatch',
message: '手机号或密码错误',
}),
).toEqual({ type: 'phoneOrPasswordMismatch', message: '手机号或密码错误' });
expect(isClientAuthError('手机号或密码错误')).toBeNull();
expect(isClientAuthError(new Error('手机号或密码错误'))).toBeNull();
expect(
isClientAuthError({ type: '', message: '手机号或密码错误' }),
).toBeNull();
expect(isClientAuthError({ type: 'phoneNumberInvalid' })).toBeNull();
expect(isClientAuthError(null)).toBeNull();
});
it('未知变体也算形状合法,由调用方按 default 交给错误池', () => {
expect(
isClientAuthError({ type: 'brandNewRejection', message: '新变体' }),
).toEqual({ type: 'brandNewRejection', message: '新变体' });
});
it('status 故意不校验:缺 status 但 message 可用的拒绝仍可读', () => {
expect(
isClientAuthError({
type: 'authServiceUnavailable',
message: '登录服务暂时不可用',
}),
).toEqual({
type: 'authServiceUnavailable',
message: '登录服务暂时不可用',
});
});
});