2014-04-23 09:21:33 -07:00
|
|
|
//
|
|
|
|
// test/unit/controllers/controllersSpec.js
|
|
|
|
//
|
2014-06-16 13:37:33 -07:00
|
|
|
|
2014-06-24 11:46:07 -07:00
|
|
|
var sinon = require('sinon');
|
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
// Replace saveAs plugin
|
2014-09-12 06:40:47 -07:00
|
|
|
saveAs = function(blob, filename) {
|
|
|
|
saveAsLastCall = {
|
|
|
|
blob: blob,
|
|
|
|
filename: filename
|
|
|
|
};
|
2014-06-16 13:37:33 -07:00
|
|
|
};
|
|
|
|
|
2014-07-29 17:44:10 -07:00
|
|
|
var startServer = require('../../mocks/FakePayProServer');
|
2014-06-16 13:37:33 -07:00
|
|
|
|
2014-06-04 19:11:18 -07:00
|
|
|
describe("Unit: Controllers", function() {
|
2014-10-29 14:34:59 -07:00
|
|
|
config.plugins.LocalStorage = true;
|
|
|
|
config.plugins.GoogleDrive = null;
|
2014-09-18 15:34:27 -07:00
|
|
|
|
2014-06-26 14:37:30 -07:00
|
|
|
var invalidForm = {
|
|
|
|
$invalid: true
|
|
|
|
};
|
2014-04-23 09:21:33 -07:00
|
|
|
|
2014-06-04 07:24:49 -07:00
|
|
|
var scope;
|
2014-07-29 17:44:10 -07:00
|
|
|
var server;
|
|
|
|
|
2014-10-29 18:54:48 -07:00
|
|
|
beforeEach(module('copayApp'));
|
|
|
|
beforeEach(module('copayApp.controllers'));
|
|
|
|
beforeEach(module(function($provide) {
|
|
|
|
$provide.value('request', {
|
|
|
|
'get': function(_, cb) {
|
|
|
|
cb(null, null, [{
|
2014-10-29 14:34:59 -07:00
|
|
|
name: 'USD Dollars',
|
|
|
|
code: 'USD',
|
|
|
|
rate: 2
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
$rootScope.iden = sinon.stub();
|
2014-11-03 12:28:36 -08:00
|
|
|
$rootScope.safeUnspentCount = 1;
|
2014-10-29 14:34:59 -07:00
|
|
|
|
|
|
|
var w = {};
|
|
|
|
w.isReady = sinon.stub().returns(true);
|
|
|
|
w.privateKey = {};
|
|
|
|
w.settings = {
|
|
|
|
unitToSatoshi: 100,
|
|
|
|
unitDecimals: 2,
|
|
|
|
alternativeName: 'US Dollar',
|
|
|
|
alternativeIsoCode: 'USD',
|
|
|
|
};
|
|
|
|
w.addressBook = {
|
|
|
|
'juan': '1',
|
|
|
|
};
|
|
|
|
w.totalCopayers = 2;
|
|
|
|
w.getMyCopayerNickname = sinon.stub().returns('nickname');
|
|
|
|
w.getMyCopayerId = sinon.stub().returns('id');
|
|
|
|
w.privateKey.toObj = sinon.stub().returns({
|
|
|
|
wallet: 'mock'
|
|
|
|
});
|
|
|
|
w.getSecret = sinon.stub().returns('secret');
|
|
|
|
w.getName = sinon.stub().returns('fakeWallet');
|
|
|
|
w.exportEncrypted = sinon.stub().returns('1234567');
|
2014-10-30 12:20:25 -07:00
|
|
|
w.getTransactionHistory = sinon.stub().yields(null);
|
2014-10-29 14:34:59 -07:00
|
|
|
w.getNetworkName = sinon.stub().returns('testnet');
|
|
|
|
|
|
|
|
w.createTx = sinon.stub().yields(null);
|
|
|
|
w.sendTx = sinon.stub().yields(null);
|
|
|
|
w.requiresMultipleSignatures = sinon.stub().returns(true);
|
|
|
|
w.getTxProposals = sinon.stub().returns([1,2,3]);
|
|
|
|
|
|
|
|
|
|
|
|
$rootScope.wallet = w;
|
|
|
|
}));
|
2014-09-18 15:34:27 -07:00
|
|
|
|
2014-09-09 08:59:48 -07:00
|
|
|
describe('More Controller', function() {
|
2014-06-16 13:37:33 -07:00
|
|
|
var ctrl;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
2014-08-21 08:04:19 -07:00
|
|
|
ctrl = $controller('MoreController', {
|
2014-06-16 13:37:33 -07:00
|
|
|
$scope: scope,
|
|
|
|
$modal: {},
|
|
|
|
});
|
2014-09-12 06:40:47 -07:00
|
|
|
saveAsLastCall = null;
|
2014-06-16 13:37:33 -07:00
|
|
|
}));
|
|
|
|
|
2014-06-17 19:16:15 -07:00
|
|
|
it('Backup controller #download', function() {
|
2014-06-16 13:37:33 -07:00
|
|
|
expect(saveAsLastCall).equal(null);
|
2014-07-16 15:00:34 -07:00
|
|
|
scope.downloadBackup();
|
2014-09-12 06:40:47 -07:00
|
|
|
expect(saveAsLastCall.blob.size).equal(7);
|
|
|
|
expect(saveAsLastCall.blob.type).equal('text/plain;charset=utf-8');
|
|
|
|
});
|
|
|
|
|
2014-09-12 07:10:45 -07:00
|
|
|
it('Backup controller should name backup correctly for multiple copayers', function() {
|
2014-09-12 06:40:47 -07:00
|
|
|
expect(saveAsLastCall).equal(null);
|
|
|
|
scope.downloadBackup();
|
2014-10-29 14:34:59 -07:00
|
|
|
expect(saveAsLastCall.filename).equal('nickname-fakeWallet-keybackup.json.aes');
|
2014-06-16 13:37:33 -07:00
|
|
|
});
|
|
|
|
|
2014-09-12 07:10:45 -07:00
|
|
|
it('Backup controller should name backup correctly for 1-1 wallet', function() {
|
|
|
|
expect(saveAsLastCall).equal(null);
|
|
|
|
scope.wallet.totalCopayers = 1;
|
|
|
|
scope.downloadBackup();
|
2014-10-29 14:34:59 -07:00
|
|
|
expect(saveAsLastCall.filename).equal('fakeWallet-keybackup.json.aes');
|
2014-09-12 07:10:45 -07:00
|
|
|
});
|
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
});
|
|
|
|
|
2014-08-29 09:20:47 -07:00
|
|
|
describe('Create Controller', function() {
|
|
|
|
var c;
|
2014-06-23 15:45:04 -07:00
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
2014-08-29 09:20:47 -07:00
|
|
|
c = $controller('CreateController', {
|
2014-06-23 15:45:04 -07:00
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2014-06-23 16:31:17 -07:00
|
|
|
describe('#getNumber', function() {
|
|
|
|
it('should return an array of n undefined elements', function() {
|
|
|
|
var n = 5;
|
|
|
|
var array = scope.getNumber(n);
|
|
|
|
expect(array.length).equal(n);
|
|
|
|
});
|
2014-06-23 15:45:04 -07:00
|
|
|
});
|
2014-06-26 14:22:32 -07:00
|
|
|
describe('#create', function() {
|
|
|
|
it('should work with invalid form', function() {
|
2014-06-26 14:37:30 -07:00
|
|
|
scope.create(invalidForm);
|
2014-06-26 14:22:32 -07:00
|
|
|
});
|
|
|
|
});
|
2014-06-23 15:45:04 -07:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-10-30 10:13:40 -07:00
|
|
|
describe('Receive Controller', function() {
|
|
|
|
var c;
|
2014-06-03 13:42:36 -07:00
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
2014-10-30 10:13:40 -07:00
|
|
|
c = $controller('ReceiveController', {
|
2014-06-03 13:42:36 -07:00
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2014-10-30 10:13:40 -07:00
|
|
|
it('should have a ReceiveController controller', function() {
|
2014-06-04 07:24:49 -07:00
|
|
|
expect(scope.loading).equal(false);
|
|
|
|
});
|
|
|
|
});
|
2014-06-03 13:42:36 -07:00
|
|
|
|
2014-10-30 10:13:40 -07:00
|
|
|
describe('History Controller', function() {
|
2014-10-30 12:20:25 -07:00
|
|
|
var ctrl;
|
2014-06-04 07:24:49 -07:00
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
2014-10-30 12:20:25 -07:00
|
|
|
|
2014-06-04 07:24:49 -07:00
|
|
|
scope = $rootScope.$new();
|
2014-10-30 12:20:25 -07:00
|
|
|
scope.wallet = null;
|
|
|
|
scope.getTransactions = sinon.stub();
|
|
|
|
ctrl = $controller('HistoryController', {
|
2014-06-04 07:24:49 -07:00
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2014-09-25 12:50:15 -07:00
|
|
|
it('should exist', function() {
|
2014-10-30 12:20:25 -07:00
|
|
|
should.exist(ctrl);
|
2014-09-25 12:50:15 -07:00
|
|
|
});
|
|
|
|
|
2014-10-30 12:20:25 -07:00
|
|
|
it('should have a HistoryController controller', function() {
|
2014-06-04 07:24:49 -07:00
|
|
|
expect(scope.loading).equal(false);
|
|
|
|
});
|
|
|
|
|
2014-10-29 14:34:59 -07:00
|
|
|
// this tests has no sense: getTransaction is async
|
|
|
|
it.skip('should return an empty array of tx from insight', function() {
|
2014-06-04 07:24:49 -07:00
|
|
|
scope.getTransactions();
|
|
|
|
expect(scope.blockchain_txs).to.be.empty;
|
|
|
|
});
|
2014-09-25 12:50:15 -07:00
|
|
|
|
|
|
|
it('should call amountAlternative and return a value', function() {
|
|
|
|
var cb = sinon.spy();
|
|
|
|
var s1 = sinon.stub(scope, 'amountAlternative');
|
|
|
|
s1.onCall(0).returns(1000);
|
|
|
|
s1.onCall(1).returns(2000);
|
|
|
|
expect(s1(100, 0, cb)).equal(1000);
|
|
|
|
expect(s1(200, 1, cb)).equal(2000);
|
|
|
|
sinon.assert.callCount(scope.amountAlternative, 2);
|
|
|
|
s1.restore();
|
|
|
|
});
|
2014-06-04 07:24:49 -07:00
|
|
|
});
|
2014-06-04 19:11:18 -07:00
|
|
|
|
2014-06-19 10:21:38 -07:00
|
|
|
describe('Send Controller', function() {
|
2014-08-28 17:06:49 -07:00
|
|
|
var scope, form, sendForm, sendCtrl;
|
2014-10-29 14:34:59 -07:00
|
|
|
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller, rateService, notification) {
|
2014-06-19 10:21:38 -07:00
|
|
|
scope = $rootScope.$new();
|
2014-08-29 09:36:38 -07:00
|
|
|
scope.rateService = rateService;
|
2014-06-19 10:21:38 -07:00
|
|
|
var element = angular.element(
|
|
|
|
'<form name="form">' +
|
|
|
|
'<input type="text" id="newaddress" name="newaddress" ng-disabled="loading" placeholder="Address" ng-model="newaddress" valid-address required>' +
|
|
|
|
'<input type="text" id="newlabel" name="newlabel" ng-disabled="loading" placeholder="Label" ng-model="newlabel" required>' +
|
|
|
|
'</form>'
|
|
|
|
);
|
|
|
|
scope.model = {
|
|
|
|
newaddress: null,
|
2014-06-23 05:31:41 -07:00
|
|
|
newlabel: null,
|
2014-06-24 11:46:07 -07:00
|
|
|
address: null,
|
|
|
|
amount: null
|
2014-06-19 10:21:38 -07:00
|
|
|
};
|
|
|
|
$compile(element)(scope);
|
2014-06-24 11:46:07 -07:00
|
|
|
|
|
|
|
var element2 = angular.element(
|
|
|
|
'<form name="form2">' +
|
|
|
|
'<input type="text" id="address" name="address" ng-model="address" valid-address required>' +
|
|
|
|
'<input type="number" id="amount" name="amount" ng-model="amount" min="1" max="10000000000" required>' +
|
2014-08-28 17:06:49 -07:00
|
|
|
'<input type="number" id="alternative" name="alternative" ng-model="alternative">' +
|
2014-06-24 11:46:07 -07:00
|
|
|
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
|
|
|
'</form>'
|
|
|
|
);
|
|
|
|
$compile(element2)(scope);
|
2014-08-28 17:06:49 -07:00
|
|
|
sendCtrl = $controller('SendController', {
|
2014-06-24 08:36:32 -07:00
|
|
|
$scope: scope,
|
2014-06-23 05:31:41 -07:00
|
|
|
$modal: {},
|
|
|
|
});
|
2014-06-24 11:46:07 -07:00
|
|
|
|
2014-06-19 10:21:38 -07:00
|
|
|
scope.$digest();
|
|
|
|
form = scope.form;
|
2014-06-24 11:46:07 -07:00
|
|
|
sendForm = scope.form2;
|
2014-08-11 16:29:44 -07:00
|
|
|
scope.sendForm = sendForm;
|
2014-06-19 10:21:38 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should have a SendController controller', function() {
|
|
|
|
expect(scope.loading).equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a title', function() {
|
|
|
|
expect(scope.title).equal('Send');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return true if wallet has addressBook', function() {
|
|
|
|
expect(scope.showAddressBook()).equal(true);
|
|
|
|
});
|
|
|
|
|
2014-07-04 08:51:27 -07:00
|
|
|
it('should validate address with network', function() {
|
2014-08-19 13:08:06 -07:00
|
|
|
form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
2014-06-19 10:21:38 -07:00
|
|
|
expect(form.newaddress.$invalid).to.equal(false);
|
|
|
|
});
|
|
|
|
|
2014-07-04 08:51:27 -07:00
|
|
|
it('should not validate address with other network', function() {
|
2014-08-19 13:08:06 -07:00
|
|
|
form.newaddress.$setViewValue('1JqniWpWNA6Yvdivg3y9izLidETnurxRQm');
|
2014-07-04 08:51:27 -07:00
|
|
|
expect(form.newaddress.$invalid).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not validate random address', function() {
|
2014-06-19 10:21:38 -07:00
|
|
|
form.newaddress.$setViewValue('thisisaninvalidaddress');
|
|
|
|
expect(form.newaddress.$invalid).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate label', function() {
|
|
|
|
form.newlabel.$setViewValue('John');
|
|
|
|
expect(form.newlabel.$invalid).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not validate label', function() {
|
|
|
|
expect(form.newlabel.$invalid).to.equal(true);
|
|
|
|
});
|
|
|
|
|
2014-08-22 19:05:08 -07:00
|
|
|
it('should create a transaction proposal with given values', function() {
|
2014-08-19 13:08:06 -07:00
|
|
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
2014-06-24 11:46:07 -07:00
|
|
|
sendForm.amount.$setViewValue(1000);
|
|
|
|
|
2014-08-06 09:59:33 -07:00
|
|
|
scope.loadTxs = sinon.spy();
|
|
|
|
|
2014-10-29 14:34:59 -07:00
|
|
|
var w = scope.wallet;
|
2014-06-24 11:46:07 -07:00
|
|
|
scope.submitForm(sendForm);
|
2014-10-29 14:34:59 -07:00
|
|
|
sinon.assert.callCount(w.createTx, 1);
|
|
|
|
sinon.assert.callCount(w.sendTx, 0);
|
2014-08-06 09:59:33 -07:00
|
|
|
sinon.assert.callCount(scope.loadTxs, 1);
|
2014-10-29 14:34:59 -07:00
|
|
|
w.createTx.getCall(0).args[0].should.equal('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
|
|
|
w.createTx.getCall(0).args[1].should.equal(1000 * scope.wallet.settings.unitToSatoshi);
|
|
|
|
(typeof w.createTx.getCall(0).args[2]).should.equal('undefined');
|
2014-06-24 11:46:07 -07:00
|
|
|
});
|
|
|
|
|
2014-08-22 19:05:08 -07:00
|
|
|
|
|
|
|
it('should handle big values in 100 BTC', function() {
|
2014-09-05 16:09:20 -07:00
|
|
|
var old = scope.wallet.settings.unitToSatoshi;
|
|
|
|
scope.wallet.settings.unitToSatoshi = 100000000;;
|
2014-08-25 09:49:26 -07:00
|
|
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
2014-08-22 19:05:08 -07:00
|
|
|
sendForm.amount.$setViewValue(100);
|
|
|
|
scope.loadTxs = sinon.spy();
|
|
|
|
scope.submitForm(sendForm);
|
2014-10-29 14:34:59 -07:00
|
|
|
var w = scope.wallet;
|
|
|
|
w.createTx.getCall(0).args[1].should.equal(100 * scope.wallet.settings.unitToSatoshi);
|
2014-09-05 16:09:20 -07:00
|
|
|
scope.wallet.settings.unitToSatoshi = old;
|
2014-08-22 19:05:08 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-09-05 16:09:20 -07:00
|
|
|
it('should handle big values in 5000 BTC', inject(function($rootScope) {
|
2014-10-29 14:34:59 -07:00
|
|
|
var w = scope.wallet;
|
|
|
|
w.requiresMultipleSignatures = sinon.stub().returns(true);
|
|
|
|
|
|
|
|
|
2014-09-05 16:09:20 -07:00
|
|
|
var old = $rootScope.wallet.settings.unitToSatoshi;
|
|
|
|
$rootScope.wallet.settings.unitToSatoshi = 100000000;;
|
2014-08-25 09:49:26 -07:00
|
|
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
2014-08-22 19:05:08 -07:00
|
|
|
sendForm.amount.$setViewValue(5000);
|
|
|
|
scope.submitForm(sendForm);
|
2014-10-29 14:34:59 -07:00
|
|
|
|
|
|
|
w.createTx.getCall(0).args[1].should.equal(5000 * $rootScope.wallet.settings.unitToSatoshi);
|
2014-09-05 16:09:20 -07:00
|
|
|
$rootScope.wallet.settings.unitToSatoshi = old;
|
|
|
|
}));
|
2014-08-22 19:05:08 -07:00
|
|
|
|
2014-08-28 17:06:49 -07:00
|
|
|
it('should convert bits amount to fiat', function(done) {
|
2014-08-29 09:36:38 -07:00
|
|
|
scope.rateService.whenAvailable(function() {
|
2014-08-28 17:06:49 -07:00
|
|
|
sendForm.amount.$setViewValue(1e6);
|
|
|
|
scope.$digest();
|
|
|
|
expect(scope.alternative).to.equal(2);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should convert fiat to bits amount', function(done) {
|
2014-08-29 09:36:38 -07:00
|
|
|
scope.rateService.whenAvailable(function() {
|
2014-08-28 17:06:49 -07:00
|
|
|
sendForm.alternative.$setViewValue(2);
|
|
|
|
scope.$digest();
|
|
|
|
expect(scope.amount).to.equal(1e6);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-08-22 19:05:08 -07:00
|
|
|
|
2014-06-24 11:46:07 -07:00
|
|
|
it('should create and send a transaction proposal', function() {
|
2014-08-19 13:08:06 -07:00
|
|
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
2014-06-24 11:46:07 -07:00
|
|
|
sendForm.amount.$setViewValue(1000);
|
2014-08-06 09:59:33 -07:00
|
|
|
scope.loadTxs = sinon.spy();
|
2014-06-24 11:46:07 -07:00
|
|
|
|
2014-10-29 14:34:59 -07:00
|
|
|
var w = scope.wallet;
|
|
|
|
w.requiresMultipleSignatures = sinon.stub().returns(false);
|
|
|
|
w.totalCopayers = w.requiredCopayers = 1;
|
|
|
|
|
|
|
|
|
2014-06-24 11:46:07 -07:00
|
|
|
scope.submitForm(sendForm);
|
2014-10-29 14:34:59 -07:00
|
|
|
sinon.assert.callCount(w.createTx, 1);
|
|
|
|
sinon.assert.callCount(w.sendTx, 1);
|
2014-08-07 06:20:24 -07:00
|
|
|
sinon.assert.callCount(scope.loadTxs, 1);
|
2014-06-24 11:46:07 -07:00
|
|
|
});
|
|
|
|
|
2014-09-08 12:37:33 -07:00
|
|
|
it('should not send txp when there is an error at creation', function() {
|
|
|
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
|
|
|
sendForm.amount.$setViewValue(1000);
|
|
|
|
scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1;
|
|
|
|
scope.loadTxs = sinon.spy();
|
2014-10-29 14:34:59 -07:00
|
|
|
var w = scope.wallet;
|
|
|
|
w.createTx.yields('error');
|
|
|
|
w.isShared = sinon.stub().returns(false);
|
|
|
|
|
2014-09-08 12:37:33 -07:00
|
|
|
|
|
|
|
scope.submitForm(sendForm);
|
2014-10-29 14:34:59 -07:00
|
|
|
|
|
|
|
sinon.assert.callCount(w.createTx, 1);
|
|
|
|
sinon.assert.callCount(w.sendTx, 0);
|
2014-09-08 12:37:33 -07:00
|
|
|
sinon.assert.callCount(scope.loadTxs, 1);
|
|
|
|
});
|
2014-06-19 10:21:38 -07:00
|
|
|
});
|
|
|
|
|
2014-08-05 07:53:58 -07:00
|
|
|
describe("Unit: Version Controller", function() {
|
2014-06-04 19:11:18 -07:00
|
|
|
var scope, $httpBackendOut;
|
|
|
|
var GH = 'https://api.github.com/repos/bitpay/copay/tags';
|
|
|
|
beforeEach(inject(function($controller, $injector) {
|
|
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
|
|
$httpBackend.when('GET', GH)
|
2014-09-05 16:19:49 -07:00
|
|
|
.respond([{
|
|
|
|
name: "v100.1.6",
|
|
|
|
zipball_url: "https://api.github.com/repos/bitpay/copay/zipball/v0.0.6",
|
|
|
|
tarball_url: "https://api.github.com/repos/bitpay/copay/tarball/v0.0.6",
|
|
|
|
commit: {
|
|
|
|
sha: "ead7352bf2eca705de58d8b2f46650691f2bc2c7",
|
|
|
|
url: "https://api.github.com/repos/bitpay/copay/commits/ead7352bf2eca705de58d8b2f46650691f2bc2c7"
|
|
|
|
}
|
|
|
|
}]);
|
2014-06-04 19:11:18 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
var rootScope;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
rootScope = $rootScope;
|
|
|
|
scope = $rootScope.$new();
|
2014-08-05 07:53:58 -07:00
|
|
|
headerCtrl = $controller('VersionController', {
|
2014-06-04 19:11:18 -07:00
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
$httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
$httpBackend.verifyNoOutstandingRequest();
|
|
|
|
});
|
|
|
|
|
2014-07-08 04:58:24 -07:00
|
|
|
|
2014-06-04 19:11:18 -07:00
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
it('should hit github for version', function() {
|
|
|
|
$httpBackend.expectGET(GH);
|
|
|
|
scope.$apply();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
|
2014-06-27 11:42:08 -07:00
|
|
|
it('should check version ', inject(function($injector) {
|
|
|
|
notification = $injector.get('notification');
|
|
|
|
var spy = sinon.spy(notification, 'version');
|
2014-06-16 13:37:33 -07:00
|
|
|
$httpBackend.expectGET(GH);
|
|
|
|
scope.$apply();
|
|
|
|
$httpBackend.flush();
|
2014-06-27 11:42:08 -07:00
|
|
|
spy.calledOnce.should.equal(true);
|
|
|
|
}));
|
2014-06-16 13:37:33 -07:00
|
|
|
|
|
|
|
it('should check blockChainStatus', function() {
|
|
|
|
$httpBackend.expectGET(GH);
|
|
|
|
$httpBackend.flush();
|
|
|
|
rootScope.insightError = 1;
|
|
|
|
scope.$apply();
|
|
|
|
expect(rootScope.insightError).equal(1);
|
|
|
|
scope.$apply();
|
|
|
|
expect(rootScope.insightError).equal(1);
|
|
|
|
scope.$apply();
|
|
|
|
});
|
2014-06-12 13:42:26 -07:00
|
|
|
|
2014-08-05 07:53:58 -07:00
|
|
|
});
|
|
|
|
|
2014-10-29 14:34:59 -07:00
|
|
|
describe.skip("Unit: Sidebar Controller", function() {
|
2014-08-05 07:53:58 -07:00
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
2014-08-07 16:07:41 -07:00
|
|
|
rootScope = $rootScope;
|
2014-10-29 14:34:59 -07:00
|
|
|
scope = $rootScope.$new();
|
2014-08-05 07:53:58 -07:00
|
|
|
headerCtrl = $controller('SidebarController', {
|
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should return an array of n undefined elements', function() {
|
2014-06-23 15:45:04 -07:00
|
|
|
var n = 5;
|
|
|
|
var array = scope.getNumber(n);
|
|
|
|
expect(array.length).equal(n);
|
|
|
|
});
|
2014-06-04 19:11:18 -07:00
|
|
|
});
|
|
|
|
|
2014-06-19 11:07:20 -07:00
|
|
|
describe('Send Controller', function() {
|
2014-06-25 15:11:50 -07:00
|
|
|
var sendCtrl, form;
|
|
|
|
beforeEach(inject(function($compile, $rootScope, $controller) {
|
2014-06-19 11:07:20 -07:00
|
|
|
scope = $rootScope.$new();
|
2014-06-23 11:12:18 -07:00
|
|
|
$rootScope.availableBalance = 123456;
|
2014-06-25 15:11:50 -07:00
|
|
|
|
|
|
|
var element = angular.element(
|
|
|
|
'<form name="form">' +
|
|
|
|
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
|
|
|
'</form>'
|
2014-07-01 15:49:05 -07:00
|
|
|
);
|
2014-06-25 15:11:50 -07:00
|
|
|
scope.model = {
|
|
|
|
amount: null
|
|
|
|
};
|
|
|
|
$compile(element)(scope);
|
|
|
|
scope.$digest();
|
|
|
|
form = scope.form;
|
|
|
|
|
2014-06-19 11:07:20 -07:00
|
|
|
sendCtrl = $controller('SendController', {
|
|
|
|
$scope: scope,
|
2014-06-23 05:53:53 -07:00
|
|
|
$modal: {},
|
2014-06-19 11:07:20 -07:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should have a SendController', function() {
|
|
|
|
expect(scope.isMobile).not.to.equal(null);
|
|
|
|
});
|
2014-06-23 11:12:18 -07:00
|
|
|
it('should autotop balance correctly', function() {
|
2014-06-25 15:11:50 -07:00
|
|
|
scope.topAmount(form);
|
|
|
|
form.amount.$setViewValue(123356);
|
2014-06-23 11:12:18 -07:00
|
|
|
expect(scope.amount).to.equal(123356);
|
2014-06-25 15:11:50 -07:00
|
|
|
expect(form.amount.$invalid).to.equal(false);
|
|
|
|
expect(form.amount.$pristine).to.equal(false);
|
|
|
|
});
|
|
|
|
it('should return available amount', function() {
|
2014-11-03 12:28:36 -08:00
|
|
|
form.amount.$setViewValue(123356);
|
2014-06-25 15:11:50 -07:00
|
|
|
var amount = scope.getAvailableAmount();
|
|
|
|
expect(amount).to.equal(123356);
|
2014-06-23 11:12:18 -07:00
|
|
|
});
|
2014-09-08 13:31:18 -07:00
|
|
|
it('should return 0 if available amount below minimum fee', function() {
|
|
|
|
inject(function($compile, $rootScope, $controller) {
|
|
|
|
$rootScope.availableBalance = 1;
|
|
|
|
});
|
|
|
|
var amount = scope.getAvailableAmount();
|
|
|
|
expect(amount).to.equal(0);
|
|
|
|
});
|
2014-06-19 11:07:20 -07:00
|
|
|
});
|
|
|
|
|
2014-06-26 14:15:27 -07:00
|
|
|
describe('Import Controller', function() {
|
|
|
|
var what;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
what = $controller('ImportController', {
|
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
2014-09-22 11:02:41 -07:00
|
|
|
it('import status', function() {
|
|
|
|
expect(scope.importStatus).equal('Importing wallet - Reading backup...');
|
|
|
|
});
|
2014-06-26 14:37:30 -07:00
|
|
|
});
|
|
|
|
|
2014-10-29 14:34:59 -07:00
|
|
|
// TODO: fix this test
|
|
|
|
describe.skip('Home Controller', function() {
|
2014-06-26 14:37:30 -07:00
|
|
|
var what;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
2014-10-29 14:34:59 -07:00
|
|
|
what = $controller('HomeController', {
|
2014-06-26 14:37:30 -07:00
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
2014-06-26 14:15:27 -07:00
|
|
|
|
2014-06-26 14:37:30 -07:00
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
|
|
|
describe('#open', function() {
|
|
|
|
it('should work with invalid form', function() {
|
|
|
|
scope.open(invalidForm);
|
|
|
|
});
|
|
|
|
});
|
2014-07-28 09:30:41 -07:00
|
|
|
});
|
|
|
|
|
2014-08-11 13:26:48 -07:00
|
|
|
describe('Settings Controller', function() {
|
|
|
|
var what;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
what = $controller('SettingsController', {
|
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-09 08:59:48 -07:00
|
|
|
describe('Copayers Controller', function() {
|
|
|
|
var saveDownload = null;
|
|
|
|
var ctrl;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
|
|
|
|
ctrl = $controller('CopayersController', {
|
|
|
|
$scope: scope,
|
|
|
|
$modal: {},
|
|
|
|
});
|
|
|
|
}));
|
2014-08-11 13:26:48 -07:00
|
|
|
|
2014-09-09 08:59:48 -07:00
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(ctrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-08-11 13:26:48 -07:00
|
|
|
|
2014-07-28 09:30:41 -07:00
|
|
|
describe('Join Controller', function() {
|
|
|
|
var what;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
what = $controller('JoinController', {
|
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
2014-06-26 14:37:30 -07:00
|
|
|
describe('#join', function() {
|
|
|
|
it('should work with invalid form', function() {
|
|
|
|
scope.join(invalidForm);
|
|
|
|
});
|
|
|
|
});
|
2014-06-26 14:15:27 -07:00
|
|
|
});
|
|
|
|
|
2014-07-01 15:49:05 -07:00
|
|
|
describe('UriPayment Controller', function() {
|
|
|
|
var what;
|
2014-10-09 06:19:13 -07:00
|
|
|
beforeEach(inject(function($controller, $rootScope, $location) {
|
2014-07-01 15:49:05 -07:00
|
|
|
scope = $rootScope.$new();
|
2014-07-04 08:51:27 -07:00
|
|
|
var routeParams = {
|
2014-10-09 06:19:13 -07:00
|
|
|
data: 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8'
|
2014-07-01 15:49:05 -07:00
|
|
|
};
|
2014-10-29 14:34:59 -07:00
|
|
|
var query = {
|
|
|
|
amount: 0.1,
|
|
|
|
message: "a bitcoin donation"
|
|
|
|
};
|
2014-07-01 15:49:05 -07:00
|
|
|
what = $controller('UriPaymentController', {
|
|
|
|
$scope: scope,
|
2014-10-09 06:19:13 -07:00
|
|
|
$routeParams: routeParams,
|
|
|
|
$location: {
|
2014-10-29 14:34:59 -07:00
|
|
|
search: function() {
|
|
|
|
return query;
|
|
|
|
}
|
2014-10-09 06:19:13 -07:00
|
|
|
}
|
2014-07-01 15:49:05 -07:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should parse url correctly', function() {
|
|
|
|
should.exist(what);
|
2014-08-13 11:15:53 -07:00
|
|
|
should.exist(scope.pendingPayment);
|
|
|
|
scope.pendingPayment.address.data.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8');
|
|
|
|
scope.pendingPayment.data.amount.should.equal(0.1);
|
|
|
|
scope.pendingPayment.data.message.should.equal('a bitcoin donation');
|
2014-07-01 15:49:05 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-08-12 12:26:15 -07:00
|
|
|
describe('Warning Controller', function() {
|
|
|
|
var what;
|
|
|
|
beforeEach(inject(function($controller, $rootScope) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
what = $controller('WarningController', {
|
|
|
|
$scope: scope,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
should.exist(what);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-23 09:21:33 -07:00
|
|
|
});
|