Fix for #4194 - me no likey much (#4198)

* Adds failing test for #4194

* Use the rest module instad of the Parse._request

- Some users have an invalid serverUrl passed in the options

* removes console.logs, fixes tests that leveraged Parse._request
This commit is contained in:
Florent Vilmart
2017-09-22 12:05:06 -04:00
committed by GitHub
parent 70ca7bdd41
commit b703ec8a79
3 changed files with 96 additions and 52 deletions

View File

@@ -1,6 +1,7 @@
import { md5Hash, newObjectId } from './cryptoUtils';
import { logger } from './logger';
import Parse from 'parse/node';
import rest from './rest';
import Auth from './Auth';
const PUSH_STATUS_COLLECTION = '_PushStatus';
const JOB_STATUS_COLLECTION = '_JobStatus';
@@ -51,21 +52,16 @@ function statusHandler(className, database) {
})
}
function restStatusHandler(className) {
function restStatusHandler(className, config) {
let lastPromise = Promise.resolve();
const auth = Auth.master(config);
function create(object) {
lastPromise = lastPromise.then(() => {
return Parse._request(
'POST',
`classes/${className}`,
object,
{ useMasterKey: true }
).then((result) => {
// merge the objects
const response = Object.assign({}, object, result);
return Promise.resolve(response);
});
return rest.create(config, auth, className, object)
.then(({ response }) => {
// merge the objects
return Promise.resolve(Object.assign({}, object, response));
});
});
return lastPromise;
}
@@ -73,15 +69,11 @@ function restStatusHandler(className) {
function update(where, object) {
// TODO: when we have updateWhere, use that for proper interfacing
lastPromise = lastPromise.then(() => {
return Parse._request(
'PUT',
`classes/${className}/${where.objectId}`,
object,
{ useMasterKey: true }).then((result) => {
// merge the objects
const response = Object.assign({}, object, result);
return Promise.resolve(response);
});
return rest.update(config, auth, className, { objectId: where.objectId }, object)
.then(({ response }) => {
// merge the objects
return Promise.resolve(Object.assign({}, object, response));
});
});
return lastPromise;
}
@@ -149,7 +141,7 @@ export function pushStatusHandler(config, existingObjectId) {
let pushStatus;
const database = config.database;
const handler = restStatusHandler(PUSH_STATUS_COLLECTION);
const handler = restStatusHandler(PUSH_STATUS_COLLECTION, config);
let objectId = existingObjectId;
const setInitial = function(body = {}, where, options = {source: 'rest'}) {
const now = new Date();
@@ -188,7 +180,6 @@ export function pushStatusHandler(config, existingObjectId) {
// lockdown!
ACL: {}
}
return handler.create(object).then((result) => {
objectId = result.objectId;
pushStatus = {