Skip to content

Ensured that raw aps data is correctly parsed #95

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

Merged
merged 1 commit into from
Oct 23, 2017
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
33 changes: 33 additions & 0 deletions spec/APNS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,39 @@ describe('APNS', () => {
expect(notification.collapseId).toEqual(collapseId);
done();
});

it('can generate APNS notification from raw data', (done) => {
//Mock request data
let data = {
'aps': {
'alert': {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "Frank"]
},
'badge': 100,
'sound': 'test'
},
'key': 'value',
'keyAgain': 'valueAgain'
};
let expirationTime = 1454571491354;
let collapseId = "collapseIdentifier";

let notification = APNS._generateNotification(data, { expirationTime: expirationTime, collapseId: collapseId });

expect(notification.expiry).toEqual(expirationTime / 1000);
expect(notification.collapseId).toEqual(collapseId);

let stringifiedJSON = notification.compile();
let jsonObject = JSON.parse(stringifiedJSON);

expect(jsonObject.aps.alert).toEqual({ "loc-key" : "GAME_PLAY_REQUEST_FORMAT", "loc-args" : [ "Jenna", "Frank"] });
expect(jsonObject.aps.badge).toEqual(100);
expect(jsonObject.aps.sound).toEqual('test');
expect(jsonObject.key).toEqual('value');
expect(jsonObject.keyAgain).toEqual('valueAgain');
done();
});

it('can choose providers for device with valid appIdentifier', (done) => {
let appIdentifier = 'topic';
Expand Down
3 changes: 3 additions & 0 deletions src/APNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export class APNS {
let payload = {};
for (let key in coreData) {
switch (key) {
case 'aps':
notification.aps = coreData.aps;
break;
case 'alert':
notification.setAlert(coreData.alert);
break;
Expand Down