关键改动: - 后端显式注册 10mb JSON/urlencoded body parser,支持较大的 AppData 写入 - 前端版本派生数据缺失状态时默认 planned,而不是 released - 增加请求体限制和版本默认状态测试 Co-Authored-By: Codex GPT-5 <codex@openai.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { configureHttpBodyParsers, DEFAULT_HTTP_BODY_LIMIT } from './http-body-limit';
|
|
|
|
jest.mock('express', () => ({
|
|
json: jest.fn(() => 'json-parser'),
|
|
urlencoded: jest.fn(() => 'urlencoded-parser'),
|
|
}));
|
|
|
|
const express = jest.requireMock('express') as {
|
|
json: jest.Mock;
|
|
urlencoded: jest.Mock;
|
|
};
|
|
|
|
describe('configureHttpBodyParsers', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('registers JSON and urlencoded parsers with a large AppData-safe limit', () => {
|
|
const app = { use: jest.fn() };
|
|
|
|
configureHttpBodyParsers(app as never);
|
|
|
|
expect(DEFAULT_HTTP_BODY_LIMIT).toBe('10mb');
|
|
expect(express.json).toHaveBeenCalledWith({ limit: '10mb' });
|
|
expect(express.urlencoded).toHaveBeenCalledWith({ extended: true, limit: '10mb' });
|
|
expect(app.use).toHaveBeenNthCalledWith(1, 'json-parser');
|
|
expect(app.use).toHaveBeenNthCalledWith(2, 'urlencoded-parser');
|
|
});
|
|
|
|
it('allows overriding the body limit for deployments with larger documents', () => {
|
|
const app = { use: jest.fn() };
|
|
|
|
configureHttpBodyParsers(app as never, '25mb');
|
|
|
|
expect(express.json).toHaveBeenCalledWith({ limit: '25mb' });
|
|
expect(express.urlencoded).toHaveBeenCalledWith({ extended: true, limit: '25mb' });
|
|
});
|
|
});
|