Skip to content

Commit 3a51aea

Browse files
✅ test: Add tests for additional error response statuses in errorResponse.test.ts (#6300)
Co-authored-by: gru-agent[bot] <185149714+gru-agent[bot]@users.noreply.github.com>
1 parent 5bacc9d commit 3a51aea

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/utils/errorResponse.test.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22

33
import { AgentRuntimeErrorType } from '@/libs/agent-runtime';
44
import { ChatErrorType } from '@/types/fetch';
@@ -32,6 +32,30 @@ describe('createErrorResponse', () => {
3232
expect(response.status).toBe(403);
3333
});
3434

35+
it('returns a 429 status for InsufficientQuota error type', () => {
36+
const errorType = AgentRuntimeErrorType.InsufficientQuota;
37+
const response = createErrorResponse(errorType);
38+
expect(response.status).toBe(429);
39+
});
40+
41+
it('returns a 429 status for QuotaLimitReached error type', () => {
42+
const errorType = AgentRuntimeErrorType.QuotaLimitReached;
43+
const response = createErrorResponse(errorType);
44+
expect(response.status).toBe(429);
45+
});
46+
47+
it('returns a 400 status for ExceededContextWindow error type', () => {
48+
const errorType = AgentRuntimeErrorType.ExceededContextWindow;
49+
const response = createErrorResponse(errorType);
50+
expect(response.status).toBe(400);
51+
});
52+
53+
it('returns a 400 status for SystemTimeNotMatchError error type', () => {
54+
const errorType = ChatErrorType.SystemTimeNotMatchError;
55+
const response = createErrorResponse(errorType);
56+
expect(response.status).toBe(400);
57+
});
58+
3559
describe('Provider Biz Error', () => {
3660
it('returns a 471 status for ProviderBizError error type', () => {
3761
const errorType = AgentRuntimeErrorType.ProviderBizError;
@@ -44,6 +68,18 @@ describe('createErrorResponse', () => {
4468
const response = createErrorResponse(errorType);
4569
expect(response.status).toBe(470);
4670
});
71+
72+
it('returns a 472 status for OllamaBizError error type', () => {
73+
const errorType = AgentRuntimeErrorType.OllamaBizError;
74+
const response = createErrorResponse(errorType);
75+
expect(response.status).toBe(472);
76+
});
77+
78+
it('returns a 472 status for OllamaServiceUnavailable error type', () => {
79+
const errorType = ChatErrorType.OllamaServiceUnavailable;
80+
const response = createErrorResponse(errorType);
81+
expect(response.status).toBe(472);
82+
});
4783
});
4884

4985
// 测试状态码不在200-599范围内的情况

0 commit comments

Comments
 (0)