Skip to content

Commit 369f1ff

Browse files
authored
Merge branch 'alpha' into dependabot/npm_and_yarn/parse-server-8.2.1
2 parents 9c69b3f + 2818ed9 commit 369f1ff

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

integration/test/IdempotencyTest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ describe('Idempotency', () => {
3535
it('handle duplicate job request', async () => {
3636
DuplicateRequestId('1234');
3737
const params = { startedBy: 'Monty Python' };
38-
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);
39-
await expectAsync(Parse.Cloud.startJob('CloudJob1', params)).toBeRejectedWithError(
38+
const jobStatusId = await Parse.Cloud.startJob('CloudJobParamsInMessage', params);
39+
await expectAsync(Parse.Cloud.startJob('CloudJobParamsInMessage', params)).toBeRejectedWithError(
4040
'Duplicate request'
4141
);
4242

@@ -49,7 +49,7 @@ describe('Idempotency', () => {
4949
}
5050
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
5151
expect(jobStatus.get('status')).toBe('succeeded');
52-
expect(jobStatus.get('params').startedBy).toBe('Monty Python');
52+
expect(JSON.parse(jobStatus.get('message'))).toEqual(params);
5353
});
5454

5555
it('handle duplicate POST / PUT request', async () => {

integration/test/ParseCloudTest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ describe('Parse Cloud', () => {
9595

9696
it('run job', async () => {
9797
const params = { startedBy: 'Monty Python' };
98-
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);
98+
const jobStatusId = await Parse.Cloud.startJob('CloudJobParamsInMessage', params);
9999
expect(jobStatusId).toBeDefined();
100100
await waitForJobStatus(jobStatusId, 'succeeded');
101101

102102
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
103-
assert.equal(jobStatus.get('status'), 'succeeded');
104-
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
103+
expect(jobStatus.get('status')).toBe('succeeded');
104+
expect(JSON.parse(jobStatus.get('message'))).toEqual(params);
105105
});
106106

107107
it('run long job', async () => {
@@ -137,7 +137,7 @@ describe('Parse Cloud', () => {
137137
it('get jobs data', done => {
138138
Parse.Cloud.getJobsData().then(result => {
139139
assert.equal(result.in_use.length, 0);
140-
assert.equal(result.jobs.length, 3);
140+
assert.equal(result.jobs.length, 4);
141141
done();
142142
});
143143
});

integration/test/cloud/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Parse.Cloud.job('CloudJob2', function () {
4545
});
4646
});
4747

48+
Parse.Cloud.job('CloudJobParamsInMessage', request => {
49+
request.message(JSON.stringify(request.params));
50+
});
51+
4852
Parse.Cloud.job('CloudJobFailing', function () {
4953
throw 'cloud job failed';
5054
});

integration/test/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const defaultConfiguration = {
7474
},
7575
},
7676
idempotencyOptions: {
77-
paths: ['functions/CloudFunctionIdempotency', 'jobs/CloudJob1', 'classes/IdempotentTest'],
77+
paths: ['functions/CloudFunctionIdempotency', 'jobs/CloudJob1', 'jobs/CloudJobParamsInMessage', 'classes/IdempotentTest'],
7878
ttl: 120,
7979
},
8080
fileUpload: {

src/ParseObject.ts

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

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

src/__tests__/Cloud-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,30 @@ 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+
});
359385
});

0 commit comments

Comments
 (0)