Merge pull request #1272 from toddreifsteck/dev
Enable APN compatibility on apnsService
This commit is contained in:
Коммит
bbdd7858fb
|
@ -90,14 +90,7 @@ ApnsService.prototype.send = function (tags, payload, callback) {
|
|||
}
|
||||
|
||||
payload = _.clone(payload);
|
||||
if (payload.payload) {
|
||||
Object.keys(payload.payload).forEach(function (property) {
|
||||
payload[property] = payload.payload[property];
|
||||
});
|
||||
|
||||
delete payload.payload;
|
||||
}
|
||||
|
||||
|
||||
if (payload.expiry) {
|
||||
var expiry = new Date(payload.expiry);
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_APNS_EXPIRY] = expiry.toISOString();
|
||||
|
@ -107,6 +100,14 @@ ApnsService.prototype.send = function (tags, payload, callback) {
|
|||
if (!_.isString(payload)) {
|
||||
if (!payload.aps) {
|
||||
payload = { aps: payload };
|
||||
|
||||
if (payload.aps.payload) {
|
||||
Object.keys(payload.aps.payload).forEach(function (innerPayloadMember) {
|
||||
payload[innerPayloadMember] = payload.aps.payload[innerPayloadMember];
|
||||
});
|
||||
|
||||
delete payload.aps.payload;
|
||||
}
|
||||
}
|
||||
|
||||
payload = JSON.stringify(payload);
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// Copyright (c) Microsoft and contributors. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
@ -97,23 +97,88 @@ describe('APNS notifications', function () {
|
|||
});
|
||||
|
||||
it('should send a simple message', function (done) {
|
||||
notificationHubService.apns.send(null, {
|
||||
alert: 'This is my toast message for iOS!'
|
||||
}, function (error, result) {
|
||||
var sendPayload = {
|
||||
alert: 'This is my toast message for iOS simple!'
|
||||
};
|
||||
|
||||
var expectedPayload = {
|
||||
aps: { alert: 'This is my toast message for iOS simple!' }
|
||||
};
|
||||
|
||||
var executeSpy = sandbox.spy(notificationHubService, '_executeRequest');
|
||||
notificationHubService.apns.send(null, sendPayload, function (error, result) {
|
||||
should.not.exist(error);
|
||||
result.statusCode.should.equal(201);
|
||||
|
||||
executeSpy.args[0][1].should.equal(JSON.stringify(expectedPayload));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a simple message with payload in apn format', function (done) {
|
||||
var sendPayload = {
|
||||
alert: 'This is my toast message for iOS apn format!',
|
||||
payload: { innerMember: 'Apn promotes payload members to members at same level as aps' }
|
||||
};
|
||||
|
||||
var expectedPayload = {
|
||||
aps: { alert: 'This is my toast message for iOS apn format!' },
|
||||
innerMember: 'Apn promotes payload members to members at same level as aps'
|
||||
};
|
||||
|
||||
var executeSpy = sandbox.spy(notificationHubService, '_executeRequest');
|
||||
notificationHubService.apns.send(null, sendPayload, function (error, result) {
|
||||
should.not.exist(error);
|
||||
result.statusCode.should.equal(201);
|
||||
|
||||
executeSpy.args[0][1].should.equal(JSON.stringify(expectedPayload));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a simple message when payload matches APNS specs', function (done) {
|
||||
notificationHubService.apns.send(null, {
|
||||
aps: { alert: 'This is my toast message for iOS!' }
|
||||
}, function (error, result) {
|
||||
var sendPayload = {
|
||||
aps: { alert: 'This is my toast message for iOS apns specs!' }
|
||||
};
|
||||
|
||||
var executeSpy = sandbox.spy(notificationHubService, '_executeRequest');
|
||||
notificationHubService.apns.send(null, sendPayload, function (error, result) {
|
||||
should.not.exist(error);
|
||||
result.statusCode.should.equal(201);
|
||||
|
||||
executeSpy.args[0][1].should.equal(JSON.stringify(sendPayload));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a simple message when payload matches APNS specs and not change other members', function (done) {
|
||||
var sendPayload = {
|
||||
aps: { alert: 'This is my toast message for iOS apns spec with data!' },
|
||||
otherMember: 'Members outside of aps are useful for sending data in notification'
|
||||
}
|
||||
|
||||
var executeSpy = sandbox.spy(notificationHubService, '_executeRequest');
|
||||
notificationHubService.apns.send(null, sendPayload, function (error, result) {
|
||||
should.not.exist(error);
|
||||
result.statusCode.should.equal(201);
|
||||
|
||||
executeSpy.args[0][1].should.equal(JSON.stringify(sendPayload));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a simple message when payload matches APNS specs and not change payload member', function (done) {
|
||||
var sendPayload = {
|
||||
aps: { alert: 'This is my toast message for iOS apns with payload extra!' },
|
||||
payload: { data: 'Members outside of aps are useful for sending data in notification' }
|
||||
};
|
||||
|
||||
var executeSpy = sandbox.spy(notificationHubService, '_executeRequest');
|
||||
notificationHubService.apns.send(null, sendPayload, function (error, result) {
|
||||
should.not.exist(error);
|
||||
result.statusCode.should.equal(201);
|
||||
|
||||
executeSpy.args[0][1].should.equal(JSON.stringify(sendPayload));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -126,7 +191,7 @@ describe('APNS notifications', function () {
|
|||
notificationHubService.apns.send(
|
||||
tagsString,
|
||||
{
|
||||
alert: 'This is my toast message for iOS!',
|
||||
alert: 'This is my toast message for iOS with tags!',
|
||||
expiry: expiryDate
|
||||
},
|
||||
function (error, result) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче