Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.1.3 #34

Merged
merged 5 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### v0.1.3 (April 21, 2020)
* Fixed multiple responses with same code returning example with 500 code.

#### v0.1.2 (March 31, 2020)
* Fixed default response body from object to null.

Expand Down
11 changes: 9 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,20 @@ helper = {
* @returns {Object} convertedResponse - postman sdk response object
*/
convertResponse: function(responses, originalRequest, types, options) {
let convertedResponses = [];
let allResponses = [],
convertedResponses = [];

if (!responses) {
return null;
}

_.forEach(responses, (res) => {
// Add all response object to allResponse
// as there can be multiple reponse for same status code, and raml-1-parser returns array in such case
_.forEach(responses, (response) => {
allResponses = _.concat(allResponses, response);
});

_.forEach(allResponses, (res) => {
let responseBody = null,
responseHeaders = [],
responseBodyType,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raml1-to-postman",
"version": "0.1.2",
"version": "0.1.3",
"description": "Converts RAML 1.0 files to postman v2 collection",
"homepage": "https://github.com/postmanlabs/raml1-to-postman",
"bugs": "https://github.com/postmanlabs/raml1-to-postman/issues",
Expand Down
40 changes: 39 additions & 1 deletion test/unit/helper.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var expect = require('chai').expect,
var _ = require('lodash'),
expect = require('chai').expect,
helper = require('../../lib/helper.js');

describe('HELPER FUNCTION TESTS ', function() {
Expand All @@ -18,4 +19,41 @@ describe('HELPER FUNCTION TESTS ', function() {
expect(convertedResponse[0].body).to.be.null;
done();
});

it('convertResponse function should return valid responses for multiple response with same status code',
function(done) {
var convertedResponses = helper.convertResponse({
'200': [
{
code: '200',
name: 'Success 1',
body: {}
},
{
code: '200',
name: 'Success 2',
body: {}
}
],
'400': {
code: '400',
name: 'Failure',
body: {}
}
}, {}, {}, {});

expect(convertedResponses).to.be.an('array');
expect(convertedResponses.length).to.eql(3);
expect(convertedResponses[0].code).to.eql(200);
expect(convertedResponses[0].name).to.eql('Success 1');
expect(convertedResponses[1].code).to.eql(200);
expect(convertedResponses[1].name).to.eql('Success 2');
expect(convertedResponses[2].code).to.eql(400);
expect(convertedResponses[2].name).to.eql('Failure');
_.forEach(convertedResponses, (convertedResponse) => {
expect(convertedResponse).to.have.any.keys('name', 'code', 'headers', 'body');
expect(convertedResponse.body).to.be.null;
});
done();
});
});