2016-03-13 19:47:56 -04:00
|
|
|
|
'use strict';
|
2016-03-29 09:44:04 -04:00
|
|
|
|
|
2016-04-20 13:35:48 -07:00
|
|
|
|
let request = require('request');
|
2016-03-29 09:44:04 -04:00
|
|
|
|
|
2016-03-07 17:19:55 -05:00
|
|
|
|
describe('Parse.Push', () => {
|
2016-03-29 09:44:04 -04:00
|
|
|
|
|
|
|
|
|
|
var setup = function() {
|
|
|
|
|
|
var pushAdapter = {
|
|
|
|
|
|
send: function(body, installations) {
|
|
|
|
|
|
var badge = body.data.badge;
|
|
|
|
|
|
let promises = installations.map((installation) => {
|
|
|
|
|
|
if (installation.deviceType == "ios") {
|
|
|
|
|
|
expect(installation.badge).toEqual(badge);
|
|
|
|
|
|
expect(installation.originalBadge+1).toEqual(installation.badge);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
expect(installation.badge).toBeUndefined();
|
|
|
|
|
|
}
|
|
|
|
|
|
return Promise.resolve({
|
|
|
|
|
|
err: null,
|
|
|
|
|
|
deviceType: installation.deviceType,
|
|
|
|
|
|
result: true
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
|
},
|
|
|
|
|
|
getValidPushTypes: function() {
|
|
|
|
|
|
return ["ios", "android"];
|
2016-03-07 17:19:55 -05:00
|
|
|
|
}
|
2016-03-29 09:44:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-07 17:19:55 -05:00
|
|
|
|
setServerConfiguration({
|
|
|
|
|
|
appId: Parse.applicationId,
|
|
|
|
|
|
masterKey: Parse.masterKey,
|
|
|
|
|
|
serverURL: Parse.serverURL,
|
|
|
|
|
|
push: {
|
|
|
|
|
|
adapter: pushAdapter
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2016-03-29 09:44:04 -04:00
|
|
|
|
|
2016-03-07 17:19:55 -05:00
|
|
|
|
var installations = [];
|
|
|
|
|
|
while(installations.length != 10) {
|
|
|
|
|
|
var installation = new Parse.Object("_Installation");
|
|
|
|
|
|
installation.set("installationId", "installation_"+installations.length);
|
|
|
|
|
|
installation.set("deviceToken","device_token_"+installations.length)
|
|
|
|
|
|
installation.set("badge", installations.length);
|
|
|
|
|
|
installation.set("originalBadge", installations.length);
|
|
|
|
|
|
installation.set("deviceType", "ios");
|
|
|
|
|
|
installations.push(installation);
|
|
|
|
|
|
}
|
2016-03-29 09:44:04 -04:00
|
|
|
|
return Parse.Object.saveAll(installations);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('should properly send push', (done) => {
|
|
|
|
|
|
return setup().then(() => {
|
2016-03-07 17:19:55 -05:00
|
|
|
|
return Parse.Push.send({
|
2016-03-29 09:44:04 -04:00
|
|
|
|
where: {
|
|
|
|
|
|
deviceType: 'ios'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: {
|
|
|
|
|
|
badge: 'Increment',
|
|
|
|
|
|
alert: 'Hello world!'
|
|
|
|
|
|
}
|
|
|
|
|
|
}, {useMasterKey: true})
|
2016-03-07 17:19:55 -05:00
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
done();
|
|
|
|
|
|
}, (err) => {
|
2016-03-29 09:44:04 -04:00
|
|
|
|
console.error();
|
|
|
|
|
|
fail('should not fail sending push')
|
|
|
|
|
|
done();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should properly send push with lowercaseIncrement', (done) => {
|
|
|
|
|
|
return setup().then(() => {
|
|
|
|
|
|
return Parse.Push.send({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
deviceType: 'ios'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: {
|
|
|
|
|
|
badge: 'increment',
|
|
|
|
|
|
alert: 'Hello world!'
|
|
|
|
|
|
}
|
|
|
|
|
|
}, {useMasterKey: true})
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
done();
|
|
|
|
|
|
}, (err) => {
|
|
|
|
|
|
console.error();
|
|
|
|
|
|
fail('should not fail sending push')
|
2016-03-07 17:19:55 -05:00
|
|
|
|
done();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-04-20 13:35:48 -07:00
|
|
|
|
|
|
|
|
|
|
it('should not allow clients to query _PushStatus', done => {
|
|
|
|
|
|
setup()
|
|
|
|
|
|
.then(() => Parse.Push.send({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
deviceType: 'ios'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: {
|
|
|
|
|
|
badge: 'increment',
|
|
|
|
|
|
alert: 'Hello world!'
|
|
|
|
|
|
}
|
|
|
|
|
|
}, {useMasterKey: true}))
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
request.get({
|
|
|
|
|
|
url: 'http://localhost:8378/1/classes/_PushStatus',
|
|
|
|
|
|
json: true,
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'X-Parse-Application-Id': 'test',
|
|
|
|
|
|
},
|
|
|
|
|
|
}, (error, response, body) => {
|
|
|
|
|
|
expect(body.results.length).toEqual(0);
|
|
|
|
|
|
done();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should allow master key to query _PushStatus', done => {
|
|
|
|
|
|
setup()
|
|
|
|
|
|
.then(() => Parse.Push.send({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
deviceType: 'ios'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: {
|
|
|
|
|
|
badge: 'increment',
|
|
|
|
|
|
alert: 'Hello world!'
|
|
|
|
|
|
}
|
|
|
|
|
|
}, {useMasterKey: true}))
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
request.get({
|
|
|
|
|
|
url: 'http://localhost:8378/1/classes/_PushStatus',
|
|
|
|
|
|
json: true,
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'X-Parse-Application-Id': 'test',
|
|
|
|
|
|
'X-Parse-Master-Key': 'test',
|
|
|
|
|
|
},
|
|
|
|
|
|
}, (error, response, body) => {
|
|
|
|
|
|
expect(body.results.length).toEqual(1);
|
|
|
|
|
|
expect(body.results[0].query).toEqual('{"deviceType":"ios"}');
|
|
|
|
|
|
expect(body.results[0].payload).toEqual('{"badge":"increment","alert":"Hello world!"}');
|
|
|
|
|
|
done();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-03-13 18:15:15 -04:00
|
|
|
|
});
|