Skip to content

Commit

Permalink
Fix according to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Dina Yakovlev committed Mar 20, 2019
1 parent aff1383 commit b1f120c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/helpers/response-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ function getRequestMethod(request) {
}

function getRequestPath(request) {
let path;
// request promise
if (request.uri) {
return request.uri.pathname;
}

// other
// axios
if (request.path) {
({ path } = request);
return request.path;
}

// supertest
if (get(request, 'req.path')) {
({ path } = request.req);
return request.req.path;
}

return (path ? path.split('?')[0] : undefined);
return undefined;
}

function getResponseHeaders(response) {
Expand Down
24 changes: 23 additions & 1 deletion test/response-adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('responseAdapter', () => {
expect(parseResponse(response)).to.be.like(expectedResponse);
});

it('request-promise response with query string', async () => {
it('request-promise request with query string', async () => {
const response = await request({
status: 200,
url: 'http://www.google.com/v2/pet/123?querty=value',
Expand Down Expand Up @@ -52,6 +52,17 @@ describe('responseAdapter', () => {
expect(parseResponse(response)).to.be.like(expectedResponse);
});

it('axios request with query string', async () => {
const response = await axios({
status: 200,
url: 'http://www.google.com/v2/pet/123?querty=value',
body: responses.body.valid.value,
headers: responses.headers.valid.value,
});

expect(parseResponse(response)).to.be.like(expectedResponse);
});

it('axios non-2xx response', async () => {
try {
await axios({
Expand All @@ -75,6 +86,17 @@ describe('responseAdapter', () => {
expect(parseResponse(response)).to.be.like(expectedResponse);
});

it('supertest request with query string', async () => {
const response = await supertest({
status: 200,
url: 'http://www.google.com/v2/pet/123?querty=value',
body: responses.body.valid.value,
headers: responses.headers.valid.value,
});

expect(parseResponse(response)).to.be.like(expectedResponse);
});

it('general object', async () => {
expect(parseResponse({
method: 'get',
Expand Down

0 comments on commit b1f120c

Please sign in to comment.