-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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', | ||
'path.level.parameters.yaml', | ||
); | ||
app = await createApp({ apiSpec }, 3005); | ||
basePath = app.basePath; | ||
|
||
// Define new coercion routes | ||
app.use( | ||
`${basePath}`, | ||
express | ||
.Router() | ||
.get(`/path_level_parameters`, (_req, res) => res.send()) | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should return 400 if pathLevel query parameter is not provided', async () => | ||
request(app) | ||
.get(`${basePath}/path_level_parameters?operationLevel=123`) | ||
.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 \'pathLevel\''); | ||
})); | ||
|
||
it('should return 400 if operationLevel query parameter is not provided', async () => | ||
request(app) | ||
.get(`${basePath}/path_level_parameters?pathLevel=123`) | ||
.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 \'operationLevel\''); | ||
})); | ||
|
||
it('should return 400 if neither operationLevel, nor pathLevel query parameters are provided', async () => | ||
request(app) | ||
.get(`${basePath}/path_level_parameters`) | ||
.send() | ||
.expect(400) | ||
.then(r => { | ||
expect(r.body.errors).to.be.an('array') | ||
expect(r.body.errors).to.have.length(2); | ||
const messages = r.body.errors.map(err => err.message); | ||
expect(messages).to.have.members([ | ||
'should have required property \'pathLevel\'', | ||
'should have required property \'operationLevel\'' | ||
]); | ||
})); | ||
|
||
it('should return 200 if both pathLevel and operationLevel query parameter are provided', async () => | ||
request(app) | ||
.get(`${basePath}/path_level_parameters?operationLevel=123&pathLevel=123`) | ||
.send() | ||
.expect(200)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
openapi: '3.0.2' | ||
info: | ||
version: 1.0.0 | ||
title: Path Level Parameters | ||
description: Path Level Parameters Test | ||
|
||
servers: | ||
- url: /v1/ | ||
|
||
paths: | ||
/path_level_parameters: | ||
parameters: | ||
- $ref: '#components/parameters/pathLevelParameter' | ||
get: | ||
parameters: | ||
- $ref: '#components/parameters/operationLevelParameter' | ||
responses: | ||
'200': | ||
description: OK | ||
'400': | ||
description: Bad Request | ||
|
||
components: | ||
parameters: | ||
pathLevelParameter: | ||
name: pathLevel | ||
in: query | ||
required: true | ||
schema: | ||
type: string | ||
operationLevelParameter: | ||
name: operationLevel | ||
in: query | ||
required: true | ||
schema: | ||
type: string |