diff --git a/test/mocks/FakePayProServer.js b/test/mocks/FakePayProServer.js index 5837af4bb..eaf611168 100644 --- a/test/mocks/FakePayProServer.js +++ b/test/mocks/FakePayProServer.js @@ -93,13 +93,18 @@ x509.der = new Buffer(x509.der, 'base64'); x509.pem = new Buffer(x509.pem, 'base64'); function startServer(cb) { - if (G.$http.__server) { + if (G.$http && G.$http.__server) { setTimeout(function() { return cb(null, G.$http.__server); }, 1); return; } + var old; + if (G.$http) { + old = G.$http; + } + var server = { POST: { @@ -271,9 +276,12 @@ function startServer(cb) { return cb(null, res, res.body); } }, - listen: function() { + listen: function(port, cb) { + if (cb) return cb(); }, - close: function() { + close: function(cb) { + if (old) G.$http = old; + return cb(); } }; diff --git a/test/test.PayPro.js b/test/test.PayPro.js index cdf337f85..eb819bff2 100644 --- a/test/test.PayPro.js +++ b/test/test.PayPro.js @@ -168,8 +168,9 @@ describe('PayPro (in Wallet) model', function() { should.exist(ntxid); console.log('Sent TX proposal to other copayers:'); console.log([ntxid, ca]); - server.close(); - done(); + server.close(function() { + done(); + }); } else { console.log('Sending TX to merchant server:'); console.log(ntxid); @@ -177,8 +178,9 @@ describe('PayPro (in Wallet) model', function() { should.exist(txid); console.log('TX sent:'); console.log([ntxid, ca]); - server.close(); - done(); + server.close(function() { + done(); + }); }); } }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 10c9891d9..018c8e171 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -10,6 +10,7 @@ saveAs = function(o) { saveAsLastCall = o; }; +var startServer = require('../../mocks/FakePayProServer'); describe("Unit: Controllers", function() { var invalidForm = { @@ -18,6 +19,8 @@ describe("Unit: Controllers", function() { var scope; + var server; + beforeEach(module('copayApp.services')); beforeEach(module('copayApp.controllers')); @@ -217,6 +220,15 @@ describe("Unit: Controllers", function() { sinon.assert.callCount(scope.loadTxs, 1); }); + it('#start the example server', function(done) { + startServer(function(err, s) { + if (err) return done(err); + server = s; + server.uri = 'https://localhost:8080/-'; + done(); + }); + }); + it('should create a payment protocol transaction proposal', function() { var uri = 'bitcoin:1JqniWpWNA6Yvdivg3y9izLidETnurxRQm?amount=0.00001000&r=https://localhost:8080/-/request'; sendForm.address.$setViewValue(uri); @@ -243,6 +255,12 @@ describe("Unit: Controllers", function() { sinon.assert.callCount(spy, 1); sinon.assert.callCount(spy2, 1); }); + + it('#stop the example server', function(done) { + server.close(function() { + done(); + }); + }); }); describe("Unit: Version Controller", function() {