Skip to content

Commit

Permalink
fix: Parse.Cloud.startJob and Parse.Push.send not returning statu…
Browse files Browse the repository at this point in the history
…s ID when setting Parse Server option `directAccess: true` (parse-community#8766)
  • Loading branch information
dplewis authored Apr 14, 2024
1 parent 6364948 commit 5b0efb2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
54 changes: 54 additions & 0 deletions spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,4 +631,58 @@ describe('ParseServerRESTController', () => {
expect(sessions[0].get('installationId')).toBe(installationId);
expect(sessions[0].get('sessionToken')).toBe(loggedUser.sessionToken);
});

it('returns a statusId when running jobs', async () => {
Parse.Cloud.job('CloudJob', () => {
return 'Cloud job completed';
});
const res = await RESTController.request(
'POST',
'/jobs/CloudJob',
{},
{ useMasterKey: true, returnStatus: true }
);
const jobStatusId = res._headers['X-Parse-Job-Status-Id'];
expect(jobStatusId).toBeDefined();
const result = await Parse.Cloud.getJobStatus(jobStatusId);
expect(result.id).toBe(jobStatusId);
});

it('returns a statusId when running push notifications', async () => {
const payload = {
data: { alert: 'We return status!' },
where: { deviceType: 'ios' },
};
const res = await RESTController.request('POST', '/push', payload, {
useMasterKey: true,
returnStatus: true,
});
const pushStatusId = res._headers['X-Parse-Push-Status-Id'];
expect(pushStatusId).toBeDefined();

const result = await Parse.Push.getPushStatus(pushStatusId);
expect(result.id).toBe(pushStatusId);
});

it('returns a statusId when running batch push notifications', async () => {
const payload = {
data: { alert: 'We return status!' },
where: { deviceType: 'ios' },
};
const res = await RESTController.request('POST', 'batch', {
requests: [{
method: 'POST',
path: '/push',
body: payload,
}],
}, {
useMasterKey: true,
returnStatus: true,
});
const pushStatusId = res[0]._headers['X-Parse-Push-Status-Id'];
expect(pushStatusId).toBeDefined();

const result = await Parse.Push.getPushStatus(pushStatusId);
expect(result.id).toBe(pushStatusId);
});
});
8 changes: 5 additions & 3 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function ParseServerRESTController(applicationId, router) {
response => {
if (options.returnStatus) {
const status = response._status;
const headers = response._headers;
delete response._status;
return { success: response, _status: status };
delete response._headers;
return { success: response, _status: status, _headers: headers };
}
return { success: response };
},
Expand Down Expand Up @@ -128,9 +130,9 @@ function ParseServerRESTController(applicationId, router) {
})
.then(
resp => {
const { response, status } = resp;
const { response, status, headers = {} } = resp;
if (options.returnStatus) {
resolve({ ...response, _status: status });
resolve({ ...response, _status: status, _headers: headers });
} else {
resolve(response);
}
Expand Down

0 comments on commit 5b0efb2

Please sign in to comment.