mirror of https://github.com/BTCPrivate/copay.git
karma unit directive and services fixed
This commit is contained in:
parent
b2c04b7372
commit
061938ea63
|
@ -7,23 +7,37 @@ describe("Unit: Testing Directives", function() {
|
|||
var $scope, form;
|
||||
|
||||
beforeEach(module('copayApp.directives'));
|
||||
|
||||
var walletConfig = {
|
||||
requiredCopayers: 3,
|
||||
totalCopayers: 5,
|
||||
spendUnconfirmed: 1,
|
||||
reconnectDelay: 100,
|
||||
networkName: 'testnet',
|
||||
alternativeName: 'lol currency',
|
||||
alternativeIsoCode: 'LOL'
|
||||
};
|
||||
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
$rootScope.wallet = new FakeWallet(walletConfig);
|
||||
var w = $rootScope.wallet;
|
||||
w.settings.unitToSatoshi = 100;
|
||||
w.settings.unitName = 'bits';
|
||||
|
||||
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');
|
||||
w.getTransactionHistory = sinon.stub().yields({});
|
||||
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;
|
||||
}));
|
||||
|
||||
describe('Validate Address', function() {
|
||||
|
@ -99,11 +113,10 @@ describe("Unit: Testing Directives", function() {
|
|||
describe('Unit: BTC', function() {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
$scope = $rootScope;
|
||||
var w = new FakeWallet(walletConfig);
|
||||
var w = $rootScope.wallet;
|
||||
w.settings.unitToSatoshi = 100000000;
|
||||
w.settings.unitName = 'BTC';
|
||||
w.settings.unitDecimals = 8;
|
||||
$rootScope.wallet = w;
|
||||
|
||||
$rootScope.availableBalance = 0.04;
|
||||
var element = angular.element(
|
||||
|
|
|
@ -7,30 +7,75 @@ var sinon = require('sinon');
|
|||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
beforeEach(angular.mock.module('copayApp'));
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
beforeEach(module(function($provide) {
|
||||
$provide.value('request', {
|
||||
'get': function(_, cb) {
|
||||
cb(null, null, [{
|
||||
name: 'USD Dollars',
|
||||
code: 'USD',
|
||||
rate: 2
|
||||
}]);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
beforeEach(inject(function($rootScope) {
|
||||
|
||||
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.balanceByAddr = [{
|
||||
'address1': 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.getId = sinon.stub().returns('id');
|
||||
w.exportEncrypted = sinon.stub().returns('1234567');
|
||||
w.getTransactionHistory = sinon.stub().yields({});
|
||||
w.getNetworkName = sinon.stub().returns('testnet');
|
||||
w.getAddressesInfo = sinon.stub().returns({});
|
||||
|
||||
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;
|
||||
}));
|
||||
|
||||
|
||||
describe("Unit: Walletfactory Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a identity service', inject(function(identity) {
|
||||
expect(identity).not.to.equal(null);
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: controllerUtils", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
|
||||
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
|
||||
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||
scope = $rootScope.$new();
|
||||
var w = $rootScope.wallet;
|
||||
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
|
||||
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
var a = {};
|
||||
a[Waddr] = 100;
|
||||
//SATs
|
||||
$rootScope.wallet.set(100000001, 90000002, a);
|
||||
w.getBalance = sinon.stub().returns(100000001, 90000002, a);
|
||||
|
||||
//retuns values in DEFAULT UNIT(bits)
|
||||
controllerUtils.updateBalance(function() {
|
||||
controllerUtils.updateBalance(null, function() {
|
||||
expect($rootScope.totalBalanceBTC).to.be.equal(1.00000001);
|
||||
expect($rootScope.availableBalanceBTC).to.be.equal(0.90000002);
|
||||
expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999);
|
||||
|
@ -45,7 +90,7 @@ describe("Unit: controllerUtils", function() {
|
|||
}));
|
||||
|
||||
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
|
||||
controllerUtils.setupRootVariables(function() {
|
||||
controllerUtils.setupGlobalVariables(function() {
|
||||
expect($rootScope.txAlertCount).to.be.equal(0);
|
||||
expect($rootScope.insightError).to.be.equal(0);
|
||||
expect($rootScope.isCollapsed).to.be.equal(0);
|
||||
|
@ -55,27 +100,24 @@ describe("Unit: controllerUtils", function() {
|
|||
});
|
||||
|
||||
describe("Unit: Notification Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a notification service', inject(function(notification) {
|
||||
expect(notification).not.to.equal(null);
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: Backup Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a backup service', inject(function(backupService) {
|
||||
expect(backupService).not.to.equal(null);
|
||||
}));
|
||||
it('should backup in file', inject(function(backupService) {
|
||||
var mock = sinon.mock(window);
|
||||
var expectation = mock.expects('saveAs');
|
||||
backupService.download(new FakeWallet());
|
||||
backupService._download({}, 'test');
|
||||
expectation.once();
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: isMobile Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a isMobile service', inject(function(isMobile) {
|
||||
expect(isMobile).not.to.equal(null);
|
||||
}));
|
||||
|
@ -91,7 +133,6 @@ describe("Unit: isMobile Service", function() {
|
|||
});
|
||||
|
||||
describe("Unit: uriHandler service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a uriHandler service', inject(function(uriHandler) {
|
||||
should.exist(uriHandler);
|
||||
}));
|
||||
|
@ -103,7 +144,6 @@ describe("Unit: uriHandler service", function() {
|
|||
});
|
||||
|
||||
describe('Unit: Rate Service', function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should be injected correctly', inject(function(rateService) {
|
||||
should.exist(rateService);
|
||||
}));
|
||||
|
@ -112,22 +152,11 @@ describe('Unit: Rate Service', function() {
|
|||
should.exist(rateService.isAvailable);
|
||||
})
|
||||
);
|
||||
beforeEach(module(function($provide) {
|
||||
$provide.value('request', {
|
||||
'get': function(_, cb) {
|
||||
cb(null, null, [{
|
||||
name: 'lol currency',
|
||||
code: 'LOL',
|
||||
rate: 2
|
||||
}]);
|
||||
}
|
||||
});
|
||||
}));
|
||||
it('should be possible to ask for conversion from fiat',
|
||||
function(done) {
|
||||
inject(function(rateService) {
|
||||
rateService.whenAvailable(function() {
|
||||
(1e8).should.equal(rateService.fromFiat(2, 'LOL'));
|
||||
(1e8).should.equal(rateService.fromFiat(2, 'USD'));
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
@ -137,7 +166,7 @@ describe('Unit: Rate Service', function() {
|
|||
function(done) {
|
||||
inject(function(rateService) {
|
||||
rateService.whenAvailable(function() {
|
||||
(2).should.equal(rateService.toFiat(1e8, 'LOL'));
|
||||
(2).should.equal(rateService.toFiat(1e8, 'USD'));
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue