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

Enable non-object JSON bodies #1282

Merged
merged 5 commits into from Dec 2, 2014
Merged

Conversation

apoco
Copy link
Contributor

@apoco apoco commented Nov 21, 2014

Updated JSON requests so they can contain bodies that are not objects

body: value
}
request(opts, function (err, resp, body) {
t.equal(err, null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind if we have t.deepEqual(value, body) here just to make sure (and clear) we're parsing back the value correctly. Currently that's not possible because createPostValidator is returning plain text, and in the case of this test it's checking only for the presence of the content-type header and if the value was stringified correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the test to do this verification using a new createPostJSONValidator method that returns a JSON response.

@lalitkapoor
Copy link
Member

Please see #1281 for more comments regarding this pull request.

@apoco
Copy link
Contributor Author

apoco commented Nov 25, 2014

@simov: updated the test

@simov
Copy link
Member

simov commented Nov 25, 2014

@apoco can you pull simov@9634268 into your branch?

The changes are:

  1. On the server you are asserting for proper stringify done by request + existing of headers
  2. The deep equality check is in the request callback - you are asserting for proper parse done by request (not by the server)

The server returns the value as it is, you was returning object all the time, which does not test the changes you made.

Otherwise 👍 from me

@simov
Copy link
Member

simov commented Nov 25, 2014

Actually you are implementing only the sending of non {} and [] stringified JSON bodies, but I though it's a good idea to test out the response parsing for them as well.

jpage-godaddy and others added 5 commits December 1, 2014 17:07
Updated JSON requests so they can contain bodies that are not objects. For avoid unexpected surprises, JSON `null` values are not sent.
Added test to ensure each type of JSON root object can be sent in a request
Modified JSON request tests so the same value sent in the request
is echoed in the test server JSON response.
@apoco
Copy link
Contributor Author

apoco commented Dec 2, 2014

I rebased and pushed a change so that the test server returns the same body it received in the request as the response. I'm confused how this makes any difference, but I think this is what was asked for.

I'm confused because the prior test:

  1. Verifies that request sent a JSON content type.
  2. Verifies that the sent JSON represents the expected value; this is done by converting the JSON to a value with JSON.parse and using deep equality to ensure the values are equivalent.
  3. Sends the value in a JSON response from the test server.
  4. Verifies that request parses the JSON response from the server to a value (body).
  5. Verifies that the value in the response is equivalent to the original value through deep equality.

To me, this describes what should be being tested. Am I missing something?

@simov
Copy link
Member

simov commented Dec 2, 2014

Exactly, that's why in my last comment in the code I said that I'm ok with the deep equality check in the validator. The reason for returning the original value back to request is exactly the same as the deep equality check on the server. Practically this should be the same, of course, but just for the sake of completeness I though it's logical to have the same deep equality check for the client as well.

Anyway looking good to me, except that Travis is failing for some reason.

@apoco
Copy link
Contributor Author

apoco commented Dec 2, 2014

Gotcha. Looks like there was a timeout for a proxy test. It doesn't look related to my changes. Maybe there's a flaky test. Is there a way to re-run the tests? Or maybe that failure can be ignored.

@simov simov merged commit ce70514 into request:master Dec 2, 2014
@simov
Copy link
Member

simov commented Dec 2, 2014

Yep, there is a restart build button, so I just did that - all passing.

simov added a commit to simov/request that referenced this pull request Dec 9, 2014
For some reason this change brakes the form option when it's object
nylen added a commit that referenced this pull request Dec 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants