diff --git a/test/integration/proxy.test.ts b/test/integration/proxy.test.ts index 4638b9e..bec8235 100644 --- a/test/integration/proxy.test.ts +++ b/test/integration/proxy.test.ts @@ -13,7 +13,7 @@ vi.hoisted(() => { }); let downstream: ReturnType; -let captured: { auth?: string; fake?: string; path?: string } = {}; +let captured: { auth?: string; fake?: string; path?: string; method?: string; body?: string } = {}; describe('gateway proxy', () => { let token = ''; @@ -32,11 +32,13 @@ describe('gateway proxy', () => { }, }); }); - echo.all('*', (c) => { + echo.all('*', async (c) => { captured = { auth: c.req.header('authorization') ?? '', fake: c.req.header('x-user-id') ?? '', path: c.req.path, + method: c.req.method, + body: await c.req.text(), }; return c.json({ from: 'downstream' }); }); @@ -66,6 +68,19 @@ describe('gateway proxy', () => { expect(captured.fake).toBe(''); }); + it('POST 转发:方法与请求体原样到下游(F1)', async () => { + const res = await buildApp().request('/api/task/task/t-1/claim', { + method: 'POST', + headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' }, + body: JSON.stringify({ note: 'hello' }), + }); + expect(res.status).toBe(200); + expect(captured.method).toBe('POST'); + expect(captured.path).toBe('/task/t-1/claim'); + expect(JSON.parse(captured.body ?? '')).toEqual({ note: 'hello' }); + expect(await res.json()).toEqual({ from: 'downstream' }); + }); + it('下游不可达 → 502 统一错误形状,点名是哪个下游(C3)', async () => { const res = await buildApp().request('/api/data/ledger/domains', { headers: { authorization: `Bearer ${token}` },