Skip to content

Commit

Permalink
test: Add Test Case for Allow Header
Browse files Browse the repository at this point in the history
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
ahilke committed Mar 12, 2021
1 parent b15e796 commit 2a5f66b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/allow.header.spec.ts
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' },
},
},
},
},
};
}

0 comments on commit 2a5f66b

Please sign in to comment.