Fixed failing code generation in http for requests without body#122
Fixed failing code generation in http for requests without body#122
Conversation
shreys7
commented
Nov 11, 2019
- Create a GET request with no body. Save it to a collection and click view in web. It fails to generate snippets for HTTP.
- It fails for all the requests where no body is present.
- The following function tries to access request.body.mode without having a check for the body field to be present:
- Added checks for request.body in the above function and corresponding tests.
codegens/http/lib/util.js
Outdated
| if (contentTypeIndex >= 0) { | ||
| if (request.headers.members[contentTypeIndex].value === 'multipart/form-data' || request.body.mode === 'formdata') { | ||
| if (request.headers.members[contentTypeIndex].value === 'multipart/form-data' || | ||
| (request.bidy && request.body.mode === 'formdata')) { |
There was a problem hiding this comment.
How is the test passing with this?
There was a problem hiding this comment.
Sorry. Corrected the typo. and the test is for the snippet generation should not fail if the request does not have a body. This is happening, the snippet is getting generated.
| @@ -168,7 +168,8 @@ function getHeaders (request) { | |||
| headers = ''; | |||
|
|
|||
| if (contentTypeIndex >= 0) { | |||
There was a problem hiding this comment.
The fix is inside this particular block which checks if the 'Content-Type' header is present.
The unit test you have written does not pass this criterion of contentTypeIndex >= 0. Hence the fix is not being tested. That is why the initial typo wasn't detected.
@shreys7
There was a problem hiding this comment.
yes. Shall I change the tests?
There was a problem hiding this comment.
Yes, you will have to add a 'Content-Type' header. Only then the unit test make sense.