Skip to content
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
1 change: 1 addition & 0 deletions doc/notification.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ This table shows the name of the setter, with the key-path of the underlying pro
| `urlArgs` | `aps.url-args` | `Array` |
| `category` | `aps.category` | `String` |
| `threadId` | `aps.thread-id` | `String` |
| `interruptionLevel` | `aps.interruption-level` | `String` |
| `mdm` | `mdm` | `String` |

When the notification is transmitted these properties will be added to the output before encoding.
Expand Down
6 changes: 6 additions & 0 deletions lib/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ module.exports = {
}
},

set interruptionLevel(value) {
if(typeof value === "string" || value === undefined) {
Copy link

@TysonAndre TysonAndre Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(typeof value === "string" || value === undefined) {
if (typeof value === "string" || value === undefined) {

nit: use the same spacing used elsewhere

EDIT: oh, it was already inconsistent but if ( seems several times more common. Didn't realize that.

this.aps["interruption-level"] = value;
}
},

prepareAlert: function () {
if (typeof this.aps.alert !== "object") {
this.aps.alert = {"body": this.aps.alert};
Expand Down
2 changes: 1 addition & 1 deletion lib/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Notification.prototype = require("./apsProperties");
["payload", "expiry", "priority", "alert", "body", "locKey",
"locArgs", "title", "subtitle", "titleLocKey", "titleLocArgs", "action",
"actionLocKey", "launchImage", "badge", "sound", "contentAvailable",
"mutableContent", "mdm", "urlArgs", "category", "threadId"].forEach( propName => {
"mutableContent", "mdm", "urlArgs", "category", "threadId", "interruptionLevel"].forEach( propName => {
const methodName = "set" + propName[0].toUpperCase() + propName.slice(1);
Notification.prototype[methodName] = function (value) {
this[propName] = value;
Expand Down
26 changes: 26 additions & 0 deletions test/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,32 @@ describe("Notification", function() {
});
});

describe("interruption-level", function() {
it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.nested.property("aps.interruption\-level");
});

it("can be set to a string", function() {
note.interruptionLevel = "the-interruption-level";

expect(compiledOutput()).to.have.nested.property("aps.interruption\-level", "the-interruption-level");
});

it("can be set to undefined", function() {
note.interruptionLevel = "the-interruption-level";
note.interruptionLevel = undefined;

expect(compiledOutput()).to.not.have.nested.property("aps.interruption\-level");
});

describe("setInterruptionLevel", function () {
it("is chainable", function () {
expect(note.setInterruptionLevel("the-interruption-level")).to.equal(note);
expect(compiledOutput()).to.have.nested.property("aps.interruption\-level", "the-interruption-level");
Copy link

@TysonAndre TysonAndre Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(compiledOutput()).to.have.nested.property("aps.interruption\-level", "the-interruption-level");
expect(compiledOutput()).to.have.nested.property("aps.interruption-level", "the-interruption-level");

nit: unnecessary escaping

EDIT: oh, based on existing test case with unnecessary escaping.

});
});
});

context("when no aps properties are set", function() {
it("is not present", function() {
expect(compiledOutput().aps).to.be.undefined;
Expand Down