Skip to content

Commit

Permalink
Merge pull request #4 from janis-commerce/FIX-buffer-response-to-string
Browse files Browse the repository at this point in the history
FIX - buffer response to string
  • Loading branch information
jormaechea committed Aug 23, 2021
2 parents 8ab120f + d75225a commit 7d1cd66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/request-response.js
Expand Up @@ -42,7 +42,7 @@ module.exports = class RequestResponse {
try {
return JSON.parse(rawBody.toString());
} catch(error) {
return rawBody;
return rawBody.toString();
}
}
};
10 changes: 6 additions & 4 deletions tests/request.js
Expand Up @@ -292,13 +292,15 @@ describe('Request Test', () => {

const url = 'http://test.com';

const bodyContent = '<h1>test</h1>';

const response = {
code: 200,
body: Buffer.from('<h1>test</h1>'),
body: Buffer.from(bodyContent),
headers: { 'content-type': 'text/html' }
};

const payload = Buffer.from('<form>test</form>', 'utf-8');
const payload = Buffer.from(bodyContent, 'utf-8');

const reqPassThrough = new PassThrough();
const writeSpy = sinon.spy(reqPassThrough, 'write');
Expand All @@ -319,8 +321,8 @@ describe('Request Test', () => {
});

assert.deepStrictEqual(Request.statusCode, response.code);
assert.deepStrictEqual(Request.responseBody, response.body);
assert.deepStrictEqual(reqResponse.rawBody, response.body);
assert.deepStrictEqual(Request.responseBody, bodyContent);
assert.deepStrictEqual(reqResponse.rawBody, payload);
});

it('Should make a get request by default', async () => {
Expand Down

0 comments on commit 7d1cd66

Please sign in to comment.