Skip to content

Commit 24495fe

Browse files
author
dhwaneetbhatt
committed
Remove lodash from checks and add a test to assert the fix
1 parent 5c78db8 commit 24495fe

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

codegens/curl/lib/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ var self = module.exports = {
297297
disableBodyPruning = true,
298298
isBodyEmpty = self.isBodyEmpty(request.body);
299299

300-
if (_.has(request, 'protocolProfileBehavior') && request.protocolProfileBehavior !== null) {
300+
// eslint-disable-next-line lodash/prefer-is-nil
301+
if (request.protocolProfileBehavior !== null && request.protocolProfileBehavior !== undefined) {
301302
followRedirect = _.get(request, 'protocolProfileBehavior.followRedirects', followRedirect);
302303
followOriginalHttpMethod =
303304
_.get(request, 'protocolProfileBehavior.followOriginalHttpMethod', followOriginalHttpMethod);

codegens/curl/test/unit/convert.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,42 @@ describe('curl convert function', function () {
976976
expect(snippet).to.not.include('--request POST');
977977
});
978978
});
979+
980+
it('should work when protocolProfileBehavior is null in request settings', function () {
981+
const request = new sdk.Request({
982+
'method': 'POST',
983+
'header': [],
984+
'body': {
985+
'mode': 'graphql',
986+
'graphql': {
987+
'query': '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}', // eslint-disable-line
988+
'variables': '{\n\t"variable_key": "variable_value"\n}'
989+
}
990+
},
991+
'url': {
992+
'raw': 'https://postman-echo.com/post',
993+
'protocol': 'https',
994+
'host': [
995+
'postman-echo',
996+
'com'
997+
],
998+
'path': [
999+
'post'
1000+
]
1001+
}
1002+
});
1003+
1004+
// this needs to be done here because protocolProfileBehavior is not in collections SDK
1005+
request.protocolProfileBehavior = null;
1006+
1007+
convert(request, { followRedirect: true, followOriginalHttpMethod: true }, function (error, snippet) {
1008+
if (error) {
1009+
expect.fail(null, null, error);
1010+
}
1011+
expect(snippet).to.be.a('string');
1012+
expect(snippet).to.include('--request POST');
1013+
});
1014+
});
9791015
});
9801016
});
9811017
});

0 commit comments

Comments
 (0)