add join test

This commit is contained in:
Gabriel Bazán 2016-01-12 15:19:29 -03:00
parent 925e83b74a
commit f6aef2de7c
1 changed files with 88 additions and 61 deletions

View File

@ -17,7 +17,7 @@ var TestData = require('../testdata');
var helpers = require('./helpers'); var helpers = require('./helpers');
describe('Push notifications', function() { describe('Push notifications', function() {
var server, wallet, requestStub, pushNotificationsService; var server, wallet, requestStub, pushNotificationsService, walletId;
before(function(done) { before(function(done) {
helpers.before(done); helpers.before(done);
@ -151,7 +151,6 @@ describe('Push notifications', function() {
helpers.createAndJoinWallet(2, 3, function(s, w) { helpers.createAndJoinWallet(2, 3, function(s, w) {
server = s; server = s;
wallet = w; wallet = w;
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) {
@ -269,8 +268,6 @@ describe('Push notifications', function() {
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, TestData.copayers[0].privKey_1H_0, { var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, TestData.copayers[0].privKey_1H_0, {
message: 'some message' message: 'some message'
}); });
// server.createTxLegacy(txOpts, function(err, tx) {
// should.not.exist(err);
server.createAddress({}, function(err, address) { server.createAddress({}, function(err, address) {
should.not.exist(err); should.not.exist(err);
server._notify('NewTxProposal', { server._notify('NewTxProposal', {
@ -289,7 +286,6 @@ describe('Push notifications', function() {
}); });
}); });
}); });
// });
}); });
it('should notify copayers a tx has been finally rejected', function(done) { it('should notify copayers a tx has been finally rejected', function(done) {
@ -332,71 +328,102 @@ describe('Push notifications', function() {
}); });
}); });
}); });
});
it('should notify copayers when a new copayer just joined into your wallet ', function(done) { describe('joinWallet', function() {
helpers.stubUtxos(server, wallet, 1, function() { beforeEach(function(done) {
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, TestData.copayers[0].privKey_1H_0, { helpers.beforeEach(function(res) {
message: 'some message' server = new WalletService();
}); var walletOpts = {
name: 'my wallet',
var txpId; m: 1,
async.waterfall([ n: 3,
pubKey: TestData.keyPair.pub,
function(next) { };
server.createTxLegacy(txOpts, next); server.createWallet(walletOpts, function(err, wId) {
},
function(txp, next) {
txpId = txp.id;
async.eachSeries(_.range(1, 3), function(i, next) {
var copayer = TestData.copayers[i];
helpers.getAuthServer(copayer.id44, function(server) {
server.rejectTx({
txProposalId: txp.id,
}, next);
});
}, next);
},
], function(err) {
should.not.exist(err); should.not.exist(err);
walletId = wId;
should.exist(walletId);
requestStub = sinon.stub();
requestStub.yields();
setTimeout(function() { pushNotificationsService = new PushNotificationsService();
var calls = requestStub.getCalls(); pushNotificationsService.start({
var args = _.map(_.takeRight(calls, 2), function(c) { lockOpts: {},
return c.args[0]; messageBroker: server.messageBroker,
}); storage: helpers.getStorage(),
request: requestStub,
args[0].body.android.data.title.should.contain('Payment proposal rejected'); pushNotificationsOpts: {
args[0].body.android.data.message.should.contain('copayer 2, copayer 3'); templatePath: './lib/templates',
args[0].body.android.data.message.should.not.contain('copayer 1'); defaultLanguage: 'en',
defaultUnit: 'btc',
subjectPrefix: '',
publicTxUrlTemplate: {
livenet: 'https://insight.bitpay.com/tx/{{txid}}',
testnet: 'https://test-insight.bitpay.com/tx/{{txid}}',
},
pushServerUrl: 'http://192.168.1.111:8000/send',
},
}, function(err) {
should.not.exist(err);
done(); done();
}, 100); });
}); });
}); });
}); });
it.only('should notify copayers when a new copayer just joined into your wallet except the one who joined', function(done) {
async.eachSeries(_.range(3), function(i, next) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'copayer ' + (i + 1),
xPubKey: TestData.copayers[i].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[i].pubKey_1H_0,
customData: 'custom data ' + (i + 1),
});
// it('should join existing wallet', function(done) { server.joinWallet(copayerOpts, next);
// var copayerOpts = helpers.getSignedCopayerOpts({ }, function(err) {
// walletId: walletId, should.not.exist(err);
// name: 'me', setTimeout(function() {
// xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H, var calls = requestStub.getCalls();
// requestPubKey: TestData.copayers[0].pubKey_1H_0, var args = _.map(calls, function(c) {
// customData: 'dummy custom data', return c.args[0];
// }); });
// server.joinWallet(copayerOpts, function(err, result) {
// should.not.exist(err);
// setTimeout(function() {
// var calls = requestStub.getCalls();
// var args = _.map(_.takeRight(calls, 2), function(c) {
// return c.args[0];
// });
// console.log(args);
// done(); var argu = _.compact(_.map(args, function(a) {
// }, 100); if (a.body.android.data.title == 'New copayer')
// }); return a;
// }); }));
server.getWallet(null, function(err, w) {
/*
First call - copayer2 joined
copayer2 should notify to copayer1
copayer2 should NOT be notifyed
*/
w.copayers[0].id.should.contain((argu[0].body.users[0]).split('$')[1]);
w.copayers[1].id.should.not.contain((argu[0].body.users[0]).split('$')[1]);
/*
Second call - copayer3 joined
copayer3 should notify to copayer1
*/
w.copayers[0].id.should.contain((argu[1].body.users[0]).split('$')[1]);
/*
Third call - copayer3 joined
copayer3 should notify to copayer2
*/
w.copayers[1].id.should.contain((argu[2].body.users[0]).split('$')[1]);
// copayer3 should NOT notify any other copayer
w.copayers[2].id.should.not.contain((argu[1].body.users[0]).split('$')[1]);
w.copayers[2].id.should.not.contain((argu[2].body.users[0]).split('$')[1]);
done();
});
}, 100);
});
});
}); });
}); });