Skip to content

Commit

Permalink
test: change test meaning
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Apr 15, 2019
1 parent fc03e90 commit a9aed0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/http-server/src/__tests__/server.oas3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ describe('server', () => {
expect(response.statusCode).toBe(500);
});

test('will return requested response using the __code property', async () => {
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=404',
});

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

test('will return requested error response with payload', async () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/http/src/mocker/negotiator/NegotiatorHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ function findResponseByStatusCode(
responses: IHttpOperationResponse[],
statusCode: string
): IHttpOperationResponse | undefined {
const candidate = responses.find(response => response.code.toLowerCase() === statusCode.toLowerCase());
const candidate = responses.find(
response => response.code.toLowerCase() === statusCode.toLowerCase()
);
if (candidate) {
return candidate;
}
return Object.assign(responses.find(response => response.code === 'default'), { code: statusCode });
return Object.assign(responses.find(response => response.code === 'default'), {
code: statusCode,
});
}

const helpers = {
Expand Down

0 comments on commit a9aed0e

Please sign in to comment.