* Fixes #3717 This fixes PR #3717. Sending push with parse-server@2.4.0 returns error 504 GATEWAY_TIMEOUT. This happens when push_time is not set (default). * Fix lint issues * Fix in PushController and add tests Add a test to check push_time format and if it should schedule push when the parse-server is configured
This commit is contained in:
committed by
Florent Vilmart
parent
35d781a160
commit
03b6449fe1
@@ -131,6 +131,42 @@ describe('PushController', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can get push time in string format', (done) => {
|
||||||
|
// Make mock request
|
||||||
|
var timeStr = '2015-03-19T22:05:08Z';
|
||||||
|
var body = {
|
||||||
|
'push_time': timeStr
|
||||||
|
}
|
||||||
|
|
||||||
|
var time = PushController.getPushTime(body);
|
||||||
|
expect(time).toEqual(new Date(timeStr));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can get push time in number format', (done) => {
|
||||||
|
// Make mock request
|
||||||
|
var timeNumber = 1426802708;
|
||||||
|
var body = {
|
||||||
|
'push_time': timeNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
var time = PushController.getPushTime(body).valueOf();
|
||||||
|
expect(time).toEqual(timeNumber * 1000);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can throw on getPushTime in invalid format', (done) => {
|
||||||
|
// Make mock request
|
||||||
|
var body = {
|
||||||
|
'push_time': 'abcd'
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(function(){
|
||||||
|
PushController.getPushTime(body);
|
||||||
|
}).toThrow();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('properly increment badges', (done) => {
|
it('properly increment badges', (done) => {
|
||||||
var pushAdapter = {
|
var pushAdapter = {
|
||||||
send: function(body, installations) {
|
send: function(body, installations) {
|
||||||
@@ -603,13 +639,24 @@ describe('PushController', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not schedule push when configured', (done) => {
|
it('should schedule push when configured', (done) => {
|
||||||
var auth = {
|
var auth = {
|
||||||
isMaster: true
|
isMaster: true
|
||||||
}
|
}
|
||||||
var pushAdapter = {
|
var pushAdapter = {
|
||||||
send: function(body, installations) {
|
send: function(body, installations) {
|
||||||
return successfulTransmissions(body, installations);
|
const promises = installations.map((device) => {
|
||||||
|
if (!device.deviceToken) {
|
||||||
|
// Simulate error when device token is not set
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
return Promise.resolve({
|
||||||
|
transmitted: true,
|
||||||
|
device: device,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
},
|
},
|
||||||
getValidPushTypes: function() {
|
getValidPushTypes: function() {
|
||||||
return ["ios"];
|
return ["ios"];
|
||||||
@@ -642,7 +689,7 @@ describe('PushController', () => {
|
|||||||
var config = new Config(Parse.applicationId);
|
var config = new Config(Parse.applicationId);
|
||||||
return Parse.Object.saveAll(installations).then(() => {
|
return Parse.Object.saveAll(installations).then(() => {
|
||||||
return pushController.sendPush(payload, {}, config, auth);
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
});
|
}).then(() => new Promise(resolve => setTimeout(resolve, 100)));
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const query = new Parse.Query('_PushStatus');
|
const query = new Parse.Query('_PushStatus');
|
||||||
return query.find({useMasterKey: true}).then((results) => {
|
return query.find({useMasterKey: true}).then((results) => {
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ export class PushController {
|
|||||||
}
|
}
|
||||||
// Replace the expiration_time and push_time with a valid Unix epoch milliseconds time
|
// Replace the expiration_time and push_time with a valid Unix epoch milliseconds time
|
||||||
body.expiration_time = PushController.getExpirationTime(body);
|
body.expiration_time = PushController.getExpirationTime(body);
|
||||||
body.push_time = PushController.getPushTime(body);
|
const push_time = PushController.getPushTime(body);
|
||||||
|
if (typeof push_time !== 'undefined') {
|
||||||
|
body['push_time'] = push_time;
|
||||||
|
}
|
||||||
// TODO: If the req can pass the checking, we return immediately instead of waiting
|
// TODO: If the req can pass the checking, we return immediately instead of waiting
|
||||||
// pushes to be sent. We probably change this behaviour in the future.
|
// pushes to be sent. We probably change this behaviour in the future.
|
||||||
let badgeUpdate = () => {
|
let badgeUpdate = () => {
|
||||||
@@ -50,7 +53,7 @@ export class PushController {
|
|||||||
onPushStatusSaved(pushStatus.objectId);
|
onPushStatusSaved(pushStatus.objectId);
|
||||||
return badgeUpdate();
|
return badgeUpdate();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (body.push_time && config.hasPushScheduledSupport) {
|
if (body.hasOwnProperty('push_time') && config.hasPushScheduledSupport) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
return config.pushControllerQueue.enqueue(body, where, config, auth, pushStatus);
|
return config.pushControllerQueue.enqueue(body, where, config, auth, pushStatus);
|
||||||
|
|||||||
Reference in New Issue
Block a user