Skip to content

Commit

Permalink
test: oas specific
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Apr 17, 2019
1 parent a555cb4 commit d459ca0
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions packages/http-server/src/__tests__/server.oas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,41 +140,43 @@ describe.each([['petstore.oas2.json'], ['petstore.oas3.json']])('server %s', fil
});

if (file === 'petstore.oas2.json') {
test('should return response even if there is no content defined in spec', async () => {
server = createServer({}, { components: {}, config: { mock: true } });
await server.prism.load({
path: resolve(__dirname, 'fixtures', 'no-responses.oas2.yaml'),
describe('oas2 specific tests', () => {
test('should return response even if there is no content defined in spec', async () => {
server = createServer({}, { components: {}, config: { mock: true } });
await server.prism.load({
path: resolve(__dirname, 'fixtures', 'no-responses.oas2.yaml'),
});

const response = await server.fastify.inject({ method: 'GET', url: '/' });

expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toEqual('text/plain');
expect(response.payload).toEqual('');
});

const response = await server.fastify.inject({ method: 'GET', url: '/' });

expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toEqual('text/plain');
expect(response.payload).toEqual('');
});
}

if (file === 'petstore.oas3.json') {
test('will return the default response when using the __code property with a non existing code', async () => {
const response = await server.fastify.inject({
method: 'GET',
url: '/pets/123?__code=499',
} else if (file === 'petstore.oas3.json') {
describe('oas3 specific', () => {
test('will return the default response when using the __code property with a non existing code', async () => {
const response = await server.fastify.inject({
method: 'GET',
url: '/pets/123?__code=499',
});

expect(response.statusCode).toBe(499);

const payload = JSON.parse(response.payload);
expect(payload).toHaveProperty('code');
expect(payload).toHaveProperty('message');
});

expect(response.statusCode).toBe(499);
test('will return 500 with error when an undefined code is requested and there is no default response', async () => {
const response = await server.fastify.inject({
method: 'GET',
url: '/pets/findByStatus?status=available&__code=499',
});

const payload = JSON.parse(response.payload);
expect(payload).toHaveProperty('code');
expect(payload).toHaveProperty('message');
});

test('will return 500 with error when an undefined code is requested and there is no default response', async () => {
const response = await server.fastify.inject({
method: 'GET',
url: '/pets/findByStatus?status=available&__code=499',
expect(response.statusCode).toBe(500);
});

expect(response.statusCode).toBe(500);
});
}
});

0 comments on commit d459ca0

Please sign in to comment.