mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 00:54:06 -08:00
5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import type { Request, Response } from 'express';
|
|
import { createServer } from 'http';
|
|
import request from 'supertest';
|
|
import { gzipSync, deflateSync } from 'zlib';
|
|
|
|
import { rawBodyReader, bodyParser } from '@/middlewares/body-parser';
|
|
|
|
describe('bodyParser', () => {
|
|
const server = createServer((req: Request, res: Response) => {
|
|
rawBodyReader(req, res, async () => {
|
|
bodyParser(req, res, () => res.end(JSON.stringify(req.body)));
|
|
});
|
|
});
|
|
|
|
it('should handle uncompressed data', async () => {
|
|
const response = await request(server).post('/').send({ hello: 'world' }).expect(200);
|
|
expect(response.text).toEqual('{"hello":"world"}');
|
|
});
|
|
|
|
it('should handle gzip data', async () => {
|
|
const response = await request(server)
|
|
.post('/')
|
|
.set('content-encoding', 'gzip')
|
|
// @ts-ignore
|
|
.serialize((d) => gzipSync(JSON.stringify(d)))
|
|
.send({ hello: 'world' })
|
|
.expect(200);
|
|
expect(response.text).toEqual('{"hello":"world"}');
|
|
});
|
|
|
|
it('should handle deflate data', async () => {
|
|
const response = await request(server)
|
|
.post('/')
|
|
.set('content-encoding', 'deflate')
|
|
// @ts-ignore
|
|
.serialize((d) => deflateSync(JSON.stringify(d)))
|
|
.send({ hello: 'world' })
|
|
.expect(200);
|
|
expect(response.text).toEqual('{"hello":"world"}');
|
|
});
|
|
});
|