* 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:
@@ -503,6 +503,62 @@ describe('PushController', () => {
|
|||||||
.then(done).catch(done.fail);
|
.then(done).catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('properly creates _PushStatus without serverURL', (done) => {
|
||||||
|
const pushStatusAfterSave = {
|
||||||
|
handler: function() {}
|
||||||
|
};
|
||||||
|
Parse.Cloud.afterSave('_PushStatus', pushStatusAfterSave.handler);
|
||||||
|
const installation = new Parse.Object("_Installation");
|
||||||
|
installation.set("installationId", "installation");
|
||||||
|
installation.set("deviceToken","device_token")
|
||||||
|
installation.set("badge", 0);
|
||||||
|
installation.set("originalBadge", 0);
|
||||||
|
installation.set("deviceType", "ios");
|
||||||
|
|
||||||
|
var payload = {data: {
|
||||||
|
alert: "Hello World!",
|
||||||
|
badge: 1,
|
||||||
|
}}
|
||||||
|
|
||||||
|
var pushAdapter = {
|
||||||
|
send: function(body, installations) {
|
||||||
|
return successfulIOS(body, installations);
|
||||||
|
},
|
||||||
|
getValidPushTypes: function() {
|
||||||
|
return ["ios"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = new Config(Parse.applicationId);
|
||||||
|
var auth = {
|
||||||
|
isMaster: true
|
||||||
|
}
|
||||||
|
var pushController = new PushController();
|
||||||
|
return installation.save().then(() => {
|
||||||
|
return reconfigureServer({
|
||||||
|
serverURL: 'http://localhost:8378/', // server with borked URL
|
||||||
|
push: { adapter: pushAdapter }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
|
}).then(() => {
|
||||||
|
// it is enqueued so it can take time
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
Parse.serverURL = 'http://localhost:8378/1'; // GOOD url
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({useMasterKey: true});
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
})
|
||||||
|
.then(done).catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
it('should properly report failures in _PushStatus', (done) => {
|
it('should properly report failures in _PushStatus', (done) => {
|
||||||
var pushAdapter = {
|
var pushAdapter = {
|
||||||
send: function(body, installations) {
|
send: function(body, installations) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ var PushWorker = require('../src').PushWorker;
|
|||||||
var PushUtils = require('../src/Push/utils');
|
var PushUtils = require('../src/Push/utils');
|
||||||
var Config = require('../src/Config');
|
var Config = require('../src/Config');
|
||||||
var { pushStatusHandler } = require('../src/StatusHandler');
|
var { pushStatusHandler } = require('../src/StatusHandler');
|
||||||
|
var rest = require('../src/rest');
|
||||||
|
|
||||||
describe('PushWorker', () => {
|
describe('PushWorker', () => {
|
||||||
it('should run with small batch', (done) => {
|
it('should run with small batch', (done) => {
|
||||||
@@ -245,7 +246,7 @@ describe('PushWorker', () => {
|
|||||||
it('tracks push status per UTC offsets', (done) => {
|
it('tracks push status per UTC offsets', (done) => {
|
||||||
const config = new Config('test');
|
const config = new Config('test');
|
||||||
const handler = pushStatusHandler(config);
|
const handler = pushStatusHandler(config);
|
||||||
const spy = spyOn(Parse, "_request").and.callThrough();
|
const spy = spyOn(rest, "update").and.callThrough();
|
||||||
const UTCOffset = 1;
|
const UTCOffset = 1;
|
||||||
handler.setInitial().then(() => {
|
handler.setInitial().then(() => {
|
||||||
return handler.trackSent([
|
return handler.trackSent([
|
||||||
@@ -267,9 +268,8 @@ describe('PushWorker', () => {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
const lastCall = spy.calls.mostRecent();
|
const lastCall = spy.calls.mostRecent();
|
||||||
expect(lastCall.args[0]).toBe('PUT');
|
expect(lastCall.args[2]).toBe(`_PushStatus`);
|
||||||
expect(lastCall.args[1]).toBe(`classes/_PushStatus/${handler.objectId}`);
|
expect(lastCall.args[4]).toEqual({
|
||||||
expect(lastCall.args[2]).toEqual({
|
|
||||||
numSent: { __op: 'Increment', amount: 1 },
|
numSent: { __op: 'Increment', amount: 1 },
|
||||||
numFailed: { __op: 'Increment', amount: 1 },
|
numFailed: { __op: 'Increment', amount: 1 },
|
||||||
'sentPerType.ios': { __op: 'Increment', amount: 1 },
|
'sentPerType.ios': { __op: 'Increment', amount: 1 },
|
||||||
@@ -322,35 +322,32 @@ describe('PushWorker', () => {
|
|||||||
it('tracks push status per UTC offsets with negative offsets', (done) => {
|
it('tracks push status per UTC offsets with negative offsets', (done) => {
|
||||||
const config = new Config('test');
|
const config = new Config('test');
|
||||||
const handler = pushStatusHandler(config);
|
const handler = pushStatusHandler(config);
|
||||||
spyOn(config.database, "create").and.callFake(() => {
|
const spy = spyOn(rest, "update").and.callThrough();
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
const spy = spyOn(Parse, "_request").and.callFake(() => {
|
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
const UTCOffset = -6;
|
const UTCOffset = -6;
|
||||||
handler.trackSent([
|
handler.setInitial().then(() => {
|
||||||
{
|
return handler.trackSent([
|
||||||
transmitted: false,
|
{
|
||||||
device: {
|
transmitted: false,
|
||||||
deviceToken: 1,
|
device: {
|
||||||
deviceType: 'ios',
|
deviceToken: 1,
|
||||||
|
deviceType: 'ios',
|
||||||
|
},
|
||||||
|
response: { error: 'Unregistered' }
|
||||||
},
|
},
|
||||||
response: { error: 'Unregistered' }
|
{
|
||||||
},
|
transmitted: true,
|
||||||
{
|
device: {
|
||||||
transmitted: true,
|
deviceToken: 1,
|
||||||
device: {
|
deviceType: 'ios',
|
||||||
deviceToken: 1,
|
},
|
||||||
deviceType: 'ios',
|
response: { error: 'Unregistered' }
|
||||||
},
|
},
|
||||||
response: { error: 'Unregistered' }
|
], UTCOffset);
|
||||||
},
|
}).then(() => {
|
||||||
], UTCOffset).then(() => {
|
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
const lastCall = spy.calls.mostRecent();
|
const lastCall = spy.calls.mostRecent();
|
||||||
expect(lastCall.args[1]).toBe(`classes/_PushStatus/${handler.objectId}`);
|
expect(lastCall.args[2]).toBe('_PushStatus');
|
||||||
expect(lastCall.args[2]).toEqual({
|
expect(lastCall.args[4]).toEqual({
|
||||||
numSent: { __op: 'Increment', amount: 1 },
|
numSent: { __op: 'Increment', amount: 1 },
|
||||||
numFailed: { __op: 'Increment', amount: 1 },
|
numFailed: { __op: 'Increment', amount: 1 },
|
||||||
'sentPerType.ios': { __op: 'Increment', amount: 1 },
|
'sentPerType.ios': { __op: 'Increment', amount: 1 },
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { md5Hash, newObjectId } from './cryptoUtils';
|
import { md5Hash, newObjectId } from './cryptoUtils';
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
import Parse from 'parse/node';
|
import rest from './rest';
|
||||||
|
import Auth from './Auth';
|
||||||
|
|
||||||
const PUSH_STATUS_COLLECTION = '_PushStatus';
|
const PUSH_STATUS_COLLECTION = '_PushStatus';
|
||||||
const JOB_STATUS_COLLECTION = '_JobStatus';
|
const JOB_STATUS_COLLECTION = '_JobStatus';
|
||||||
@@ -51,21 +52,16 @@ function statusHandler(className, database) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function restStatusHandler(className) {
|
function restStatusHandler(className, config) {
|
||||||
let lastPromise = Promise.resolve();
|
let lastPromise = Promise.resolve();
|
||||||
|
const auth = Auth.master(config);
|
||||||
function create(object) {
|
function create(object) {
|
||||||
lastPromise = lastPromise.then(() => {
|
lastPromise = lastPromise.then(() => {
|
||||||
return Parse._request(
|
return rest.create(config, auth, className, object)
|
||||||
'POST',
|
.then(({ response }) => {
|
||||||
`classes/${className}`,
|
// merge the objects
|
||||||
object,
|
return Promise.resolve(Object.assign({}, object, response));
|
||||||
{ useMasterKey: true }
|
});
|
||||||
).then((result) => {
|
|
||||||
// merge the objects
|
|
||||||
const response = Object.assign({}, object, result);
|
|
||||||
return Promise.resolve(response);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return lastPromise;
|
return lastPromise;
|
||||||
}
|
}
|
||||||
@@ -73,15 +69,11 @@ function restStatusHandler(className) {
|
|||||||
function update(where, object) {
|
function update(where, object) {
|
||||||
// TODO: when we have updateWhere, use that for proper interfacing
|
// TODO: when we have updateWhere, use that for proper interfacing
|
||||||
lastPromise = lastPromise.then(() => {
|
lastPromise = lastPromise.then(() => {
|
||||||
return Parse._request(
|
return rest.update(config, auth, className, { objectId: where.objectId }, object)
|
||||||
'PUT',
|
.then(({ response }) => {
|
||||||
`classes/${className}/${where.objectId}`,
|
// merge the objects
|
||||||
object,
|
return Promise.resolve(Object.assign({}, object, response));
|
||||||
{ useMasterKey: true }).then((result) => {
|
});
|
||||||
// merge the objects
|
|
||||||
const response = Object.assign({}, object, result);
|
|
||||||
return Promise.resolve(response);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return lastPromise;
|
return lastPromise;
|
||||||
}
|
}
|
||||||
@@ -149,7 +141,7 @@ export function pushStatusHandler(config, existingObjectId) {
|
|||||||
|
|
||||||
let pushStatus;
|
let pushStatus;
|
||||||
const database = config.database;
|
const database = config.database;
|
||||||
const handler = restStatusHandler(PUSH_STATUS_COLLECTION);
|
const handler = restStatusHandler(PUSH_STATUS_COLLECTION, config);
|
||||||
let objectId = existingObjectId;
|
let objectId = existingObjectId;
|
||||||
const setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
const setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -188,7 +180,6 @@ export function pushStatusHandler(config, existingObjectId) {
|
|||||||
// lockdown!
|
// lockdown!
|
||||||
ACL: {}
|
ACL: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler.create(object).then((result) => {
|
return handler.create(object).then((result) => {
|
||||||
objectId = result.objectId;
|
objectId = result.objectId;
|
||||||
pushStatus = {
|
pushStatus = {
|
||||||
|
|||||||
Reference in New Issue
Block a user