test: 代理 POST 方法与请求体转发断言
This commit is contained in:
@@ -13,7 +13,7 @@ vi.hoisted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let downstream: ReturnType<typeof serve>;
|
let downstream: ReturnType<typeof serve>;
|
||||||
let captured: { auth?: string; fake?: string; path?: string } = {};
|
let captured: { auth?: string; fake?: string; path?: string; method?: string; body?: string } = {};
|
||||||
|
|
||||||
describe('gateway proxy', () => {
|
describe('gateway proxy', () => {
|
||||||
let token = '';
|
let token = '';
|
||||||
@@ -32,11 +32,13 @@ describe('gateway proxy', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
echo.all('*', (c) => {
|
echo.all('*', async (c) => {
|
||||||
captured = {
|
captured = {
|
||||||
auth: c.req.header('authorization') ?? '',
|
auth: c.req.header('authorization') ?? '',
|
||||||
fake: c.req.header('x-user-id') ?? '',
|
fake: c.req.header('x-user-id') ?? '',
|
||||||
path: c.req.path,
|
path: c.req.path,
|
||||||
|
method: c.req.method,
|
||||||
|
body: await c.req.text(),
|
||||||
};
|
};
|
||||||
return c.json({ from: 'downstream' });
|
return c.json({ from: 'downstream' });
|
||||||
});
|
});
|
||||||
@@ -66,6 +68,19 @@ describe('gateway proxy', () => {
|
|||||||
expect(captured.fake).toBe('');
|
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 () => {
|
it('下游不可达 → 502 统一错误形状,点名是哪个下游(C3)', async () => {
|
||||||
const res = await buildApp().request('/api/data/ledger/domains', {
|
const res = await buildApp().request('/api/data/ledger/domains', {
|
||||||
headers: { authorization: `Bearer ${token}` },
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
|||||||
Reference in New Issue
Block a user