Skip to content
Closed
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
24 changes: 12 additions & 12 deletions lib/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ Notification.prototype = require("./apsProperties");
Notification.prototype.headers = function headers() {
let headers = {};

if (this.priority !== 10) {
headers["apns-priority"] = this.priority;
if (this.payload.priority) {
headers["apns-priority"] = this.payload.priority;
}

if (this.id) {
headers["apns-id"] = this.id;
if (this.payload.id) {
headers["apns-id"] = this.payload.id;
}

if (this.expiry > 0) {
headers["apns-expiration"] = this.expiry;
if (this.payload.expiry) {
headers["apns-expiration"] = this.payload.expiry;
}

if (this.topic) {
headers["apns-topic"] = this.topic;
if (this.payload.topic) {
headers["apns-topic"] = this.payload.topic;
}

if (this.collapseId) {
headers["apns-collapse-id"] = this.collapseId;
if (this.payload.collapseId) {
headers["apns-collapse-id"] = this.payload.collapseId;
}

if (this.pushType) {
headers["apns-push-type"] = this.pushType;
if (this.payload.pushType) {
headers["apns-push-type"] = this.payload.pushType;
}

return headers;
Expand Down
14 changes: 7 additions & 7 deletions test/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,48 +118,48 @@ describe("Notification", function() {

context("priority is non-default", function() {
it("contains the apns-priority header", function() {
note.priority = 5;
note.payload.priority = 5;
expect(note.headers()).to.have.property("apns-priority", 5);
});
});

context("id is set", function() {
it("contains the apns-id header", function() {
note.id = "123e4567-e89b-12d3-a456-42665544000";
note.payload.id = "123e4567-e89b-12d3-a456-42665544000";

expect(note.headers()).to.have.property("apns-id", "123e4567-e89b-12d3-a456-42665544000");
});
});

context("expiry is non-zero", function() {
it("contains the apns-expiration header", function() {
note.expiry = 1000;
note.payload.expiry = 1000;

expect(note.headers()).to.have.property("apns-expiration", 1000);
});
});

context("topic is set", function() {
it("contains the apns-topic header", function() {
note.topic = "io.apn.node";
note.payload.topic = "io.apn.node";

expect(note.headers()).to.have.property("apns-topic", "io.apn.node");
});
});

context("collapseId is set", function () {
it("contains the apns-collapse-id header", function () {
note.collapseId = "io.apn.collapse";
note.payload.collapseId = "io.apn.collapse";

expect(note.headers()).to.have.property("apns-collapse-id", "io.apn.collapse");
});
});

context("pushType is set", function () {
it("contains the apns-push-type header", function () {
note.pushType = "alert";
note.payload.pushType = "background";

expect(note.headers()).to.have.property("apns-push-type", "alert");
expect(note.headers()).to.have.property("apns-push-type", "background");
});
});
});
Expand Down