Skip to content

Commit cc2fcea

Browse files
claude-code-bestglm-5-turbo
andcommitted
fix(rcs): add resJson helper to resolve strict mode type errors in tests
Hono Response.json() returns Promise<unknown> under strict TypeScript, causing 121 TS errors across middleware and routes test files. Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
1 parent 6234bad commit cc2fcea

2 files changed

Lines changed: 110 additions & 100 deletions

File tree

packages/remote-control-server/src/__tests__/middleware.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { describe, test, expect, beforeEach, afterAll, mock } from 'bun:test'
22

3+
// res.json() returns Promise<unknown> in strict mode; this helper narrows to any for test assertions
4+
function resJson(res: Response) {
5+
return res.json() as Promise<any>
6+
}
7+
38
// Mock config before imports
49
const mockConfig = {
510
port: 3000,
@@ -87,7 +92,7 @@ describe('Auth Middleware', () => {
8792
},
8893
})
8994
expect(res.status).toBe(200)
90-
const body = await res.json()
95+
const body = await resJson(res)
9196
expect(body.username).toBe('alice')
9297
})
9398

@@ -96,7 +101,7 @@ describe('Auth Middleware', () => {
96101
headers: { Authorization: 'Bearer test-api-key' },
97102
})
98103
expect(res.status).toBe(200)
99-
const body = await res.json()
104+
const body = await resJson(res)
100105
expect(body.username).toBe('bob')
101106
})
102107

@@ -107,7 +112,7 @@ describe('Auth Middleware', () => {
107112
headers: { Authorization: `Bearer ${token}` },
108113
})
109114
expect(res.status).toBe(200)
110-
const body = await res.json()
115+
const body = await resJson(res)
111116
expect(body.username).toBe('charlie')
112117
})
113118

@@ -162,7 +167,7 @@ describe('Auth Middleware', () => {
162167
headers: { Authorization: `Bearer ${jwt}` },
163168
})
164169
expect(res.status).toBe(200)
165-
const body = await res.json()
170+
const body = await resJson(res)
166171
expect(body.jwtPayload).not.toBeNull()
167172
expect(body.jwtPayload.session_id).toBe('ses_123')
168173
})
@@ -191,7 +196,7 @@ describe('Auth Middleware', () => {
191196
describe('extractWebSocketAuthToken', () => {
192197
test('does not read tokens from query params', async () => {
193198
const res = await app.request('/ws-auth-token?token=test-api-key')
194-
const body = await res.json()
199+
const body = await resJson(res)
195200
expect(body.token).toBeNull()
196201
})
197202

@@ -201,7 +206,7 @@ describe('Auth Middleware', () => {
201206
'Sec-WebSocket-Protocol': encodeWebSocketAuthProtocol('test-api-key'),
202207
},
203208
})
204-
const body = await res.json()
209+
const body = await resJson(res)
205210
expect(body.token).toBe('test-api-key')
206211
})
207212
})
@@ -210,7 +215,7 @@ describe('Auth Middleware', () => {
210215
test('accepts UUID from query param', async () => {
211216
const res = await app.request('/uuid-test?uuid=test-uuid-1')
212217
expect(res.status).toBe(200)
213-
const body = await res.json()
218+
const body = await resJson(res)
214219
expect(body.uuid).toBe('test-uuid-1')
215220
})
216221

@@ -219,7 +224,7 @@ describe('Auth Middleware', () => {
219224
headers: { 'X-UUID': 'test-uuid-2' },
220225
})
221226
expect(res.status).toBe(200)
222-
const body = await res.json()
227+
const body = await resJson(res)
223228
expect(body.uuid).toBe('test-uuid-2')
224229
})
225230

@@ -232,21 +237,21 @@ describe('Auth Middleware', () => {
232237
describe('getUuidFromRequest', () => {
233238
test('extracts from query param', async () => {
234239
const res = await app.request('/uuid-extract?uuid=from-query')
235-
const body = await res.json()
240+
const body = await resJson(res)
236241
expect(body.uuid).toBe('from-query')
237242
})
238243

239244
test('extracts from header', async () => {
240245
const res = await app.request('/uuid-extract', {
241246
headers: { 'X-UUID': 'from-header' },
242247
})
243-
const body = await res.json()
248+
const body = await resJson(res)
244249
expect(body.uuid).toBe('from-header')
245250
})
246251

247252
test('returns undefined when no UUID', async () => {
248253
const res = await app.request('/uuid-extract')
249-
const body = await res.json()
254+
const body = await resJson(res)
250255
expect(body.uuid).toBeUndefined()
251256
})
252257
})

0 commit comments

Comments
 (0)