Skip to content

Commit

Permalink
adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trebler committed Aug 19, 2019
1 parent dd02c20 commit faf2b22
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/request.bodies.ref.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as path from 'path';
import * as express from 'express';
import { expect } from 'chai';
import * as request from 'supertest';
import { createApp } from './common/app';

const packageJson = require('../package.json');

describe(packageJson.name, () => {
let app = null;
let basePath = null;

before(async () => {
// Set up the express app
const apiSpec = path.join(
'test',
'resources',
'request.bodies.ref.yaml',
);
app = await createApp({ apiSpec }, 3005);
basePath = app.basePath;

// Define new coercion routes
app.use(
`${basePath}`,
express
.Router()
.post(`/request_bodies_ref`, (req, res) => res.json(req.body))
);
});

after(() => {
app.server.close();
});

it('should return 400 if testProperty body property is not provided', async () =>
request(app)
.post(`${basePath}/request_bodies_ref`)
.send({})
.expect(400)
.then(r => {
expect(r.body.errors).to.be.an('array')
expect(r.body.errors).to.have.length(1);
const message = r.body.errors[0].message;
expect(message).to.equal('should have required property \'testProperty\'');
}));

it('should return 200 if testProperty body property is provided', async () =>
request(app)
.post(`${basePath}/request_bodies_ref`)
.send({
testProperty: 'abc'
})
.expect(200));
});
33 changes: 33 additions & 0 deletions test/resources/request.bodies.ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
openapi: '3.0.2'
info:
version: 1.0.0
title: requestBodies $ref
description: requestBodies $ref Test

servers:
- url: /v1/

paths:
/request_bodies_ref:
post:
requestBody:
$ref: '#components/requestBodies/TestBody'
responses:
'200':
description: OK
'400':
description: Bad Request

components:
requestBodies:
TestBody:
required: true
content:
application/json:
schema:
type: object
properties:
testProperty:
type: string
required:
- testProperty

0 comments on commit faf2b22

Please sign in to comment.