Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

evaluate-http-status.spec.ts

38 lines1.0 KB

1import { test, expect } from './fixtures'
2​
3const CASES = [
4 {
5 provider: 'typesafe',
6 status: 429,
7 message:
8 'TypeSafe evaluate request failed: 429 Too Many Requests \u2014 {"error":"rejected"}',
9 },
10 {
11 provider: 'vercel-gateway',
12 status: 503,
13 message:
14 'Vercel Gateway evaluate request failed: 503 Service Unavailable \u2014 {"error":"rejected"}',
15 },
16] as const
17​
18test.describe('decide() on a non-ok provider response', () => {
19 for (const { provider, status, message } of CASES) {
20 test(`${provider} rejects with the HTTP status on the error`, async ({
21 request,
22 }) => {
23 const response = await request.post(
24 `/api/evaluate-http-status?provider=${provider}&status=${status}`,
25 )
26 expect(response.ok()).toBe(true)
27​
28 const result = (await response.json()) as {
29 ok: boolean
30 error?: { name?: string; message: string; status?: number }
31 }
32 expect(result).toEqual({
33 ok: false,
34 error: { name: 'Error', message, status },
35 })
36 })
37 }
38})