refactor(new merge) (#369)
Co-authored-by: paisley <8197966+su8su@users.noreply.github.com> Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
e28eba01e1
commit
3d664c017a
26
tests/unit/error-model.test.ts
Normal file
26
tests/unit/error-model.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { AppError, mapBackendErrorCode, normalizeAppError } from '@/lib/error-model';
|
||||
|
||||
describe('error-model', () => {
|
||||
it('maps backend UNSUPPORTED to CHANNEL_UNAVAILABLE', () => {
|
||||
expect(mapBackendErrorCode('UNSUPPORTED')).toBe('CHANNEL_UNAVAILABLE');
|
||||
});
|
||||
|
||||
it('normalizes auth errors into AUTH_INVALID', () => {
|
||||
const error = normalizeAppError(new Error('HTTP 401: Invalid Authentication'));
|
||||
expect(error.code).toBe('AUTH_INVALID');
|
||||
});
|
||||
|
||||
it('normalizes ipc channel errors into CHANNEL_UNAVAILABLE', () => {
|
||||
const error = normalizeAppError(new Error('Invalid IPC channel: hostapi:fetch'));
|
||||
expect(error.code).toBe('CHANNEL_UNAVAILABLE');
|
||||
});
|
||||
|
||||
it('preserves AppError and merges details', () => {
|
||||
const base = new AppError('TIMEOUT', 'request timeout', undefined, { a: 1 });
|
||||
const normalized = normalizeAppError(base, { b: 2 });
|
||||
expect(normalized.code).toBe('TIMEOUT');
|
||||
expect(normalized.details).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user