Browse Source

test subscribe/unsubscribe

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
c4f6290fda
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 103
      test/integration/server.js

103
test/integration/server.js

@ -7032,40 +7032,105 @@ describe('Wallet service', function() {
}); });
it('should subscribe copayer to push notifications service', function(done) { it('should subscribe copayer to push notifications service', function(done) {
request.yields();
helpers.getAuthServer(wallet.copayers[0].id, function(server) { helpers.getAuthServer(wallet.copayers[0].id, function(server) {
should.exist(server); should.exist(server);
server.pushNotificationsSubscribe({ server.pushNotificationsSubscribe({
token: 'DEVICE_TOKEN' token: 'DEVICE_TOKEN',
}, function(err, response) { packageName: 'com.wallet',
platform: 'Android',
}, function(err) {
should.not.exist(err); should.not.exist(err);
var calls = request.getCalls(); server.storage.fetchPushNotificationSubs(wallet.copayers[0].id, function(err, subs) {
calls.length.should.equal(1); should.not.exist(err);
var args = _.map(calls, function(c) { should.exist(subs);
return c.args[0]; subs.length.should.equal(1);
var s = subs[0];
s.token.should.equal('DEVICE_TOKEN');
s.packageName.should.equal('com.wallet');
s.platform.should.equal('Android')
done();
});
});
}); });
args[0].body.user.should.contain(wallet.copayers[0].id); });
args[0].body.user.should.contain(wallet.id); it('should allow multiple subscriptions for the same copayer', function(done) {
args[0].body.token.should.contain('DEVICE_TOKEN'); helpers.getAuthServer(wallet.copayers[0].id, function(server) {
should.exist(server);
server.pushNotificationsSubscribe({
token: 'DEVICE_TOKEN',
packageName: 'com.wallet',
platform: 'Android',
}, function(err) {
server.pushNotificationsSubscribe({
token: 'DEVICE_TOKEN2',
packageName: 'com.my-other-wallet',
platform: 'iOS',
}, function(err) {
should.not.exist(err);
server.storage.fetchPushNotificationSubs(wallet.copayers[0].id, function(err, subs) {
should.not.exist(err);
should.exist(subs);
subs.length.should.equal(2);
done(); done();
}); });
}); });
}); });
});
});
it('should unsubscribe copayer to push notifications service', function(done) { it('should unsubscribe copayer to push notifications service', function(done) {
request.yields();
helpers.getAuthServer(wallet.copayers[0].id, function(server) { helpers.getAuthServer(wallet.copayers[0].id, function(server) {
should.exist(server); should.exist(server);
server.pushNotificationsUnsubscribe(function(err, response) { async.series([
function(next) {
server.pushNotificationsSubscribe({
token: 'DEVICE_TOKEN',
packageName: 'com.wallet',
platform: 'Android',
}, next);
},
function(next) {
server.pushNotificationsSubscribe({
token: 'DEVICE_TOKEN2',
packageName: 'com.my-other-wallet',
platform: 'iOS',
}, next);
},
function(next) {
server.pushNotificationsUnsubscribe({
token: 'DEVICE_TOKEN2'
}, next);
},
function(next) {
server.storage.fetchPushNotificationSubs(wallet.copayers[0].id, function(err, subs) {
should.not.exist(err); should.not.exist(err);
var calls = request.getCalls(); should.exist(subs);
calls.length.should.equal(1); subs.length.should.equal(1);
var args = _.map(calls, function(c) { var s = subs[0];
return c.args[0]; s.token.should.equal('DEVICE_TOKEN');
next();
}); });
},
args[0].body.user.should.contain(wallet.copayers[0].id); function(next) {
args[0].body.user.should.contain(wallet.id); helpers.getAuthServer(wallet.copayers[1].id, function(server) {
server.pushNotificationsUnsubscribe({
token: 'DEVICE_TOKEN'
}, next);
});
},
function(next) {
server.storage.fetchPushNotificationSubs(wallet.copayers[0].id, function(err, subs) {
should.not.exist(err);
should.exist(subs);
subs.length.should.equal(1);
var s = subs[0];
s.token.should.equal('DEVICE_TOKEN');
next();
});
},
], function(err) {
should.not.exist(err);
done(); done();
}); });
}); });

Loading…
Cancel
Save