0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
verdaccio/packages/middleware/test/json.spec.ts
Juan Picado a1986e098d
feat: expose middleware utils (#3580)
* feat: expose middleware utils

* feat: expose middleware utils

* Update antiLoop.ts

* Update e2e-ci.yml
2023-01-29 15:08:50 +01:00

32 lines
852 B
TypeScript

import bodyParser from 'body-parser';
import request from 'supertest';
import { HEADERS, HTTP_STATUS } from '@verdaccio/core';
import { expectJson } from '../src';
import { getApp } from './helper';
test('body is json', async () => {
const app = getApp([]);
app.use(bodyParser.json({ strict: false, limit: '10mb' }));
// @ts-ignore
app.put('/json', expectJson, (req, res) => {
res.status(HTTP_STATUS.OK).json({});
});
return request(app)
.put('/json')
.send({ name: 'john' })
.set(HEADERS.CONTENT_TYPE, 'application/json')
.expect(HTTP_STATUS.OK);
});
test('body is not json', async () => {
const app = getApp([]);
// @ts-ignore
app.put('/json', expectJson, (req, res) => {
res.status(HTTP_STATUS.OK).json({});
});
return request(app).put('/json').send('test=4').expect(HTTP_STATUS.BAD_REQUEST);
});