Push: Cleanup invalid device tokens (#4149)

* Adds collecting invalid / expired device tokens from GCM / APNS

* Cleanup invalid installations based on responses from the adapters

* Adds test for cleanup

* Adds tests for removal
This commit is contained in:
Florent Vilmart
2017-09-12 14:53:05 -04:00
committed by GitHub
parent a1554d04ab
commit 3a17904ce8
3 changed files with 111 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
var PushWorker = require('../src').PushWorker;
var PushUtils = require('../src/Push/utils');
var Config = require('../src/Config');
var { pushStatusHandler } = require('../src/StatusHandler');
describe('PushWorker', () => {
it('should run with small batch', (done) => {
@@ -156,4 +157,89 @@ describe('PushWorker', () => {
expect(PushUtils.groupByLocaleIdentifier([])).toEqual({default: []});
});
});
describe('pushStatus', () => {
it('should remove invalid installations', (done) => {
const config = new Config('test');
const handler = pushStatusHandler(config);
const spy = spyOn(config.database, "update").and.callFake(() => {
return Promise.resolve();
});
handler.trackSent([
{
transmitted: false,
device: {
deviceToken: 1,
deviceType: 'ios',
},
response: { error: 'Unregistered' }
},
{
transmitted: true,
device: {
deviceToken: 10,
deviceType: 'ios',
},
},
{
transmitted: false,
device: {
deviceToken: 2,
deviceType: 'ios',
},
response: { error: 'NotRegistered' }
},
{
transmitted: false,
device: {
deviceToken: 3,
deviceType: 'ios',
},
response: { error: 'InvalidRegistration' }
},
{
transmitted: true,
device: {
deviceToken: 11,
deviceType: 'ios',
},
},
{
transmitted: false,
device: {
deviceToken: 4,
deviceType: 'ios',
},
response: { error: 'InvalidRegistration' }
},
{
transmitted: false,
device: {
deviceToken: 5,
deviceType: 'ios',
},
response: { error: 'InvalidRegistration' }
},
{ // should not be deleted
transmitted: false,
device: {
deviceToken: 101,
deviceType: 'ios',
},
response: { error: 'invalid error...' }
}
], true);
expect(spy).toHaveBeenCalled();
expect(spy.calls.count()).toBe(1);
const lastCall = spy.calls.mostRecent();
expect(lastCall.args[0]).toBe('_Installation');
expect(lastCall.args[1]).toEqual({
deviceToken: { '$in': [1,2,3,4,5] }
});
expect(lastCall.args[2]).toEqual({
deviceToken: { '__op': "Delete" }
});
done();
});
});
});