push notifications unsubscribe method refactor
This commit is contained in:
parent
88d292aace
commit
bd7bcbab45
|
@ -527,18 +527,9 @@ ExpressApp.prototype.start = function(opts, cb) {
|
|||
});
|
||||
});
|
||||
|
||||
router.delete('/v1/pushnotifications/subscriptions/', function(req, res) {
|
||||
router.delete('/v1/pushnotifications/subscriptions/:token/', function(req, res) {
|
||||
getServerWithAuth(req, res, function(server) {
|
||||
server.pushNotificationsUnsubscribe(null, function(err, response) {
|
||||
if (err) return returnError(err, res, req);
|
||||
res.json(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/v1/pushnotifications/subscriptions/:opts/', function(req, res) {
|
||||
getServerWithAuth(req, res, function(server) {
|
||||
server.pushNotificationsUnsubscribe(req.params['opts'], function(err, response) {
|
||||
server.pushNotificationsUnsubscribe(req.params['token'], function(err, response) {
|
||||
if (err) return returnError(err, res, req);
|
||||
res.json(response);
|
||||
});
|
||||
|
|
|
@ -2430,7 +2430,7 @@ WalletService.prototype.getFiatRate = function(opts, cb) {
|
|||
WalletService.prototype.pushNotificationsSubscribe = function(opts, cb) {
|
||||
var self = this;
|
||||
|
||||
opts.user = self.walletId + '$' + self.copayerId;
|
||||
opts.user = self.walletId + '$' + self.copayerId + '$' + opts.token;
|
||||
|
||||
request({
|
||||
url: config.pushNotificationsOpts.pushServerUrl + '/subscribe',
|
||||
|
@ -2442,21 +2442,16 @@ WalletService.prototype.pushNotificationsSubscribe = function(opts, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
WalletService.prototype.pushNotificationsUnsubscribe = function(opts, cb) {
|
||||
WalletService.prototype.pushNotificationsUnsubscribe = function(token, cb) {
|
||||
var self = this;
|
||||
|
||||
if (opts) opts = {
|
||||
token: opts
|
||||
};
|
||||
else opts = {
|
||||
user: self.walletId + '$' + self.copayerId
|
||||
};
|
||||
|
||||
request({
|
||||
url: config.pushNotificationsOpts.pushServerUrl + '/unsubscribe',
|
||||
method: 'POST',
|
||||
json: true,
|
||||
body: opts
|
||||
body: {
|
||||
user: self.walletId + '$' + self.copayerId + '$' + token
|
||||
}
|
||||
}, function(err, response) {
|
||||
return cb(err, response);
|
||||
});
|
||||
|
|
|
@ -5453,7 +5453,7 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Subscribe/unsubscribe', function() {
|
||||
describe.only('Subscribe/unsubscribe', function() {
|
||||
var server, wallet;
|
||||
beforeEach(function(done) {
|
||||
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
||||
|
@ -5467,7 +5467,9 @@ describe('Wallet service', function() {
|
|||
request.yields();
|
||||
helpers.getAuthServer(wallet.copayers[0].id, function(server) {
|
||||
should.exist(server);
|
||||
server.pushNotificationsSubscribe({}, function(err, response) {
|
||||
server.pushNotificationsSubscribe({
|
||||
token: 'DEVICE_TOKEN'
|
||||
}, function(err, response) {
|
||||
should.not.exist(err);
|
||||
var calls = request.getCalls();
|
||||
calls.length.should.equal(1);
|
||||
|
@ -5475,6 +5477,8 @@ describe('Wallet service', function() {
|
|||
return c.args[0];
|
||||
});
|
||||
args[0].body.user.should.contain(wallet.copayers[0].id);
|
||||
args[0].body.user.should.contain(wallet.id);
|
||||
args[0].body.user.should.contain('DEVICE_TOKEN');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -5484,7 +5488,7 @@ describe('Wallet service', function() {
|
|||
request.yields();
|
||||
helpers.getAuthServer(wallet.copayers[0].id, function(server) {
|
||||
should.exist(server);
|
||||
server.pushNotificationsUnsubscribe(null, function(err, response) {
|
||||
server.pushNotificationsUnsubscribe('DEVICE_TOKEN', function(err, response) {
|
||||
should.not.exist(err);
|
||||
var calls = request.getCalls();
|
||||
calls.length.should.equal(1);
|
||||
|
@ -5493,24 +5497,8 @@ describe('Wallet service', function() {
|
|||
});
|
||||
|
||||
args[0].body.user.should.contain(wallet.copayers[0].id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should unsubscribe all wallets from device to push notifications service', function(done) {
|
||||
request.yields();
|
||||
helpers.getAuthServer(wallet.copayers[0].id, function(server) {
|
||||
should.exist(server);
|
||||
server.pushNotificationsUnsubscribe('TOKEN_DEVICE', function(err, response) {
|
||||
should.not.exist(err);
|
||||
var calls = request.getCalls();
|
||||
calls.length.should.equal(1);
|
||||
var args = _.map(calls, function(c) {
|
||||
return c.args[0];
|
||||
});
|
||||
|
||||
args[0].body.token.should.contain('TOKEN_DEVICE');
|
||||
args[0].body.user.should.contain(wallet.id);
|
||||
args[0].body.user.should.contain('DEVICE_TOKEN');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue