Skip to content

Commit

Permalink
add test for array response
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Oct 28, 2019
1 parent 15c137e commit 5690be2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/resources/response.validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users:
get:
tags:
- Users
summary: Get users
operationId: getUsers
parameters: []
responses:
'200':
description: the users
content:
application/json:
schema:
$ref: '#/components/schemas/Users'

components:
schemas:
Expand All @@ -87,6 +101,12 @@ components:
type: integer
format: int64

Users:
description: 'Generic list of values from database schema'
type: array
items:
type: string

Human:
required:
- id
Expand Down
14 changes: 14 additions & 0 deletions test/response.validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe(packageJson.name, () => {
{ apiSpec: apiSpecPath, validateResponses: true },
3005,
app => {
app.get(`${app.basePath}/users`, (req, res) => {
const json = ['user1', 'user2', 'user3'];
return res.json(json);
});
app.get(`${app.basePath}/pets`, (req, res) => {
let json = {};
if ((req.query.mode = 'bad_type')) {
Expand Down Expand Up @@ -48,4 +52,14 @@ describe(packageJson.name, () => {
.to.have.property('code')
.that.equals(500);
}));

it('should pass if response is a list', async () =>
request(app)
.get(`${app.basePath}/users`)
.expect(200)
.then((r: any) => {
expect(r.body)
.is.an('array')
.with.length(3);
}));
});

0 comments on commit 5690be2

Please sign in to comment.