Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support headers in data field #148

Merged
merged 2 commits into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions spec/APNS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,67 @@ describe('APNS', () => {
done();
});

it('can send APNS notification headers in data', (done) => {
let args = {
cert: new Buffer('testCert'),
key: new Buffer('testKey'),
production: true,
topic: 'topic'
};
let apns = new APNS(args);
let provider = apns.providers[0];
spyOn(provider, 'send').and.callFake((notification, devices) => {
return Promise.resolve({
sent: devices,
failed: []
})
});
// Mock data
let expirationTime = 1454571491354;
let collapseId = "collapseIdentifier";
let pushType = "alert"; // or background
let data = {
'expiration_time': expirationTime,
'data': {
'alert': 'alert',
'collapse_id': collapseId,
'push_type': pushType,
'priority': 6,
}
};
// Mock devices
let mockedDevices = [
{
deviceToken: '112233',
appIdentifier: 'topic'
},
{
deviceToken: '112234',
appIdentifier: 'topic'
},
{
deviceToken: '112235',
appIdentifier: 'topic'
},
{
deviceToken: '112236',
appIdentifier: 'topic'
}
];
let promise = apns.send(data, mockedDevices);
expect(provider.send).toHaveBeenCalled();
let calledArgs = provider.send.calls.first().args;
let notification = calledArgs[0];
expect(notification.aps.alert).toEqual(data.data.alert);
expect(notification.expiry).toEqual(Math.round(data['expiration_time'] / 1000));
expect(notification.collapseId).toEqual(collapseId);
expect(notification.pushType).toEqual(pushType);
expect(notification.priority).toEqual(6);
let apnDevices = calledArgs[1];
expect(apnDevices.length).toEqual(4);
done();
});

it('can send APNS notification to multiple bundles', (done) => {
let args = [{
cert: new Buffer('testCert'),
Expand Down
8 changes: 4 additions & 4 deletions src/APNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export class APNS {
*/
send(data, allDevices) {
let coreData = data.data;
let expirationTime = data['expiration_time'];
let collapseId = data['collapse_id'];
let pushType = data['push_type'];
let priority = data['priority'];
let expirationTime = data['expiration_time'] || coreData['expiration_time'];
let collapseId = data['collapse_id'] || coreData['collapse_id'];
let pushType = data['push_type'] || coreData['push_type'];
let priority = data['priority'] || coreData['priority'];
let allPromises = [];

let devicesPerAppIdentifier = {};
Expand Down