0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/middleware/test/json.spec.ts
Juan Picado ae93e039da
fix: expose middleware methods #3915 (#3934)
* fix: expose middleware methods #3915

* remove body-parser dep

* fix 404 issue
2023-07-15 20:38:43 +02:00

32 lines
842 B
TypeScript

import express from 'express';
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(express.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);
});