|
@ -10,6 +10,8 @@ var log = require('npmlog'); |
|
|
log.debug = log.verbose; |
|
|
log.debug = log.verbose; |
|
|
log.level = 'info'; |
|
|
log.level = 'info'; |
|
|
|
|
|
|
|
|
|
|
|
var sjcl = require('sjcl'); |
|
|
|
|
|
|
|
|
var WalletService = require('../../lib/server'); |
|
|
var WalletService = require('../../lib/server'); |
|
|
var PushNotificationsService = require('../../lib/pushnotificationsservice'); |
|
|
var PushNotificationsService = require('../../lib/pushnotificationsservice'); |
|
|
|
|
|
|
|
@ -36,11 +38,24 @@ describe('Push notifications', function() { |
|
|
var i = 0; |
|
|
var i = 0; |
|
|
async.eachSeries(w.copayers, function(copayer, next) { |
|
|
async.eachSeries(w.copayers, function(copayer, next) { |
|
|
helpers.getAuthServer(copayer.id, function(server) { |
|
|
helpers.getAuthServer(copayer.id, function(server) { |
|
|
server.savePreferences({ |
|
|
async.parallel([ |
|
|
email: 'copayer' + (++i) + '@domain.com', |
|
|
|
|
|
language: 'en', |
|
|
function(done) { |
|
|
unit: 'bit', |
|
|
server.savePreferences({ |
|
|
}, next); |
|
|
email: 'copayer' + (++i) + '@domain.com', |
|
|
|
|
|
language: 'en', |
|
|
|
|
|
unit: 'bit', |
|
|
|
|
|
}, done); |
|
|
|
|
|
}, |
|
|
|
|
|
function(done) { |
|
|
|
|
|
server.pushNotificationsSubscribe({ |
|
|
|
|
|
token: '1234', |
|
|
|
|
|
packageName: 'com.wallet', |
|
|
|
|
|
platform: 'Android', |
|
|
|
|
|
}, done); |
|
|
|
|
|
}, |
|
|
|
|
|
], next); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
@ -59,8 +74,8 @@ describe('Push notifications', function() { |
|
|
defaultLanguage: 'en', |
|
|
defaultLanguage: 'en', |
|
|
defaultUnit: 'btc', |
|
|
defaultUnit: 'btc', |
|
|
subjectPrefix: '', |
|
|
subjectPrefix: '', |
|
|
|
|
|
pushServerUrl: 'http://localhost:8000', |
|
|
pushServerUrl: 'http://localhost:8000/send', |
|
|
authorizationKey: 'secret', |
|
|
}, |
|
|
}, |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
@ -93,8 +108,8 @@ describe('Push notifications', function() { |
|
|
return c.args[0]; |
|
|
return c.args[0]; |
|
|
}); |
|
|
}); |
|
|
calls.length.should.equal(1); |
|
|
calls.length.should.equal(1); |
|
|
args[0].body.android.data.title.should.contain('New payment received'); |
|
|
args[0].body.notification.title.should.contain('New payment received'); |
|
|
args[0].body.android.data.message.should.contain('123,000'); |
|
|
args[0].body.notification.body.should.contain('123,000'); |
|
|
done(); |
|
|
done(); |
|
|
}, 100); |
|
|
}, 100); |
|
|
}); |
|
|
}); |
|
@ -154,11 +169,24 @@ describe('Push notifications', function() { |
|
|
var i = 0; |
|
|
var i = 0; |
|
|
async.eachSeries(w.copayers, function(copayer, next) { |
|
|
async.eachSeries(w.copayers, function(copayer, next) { |
|
|
helpers.getAuthServer(copayer.id, function(server) { |
|
|
helpers.getAuthServer(copayer.id, function(server) { |
|
|
server.savePreferences({ |
|
|
async.parallel([ |
|
|
email: 'copayer' + (++i) + '@domain.com', |
|
|
|
|
|
language: 'en', |
|
|
function(done) { |
|
|
unit: 'bit', |
|
|
server.savePreferences({ |
|
|
}, next); |
|
|
email: 'copayer' + (++i) + '@domain.com', |
|
|
|
|
|
language: 'en', |
|
|
|
|
|
unit: 'bit', |
|
|
|
|
|
}, done); |
|
|
|
|
|
}, |
|
|
|
|
|
function(done) { |
|
|
|
|
|
server.pushNotificationsSubscribe({ |
|
|
|
|
|
token: '1234', |
|
|
|
|
|
packageName: 'com.wallet', |
|
|
|
|
|
platform: 'Android', |
|
|
|
|
|
}, done); |
|
|
|
|
|
}, |
|
|
|
|
|
], next); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
@ -177,8 +205,8 @@ describe('Push notifications', function() { |
|
|
defaultLanguage: 'en', |
|
|
defaultLanguage: 'en', |
|
|
defaultUnit: 'btc', |
|
|
defaultUnit: 'btc', |
|
|
subjectPrefix: '', |
|
|
subjectPrefix: '', |
|
|
|
|
|
pushServerUrl: 'http://localhost:8000', |
|
|
pushServerUrl: 'http://localhost:8000/send', |
|
|
authorizationKey: 'secret', |
|
|
}, |
|
|
}, |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
@ -214,14 +242,14 @@ describe('Push notifications', function() { |
|
|
|
|
|
|
|
|
calls.length.should.equal(3); |
|
|
calls.length.should.equal(3); |
|
|
|
|
|
|
|
|
args[0].body.android.data.title.should.contain('Nuevo pago recibido'); |
|
|
args[0].body.notification.title.should.contain('Nuevo pago recibido'); |
|
|
args[0].body.android.data.message.should.contain('0.123'); |
|
|
args[0].body.notification.body.should.contain('0.123'); |
|
|
|
|
|
|
|
|
args[1].body.android.data.title.should.contain('New payment received'); |
|
|
args[1].body.notification.title.should.contain('New payment received'); |
|
|
args[1].body.android.data.message.should.contain('123,000'); |
|
|
args[1].body.notification.body.should.contain('123,000'); |
|
|
|
|
|
|
|
|
args[2].body.android.data.title.should.contain('New payment received'); |
|
|
args[2].body.notification.title.should.contain('New payment received'); |
|
|
args[2].body.android.data.message.should.contain('123,000'); |
|
|
args[2].body.notification.body.should.contain('123,000'); |
|
|
done(); |
|
|
done(); |
|
|
}, 100); |
|
|
}, 100); |
|
|
}); |
|
|
}); |
|
@ -333,9 +361,7 @@ describe('Push notifications', function() { |
|
|
return c.args[0]; |
|
|
return c.args[0]; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
args[0].body.android.data.title.should.contain('Payment proposal rejected'); |
|
|
args[0].body.notification.title.should.contain('Payment proposal rejected'); |
|
|
args[0].body.android.data.message.should.contain('copayer 2, copayer 3'); |
|
|
|
|
|
args[0].body.android.data.message.should.not.contain('copayer 1'); |
|
|
|
|
|
done(); |
|
|
done(); |
|
|
}, 100); |
|
|
}, 100); |
|
|
}); |
|
|
}); |
|
@ -392,11 +418,11 @@ describe('Push notifications', function() { |
|
|
return c.args[0]; |
|
|
return c.args[0]; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
args[0].body.android.data.title.should.contain('Payment sent'); |
|
|
args[0].body.notification.title.should.contain('Payment sent'); |
|
|
args[1].body.android.data.title.should.contain('Payment sent'); |
|
|
args[1].body.notification.title.should.contain('Payment sent'); |
|
|
|
|
|
|
|
|
server.copayerId.should.not.equal((args[0].body.users[0]).split('$')[1]); |
|
|
sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(server.copayerId)).should.not.equal(args[0].body.data.copayerId); |
|
|
server.copayerId.should.not.equal((args[1].body.users[0]).split('$')[1]); |
|
|
sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(server.copayerId)).should.not.equal(args[1].body.data.copayerId); |
|
|
done(); |
|
|
done(); |
|
|
}, 100); |
|
|
}, 100); |
|
|
}); |
|
|
}); |
|
@ -432,7 +458,8 @@ describe('Push notifications', function() { |
|
|
defaultLanguage: 'en', |
|
|
defaultLanguage: 'en', |
|
|
defaultUnit: 'btc', |
|
|
defaultUnit: 'btc', |
|
|
subjectPrefix: '', |
|
|
subjectPrefix: '', |
|
|
pushServerUrl: 'http://localhost:8000/send', |
|
|
pushServerUrl: 'http://localhost:8000', |
|
|
|
|
|
authorizationKey: 'secret', |
|
|
}, |
|
|
}, |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
@ -452,44 +479,54 @@ describe('Push notifications', function() { |
|
|
customData: 'custom data ' + (i + 1), |
|
|
customData: 'custom data ' + (i + 1), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, next); |
|
|
server.joinWallet(copayerOpts, function(err, res) { |
|
|
|
|
|
if (err) return next(err); |
|
|
|
|
|
|
|
|
|
|
|
helpers.getAuthServer(res.copayerId, function(server) { |
|
|
|
|
|
server.pushNotificationsSubscribe({ |
|
|
|
|
|
token: 'token:' + copayerOpts.name, |
|
|
|
|
|
packageName: 'com.wallet', |
|
|
|
|
|
platform: 'Android', |
|
|
|
|
|
}, next); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
should.not.exist(err); |
|
|
should.not.exist(err); |
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
var calls = requestStub.getCalls(); |
|
|
var calls = requestStub.getCalls(); |
|
|
var args = _.map(calls, function(c) { |
|
|
var args = _.filter(_.map(calls, function(call) { |
|
|
return c.args[0]; |
|
|
return call.args[0]; |
|
|
|
|
|
}), function(arg) { |
|
|
|
|
|
return arg.body.notification.title == 'New copayer'; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
var argu = _.compact(_.map(args, function(a) { |
|
|
server.getWallet(null, function(err, wallet) { |
|
|
if (a.body.android.data.title == 'New copayer') |
|
|
|
|
|
return a; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
server.getWallet(null, function(err, w) { |
|
|
|
|
|
/* |
|
|
/* |
|
|
First call - copayer2 joined |
|
|
First call - copayer2 joined |
|
|
copayer2 should notify to copayer1 |
|
|
copayer2 should notify to copayer1 |
|
|
copayer2 should NOT be notifyed |
|
|
copayer2 should NOT be notifyed |
|
|
*/ |
|
|
*/ |
|
|
w.copayers[0].id.should.contain((argu[0].body.users[0]).split('$')[1]); |
|
|
var hashedCopayerIds = _.map(wallet.copayers, function(copayer) { |
|
|
w.copayers[1].id.should.not.contain((argu[0].body.users[0]).split('$')[1]); |
|
|
return sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(copayer.id)); |
|
|
|
|
|
}); |
|
|
|
|
|
hashedCopayerIds[0].should.equal((args[0].body.data.copayerId)); |
|
|
|
|
|
hashedCopayerIds[1].should.not.equal((args[0].body.data.copayerId)); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
Second call - copayer3 joined |
|
|
Second call - copayer3 joined |
|
|
copayer3 should notify to copayer1 |
|
|
copayer3 should notify to copayer1 |
|
|
*/ |
|
|
*/ |
|
|
w.copayers[0].id.should.contain((argu[1].body.users[0]).split('$')[1]); |
|
|
hashedCopayerIds[0].should.equal((args[1].body.data.copayerId)); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
Third call - copayer3 joined |
|
|
Third call - copayer3 joined |
|
|
copayer3 should notify to copayer2 |
|
|
copayer3 should notify to copayer2 |
|
|
*/ |
|
|
*/ |
|
|
w.copayers[1].id.should.contain((argu[2].body.users[0]).split('$')[1]); |
|
|
hashedCopayerIds[1].should.equal((args[2].body.data.copayerId)); |
|
|
|
|
|
|
|
|
// copayer3 should NOT notify any other copayer
|
|
|
// copayer3 should NOT notify any other copayer
|
|
|
w.copayers[2].id.should.not.contain((argu[1].body.users[0]).split('$')[1]); |
|
|
hashedCopayerIds[2].should.not.equal((args[1].body.data.copayerId)); |
|
|
w.copayers[2].id.should.not.contain((argu[2].body.users[0]).split('$')[1]); |
|
|
hashedCopayerIds[2].should.not.equal((args[2].body.data.copayerId)); |
|
|
done(); |
|
|
done(); |
|
|
}); |
|
|
}); |
|
|
}, 100); |
|
|
}, 100); |
|
|