Skip to content
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
4 changes: 4 additions & 0 deletions integration/cloud/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Parse.Cloud.define("bar", function(request) {
}
});

Parse.Cloud.define('CloudFunctionUndefined', function() {
return undefined;
});

Parse.Cloud.job('CloudJob1', function() {
return {
status: 'cloud job completed'
Expand Down
7 changes: 7 additions & 0 deletions integration/test/ParseCloudTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ describe('Parse Cloud', () => {
}
});

it('run function with undefined', (done) => {
Parse.Cloud.run('CloudFunctionUndefined', {}).then((result) => {
assert.strictEqual(result, undefined);
done();
});
});

it('run job', (done) => {
const params = { startedBy: 'Monty Python' };
Parse.Cloud.startJob('CloudJob1', params).then((jobStatusId) => {
Expand Down
13 changes: 9 additions & 4 deletions src/Cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ const DefaultController = {
);

return request.then((res) => {
if (typeof res === 'object' &&
Object.keys(res).length > 0 &&
!res.hasOwnProperty('result')) {
throw new ParseError(
ParseError.INVALID_JSON,
'The server returned an invalid response.'
);
}
const decoded = decode(res);
if (decoded && decoded.hasOwnProperty('result')) {
return Promise.resolve(decoded.result);
}
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!

return Promise.resolve(undefined);
});
},

Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/Cloud-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ describe('CloudController', () => {
});
});

it('run undefined response', (done) => {
const request = jest.fn();
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


const ajax = jest.fn();
CoreManager.setRESTController({ request: request, ajax: ajax });

Cloud.run('myfunction').then(() => {
done();
});
});

it('startJob passes encoded requests', () => {
Cloud.startJob('myJob', { value: 12, when: new Date(Date.UTC(2015,0,1)) });

Expand Down