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

Handle undefined in Cloud Code #682

Merged
merged 2 commits into from Oct 21, 2018

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Oct 21, 2018

Closes #417

Based on discussion parse-community/parse-server#5053

Previously threw Invalid response and unhandled promise rejection

@@ -70,6 +70,13 @@ describe('Parse Cloud', () => {
}
});

it('run function with undefined', (done) => {
Parse.Cloud.run('CloudFunctionUndefined', {}).then((result) => {
assert.equal(result, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why null? Should be undefined

throw new ParseError(
ParseError.INVALID_JSON,
'The server returned an invalid response.'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should still throw an error if there was a .result before but not after decoding.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don’t think that would ever happen

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok then!

src/Cloud.js Outdated
ParseError.INVALID_JSON,
'The server returned an invalid response.'
);
return Promise.resolve(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

To match what iOS doesf we should do the decoding on the .result and return whatever the returned value is

Copy link
Member Author

Choose a reason for hiding this comment

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

.decode handles that internally

Copy link
Contributor

Choose a reason for hiding this comment

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

So let’s just return the decoded result, defined or undefined. Perhaps we could check that only the result key is at least définined and no other

Copy link
Member Author

Choose a reason for hiding this comment

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

I though about that as well. But let say we wanted to add additional response to cloud code like status OK or something

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we will revisit, so far we have this failing because undefined is not serialized where all other platforms support it.

request.mockReturnValue(Promise.resolve({
success: false
}));
request.mockReturnValue(Promise.resolve(undefined));
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably remove the whole test then

Copy link
Member Author

Choose a reason for hiding this comment

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

I change it, need for unit test

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the test should stay the same. Returning an object with unknown key should not be valid.
Ie: if the response has not .result and there is at least a key, then we fail

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see what you mean

@codecov
Copy link

codecov bot commented Oct 21, 2018

Codecov Report

Merging #682 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #682      +/-   ##
==========================================
+ Coverage   85.68%   85.69%   +0.01%     
==========================================
  Files          48       48              
  Lines        3876     3880       +4     
  Branches      879      882       +3     
==========================================
+ Hits         3321     3325       +4     
  Misses        555      555
Impacted Files Coverage Δ
src/Cloud.js 92.5% <100%> (+0.83%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e69adf...0eb0e7e. Read the comment docs.

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

LGTM

@flovilmart flovilmart merged commit 0cc4978 into parse-community:master Oct 21, 2018
@dplewis dplewis deleted the cloud-undefined-fix branch October 25, 2018 18:32
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

2 participants