Skip to content

Commit 86b0ef8

Browse files
committed
add aps.attributes to js
1 parent 0ac98a9 commit 86b0ef8

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

lib/notification/apsProperties.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ module.exports = {
203203
}
204204
},
205205

206+
set attributes(value) {
207+
if (typeof value === 'object' || value === undefined) {
208+
this.aps['attributes'] = value;
209+
}
210+
},
211+
206212
prepareAlert: function () {
207213
if (typeof this.aps.alert !== 'object') {
208214
this.aps.alert = { body: this.aps.alert };

lib/notification/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Notification.prototype = require('./apsProperties');
6161
'inputPushChannel',
6262
'inputPushToken',
6363
'attributesType',
64+
'attributes',
6465
].forEach(propName => {
6566
const methodName = 'set' + propName[0].toUpperCase() + propName.slice(1);
6667
Notification.prototype[methodName] = function (value) {

test/notification/apsProperties.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,37 @@ describe('Notification', function () {
12211221
});
12221222
});
12231223

1224+
describe('attributes', function () {
1225+
const payload = { foo: 'bar' };
1226+
it('defaults to undefined', function () {
1227+
expect(compiledOutput()).to.not.have.nested.property('aps.attributes');
1228+
});
1229+
1230+
it('can be set to a object', function () {
1231+
note.attributes = payload;
1232+
1233+
expect(compiledOutput())
1234+
.to.have.nested.property('aps.attributes')
1235+
.that.deep.equals(payload);
1236+
});
1237+
1238+
it('can be set to undefined', function () {
1239+
note.attributes = payload;
1240+
note.attributes = undefined;
1241+
1242+
expect(compiledOutput()).to.not.have.nested.property('aps.attributes');
1243+
});
1244+
1245+
describe('setAttributes', function () {
1246+
it('is chainable', function () {
1247+
expect(note.setAttributes(payload)).to.equal(note);
1248+
expect(compiledOutput())
1249+
.to.have.nested.property('aps.attributes')
1250+
.that.deep.equals(payload);
1251+
});
1252+
});
1253+
});
1254+
12241255
context('when no aps properties are set', function () {
12251256
it('is not present', function () {
12261257
expect(compiledOutput().aps).to.be.undefined;

0 commit comments

Comments
 (0)