forked from cdimascio/express-openapi-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Test Case for Allow Header
The Allow header must be sent if the server responds with 405 to indicate which request methods can be used. See cdimascio#467.
- Loading branch information
Showing
1 changed file
with
58 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,58 @@ | ||
import { expect } from 'chai'; | ||
import * as express from 'express'; | ||
import * as request from 'supertest'; | ||
import * as packageJson from '../package.json'; | ||
import { OpenAPIV3 } from '../src/framework/types'; | ||
import { createApp } from './common/app'; | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
app = await createApp({ apiSpec: createApiSpec() }, 3001, (app) => | ||
app.use( | ||
app.basePath, | ||
express | ||
.Router() | ||
.get(`/pets`, () => ['cat', 'dog']) | ||
.post(`/pets`, (req, res) => res.json(req.body)), | ||
), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('adds allow header to 405 - Method Not Allowed', async () => | ||
request(app) | ||
.put('/pets') | ||
.expect(405) | ||
.then((response) => { | ||
expect(response.header).to.include({ allow: 'GET, POST' }); | ||
})); | ||
}); | ||
|
||
function createApiSpec(): OpenAPIV3.Document { | ||
return { | ||
openapi: '3.0.3', | ||
info: { | ||
title: 'Petstore API', | ||
version: '1.0.0', | ||
}, | ||
paths: { | ||
'/pets': { | ||
get: { | ||
responses: { | ||
'200': { description: 'GET Pet' }, | ||
}, | ||
}, | ||
post: { | ||
responses: { | ||
'200': { description: 'POST Pet' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |