Skip to content

Commit a8bb14b

Browse files
author
Marcus Olsson
committed
fix: Null fix in ParseObject (#2622)
1 parent bee4a41 commit a8bb14b

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/ParseObject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ class ParseObject<T extends Attributes = Attributes> {
514514

515515
static _getRequestOptions(options: RequestOptions & FullOptions & { json?: boolean } = {}) {
516516
const requestOptions: RequestOptions & FullOptions & { json?: boolean } = {};
517-
if (!options) {
518-
return requestOptions;
517+
if (Object.prototype.toString.call(options) !== '[object Object]') {
518+
throw new Error('request options must be of type Object');
519519
}
520520
const { hasOwn } = Object;
521521
if (hasOwn(options, 'useMasterKey')) {

src/__tests__/Cloud-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,31 @@ describe('CloudController', () => {
356356
});
357357
expect(options.useMasterKey).toBe(false);
358358
});
359+
360+
it('run passes with empty options', () => {
361+
const values = [undefined, {}];
362+
363+
const mockRun = jest.fn();
364+
mockRun.mockReturnValue(Promise.resolve({ result: {} }));
365+
366+
CoreManager.setCloudController({
367+
run: mockRun,
368+
getJobsData: jest.fn(),
369+
startJob: jest.fn(),
370+
});
371+
372+
for (const value of values) {
373+
mockRun.mockClear();
374+
expect(() => Cloud.run('myfunction', {}, value)).not.toThrow();
375+
expect(mockRun).toHaveBeenLastCalledWith('myfunction', {}, {});
376+
}
377+
});
378+
379+
it('run throws with invalid options', () => {
380+
const values = [null, []];
381+
for (const value of values) {
382+
expect(() => Cloud.run('myfunction', {}, value)).toThrow();
383+
}
384+
});
385+
359386
});

src/__tests__/ParseObject-test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,23 +3543,3 @@ describe('ParseObject pin', () => {
35433543
CoreManager.set('NODE_LOGGING', false);
35443544
});
35453545
});
3546-
3547-
describe('ParseObject._getRequestOptions', () => {
3548-
it('returns empty object when options is null', () => {
3549-
const requestOptions = ParseObject._getRequestOptions(null);
3550-
3551-
expect(requestOptions).toEqual({});
3552-
});
3553-
3554-
it('returns empty object when options is an empty string', () => {
3555-
const requestOptions = ParseObject._getRequestOptions("");
3556-
3557-
expect(requestOptions).toEqual({});
3558-
});
3559-
3560-
it('returns empty object when options is undefined', () => {
3561-
const requestOptions = ParseObject._getRequestOptions(undefined);
3562-
3563-
expect(requestOptions).toEqual({});
3564-
});
3565-
});

0 commit comments

Comments
 (0)