Skip to content

feat: Add input-push-channel and input-push-token to APS #177

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 4 commits into from
Mar 12, 2025
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
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ interface Aps {
timestamp?: number
event?: string
"dismissal-date"?: number
"input-push-channel"?: string
"input-push-token"?: number
"attributes-type"?: string
attributes?: Object
}
Expand Down
30 changes: 30 additions & 0 deletions lib/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ module.exports = {
}
},

set filterCriteria(value) {
if (typeof value === 'string' || value === undefined) {
this.aps['filter-criteria'] = value;
}
},

set inputPushChannel(value) {
if (typeof value === 'string' || value === undefined) {
this.aps['input-push-channel'] = value;
}
},

set inputPushToken(value) {
if (typeof value === 'number' || value === undefined) {
this.aps['input-push-token'] = value;
}
},

set attributesType(value) {
if (typeof value === 'string' || value === undefined) {
this.aps['attributes-type'] = value;
}
},

set attributes(value) {
if (typeof value === 'object' || value === undefined) {
this.aps['attributes'] = value;
}
},

prepareAlert: function () {
if (typeof this.aps.alert !== 'object') {
this.aps.alert = { body: this.aps.alert };
Expand Down
5 changes: 5 additions & 0 deletions lib/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Notification.prototype = require('./apsProperties');
'event',
'contentState',
'dismissalDate',
'filterCriteria',
'inputPushChannel',
'inputPushToken',
'attributesType',
'attributes',
].forEach(propName => {
const methodName = 'set' + propName[0].toUpperCase() + propName.slice(1);
Notification.prototype[methodName] = function (value) {
Expand Down
153 changes: 153 additions & 0 deletions test/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,159 @@ describe('Notification', function () {
});
});

describe('input-push-channel', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.input-push-channel');
});

it('can be set to a string', function () {
note.inputPushChannel = 'the-input-push-channel';

expect(compiledOutput()).to.have.nested.property(
'aps.input-push-channel',
'the-input-push-channel'
);
});

it('can be set to undefined', function () {
note.inputPushChannel = 'input-push-channel';
note.inputPushChannel = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.input-push-channel');
});

describe('setInputPushChannel', function () {
it('is chainable', function () {
expect(note.setInputPushChannel('the-input-push-channel')).to.equal(note);
expect(compiledOutput()).to.have.nested.property(
'aps.input-push-channel',
'the-input-push-channel'
);
});
});
});

describe('input-push-token', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.input-push-token');
});

it('can be set to a number', function () {
note.inputPushToken = 1;

expect(compiledOutput()).to.have.nested.property('aps.input-push-token', 1);
});

it('can be set to undefined', function () {
note.inputPushToken = 1;
note.inputPushToken = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.input-push-token');
});

describe('setInputPushToken', function () {
it('is chainable', function () {
expect(note.setInputPushToken(1)).to.equal(note);
expect(compiledOutput()).to.have.nested.property('aps.input-push-token', 1);
});
});
});

describe('filter-criteria', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.filter-criteria');
});

it('can be set to a string', function () {
note.filterCriteria = 'the-filter-criteria';

expect(compiledOutput()).to.have.nested.property(
'aps.filter-criteria',
'the-filter-criteria'
);
});

it('can be set to undefined', function () {
note.filterCriteria = 'filter-criteria';
note.filterCriteria = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.filter-criteria');
});

describe('setFilterCriteria', function () {
it('is chainable', function () {
expect(note.setFilterCriteria('the-filter-criteria')).to.equal(note);
expect(compiledOutput()).to.have.nested.property(
'aps.filter-criteria',
'the-filter-criteria'
);
});
});
});

describe('attributes-type', function () {
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.attributes-type');
});

it('can be set to a string', function () {
note.attributesType = 'the-attributes-type';

expect(compiledOutput()).to.have.nested.property(
'aps.attributes-type',
'the-attributes-type'
);
});

it('can be set to undefined', function () {
note.attributesType = 'attributes-type';
note.attributesType = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.attributes-type');
});

describe('setAttributesType', function () {
it('is chainable', function () {
expect(note.setAttributesType('the-attributes-type')).to.equal(note);
expect(compiledOutput()).to.have.nested.property(
'aps.attributes-type',
'the-attributes-type'
);
});
});
});

describe('attributes', function () {
const payload = { foo: 'bar' };
it('defaults to undefined', function () {
expect(compiledOutput()).to.not.have.nested.property('aps.attributes');
});

it('can be set to a object', function () {
note.attributes = payload;

expect(compiledOutput())
.to.have.nested.property('aps.attributes')
.that.deep.equals(payload);
});

it('can be set to undefined', function () {
note.attributes = payload;
note.attributes = undefined;

expect(compiledOutput()).to.not.have.nested.property('aps.attributes');
});

describe('setAttributes', function () {
it('is chainable', function () {
expect(note.setAttributes(payload)).to.equal(note);
expect(compiledOutput())
.to.have.nested.property('aps.attributes')
.that.deep.equals(payload);
});
});
});

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