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 99a1af1c35
vitest migration more packages (#4872)
* migrate storage package

* migrate middleware package

* migrate auth-memory plugin
2024-09-29 16:03:29 +02:00

33 lines
873 B
TypeScript

import express from 'express';
import request from 'supertest';
import { test } from 'vitest';
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);
});