-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
optional-request-body.spec.ts
41 lines (36 loc) 路 1018 Bytes
/
optional-request-body.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as path from 'path';
import * as express from 'express';
import * as request from 'supertest';
import { createApp } from './common/app';
import * as packageJson from '../package.json';
describe(packageJson.name, () => {
let app = null;
before(async () => {
// Set up the express app
const apiSpec = path.join(__dirname, 'optional-request-body.yaml');
app = await createApp({ apiSpec }, 3005, (app) =>
app.use(
express.Router().post(`/documents`, (req, res) =>
res.status(201).json({
id: 123,
name: req.body ? req.body.name : '',
}),
),
),
);
});
after(() => {
app.server.close();
});
it('create document should return 201', async () =>
request(app)
.post(`/documents`)
.set('Content-Type', 'application/json')
.expect(201));
it('return 415', async () =>
request(app)
.post(`/documents`)
.set('Content-Type', 'image/png')
.send()
.expect(415));
});