Wallet/test/unit/services/servicesSpec.js

146 lines
4.6 KiB
JavaScript
Raw Normal View History

2014-04-23 13:21:33 -03:00
//
// test/unit/services/servicesSpec.js
//
//
//
2014-06-18 13:01:50 -03:00
var sinon = require('sinon');
2014-06-25 17:10:00 -03:00
beforeEach(function() {
config.unitToSatoshi = 100;
config.unitName = 'bits';
});
describe('Check config', function() {
2014-06-25 17:10:00 -03:00
it('unit should be set to BITS in config.js', function() {
expect(config.unitToSatoshi).to.equal(100);
expect(config.unitName).to.equal('bits');
});
});
2014-06-12 17:42:26 -03:00
describe("Unit: Walletfactory Service", function() {
beforeEach(angular.mock.module('copayApp.services'));
2014-04-23 18:07:20 -03:00
it('should contain a walletFactory service', inject(function(walletFactory) {
expect(walletFactory).not.to.equal(null);
}));
2014-06-12 17:42:26 -03:00
});
2014-04-23 18:07:20 -03:00
2014-06-12 17:42:26 -03:00
describe("Unit: controllerUtils", function() {
2014-06-25 11:12:38 -03:00
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();
$rootScope.wallet = new FakeWallet();
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
var a = {};
a[Waddr] = 100;
//SATs
$rootScope.wallet.set(100000001, 90000002, a);
//retuns values in DEFAULT UNIT(bits)
controllerUtils.updateBalance(function() {
2014-06-27 09:53:18 -03:00
expect($rootScope.totalBalanceBTC).to.be.equal(1.00000001);
expect($rootScope.availableBalanceBTC).to.be.equal(0.90000002);
2014-07-31 11:55:53 -03:00
expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999);
2014-06-25 11:12:38 -03:00
expect($rootScope.totalBalance).to.be.equal(1000000.01);
expect($rootScope.availableBalance).to.be.equal(900000.02);
2014-07-31 11:55:53 -03:00
expect($rootScope.lockedBalance).to.be.equal(99999.99);
2014-06-25 11:12:38 -03:00
expect($rootScope.addrInfos).not.to.equal(null);
expect($rootScope.addrInfos[0].address).to.equal(Waddr);
2014-06-12 17:42:26 -03:00
});
2014-06-25 11:12:38 -03:00
}));
2014-06-16 17:40:59 -03:00
2014-06-25 11:12:38 -03:00
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
controllerUtils.setupRootVariables(function() {
expect($rootScope.txAlertCount).to.be.equal(0);
expect($rootScope.insightError).to.be.equal(0);
expect($rootScope.isCollapsed).to.be.equal(0);
expect($rootScope.unitName).to.be.equal('bits');
});
}));
});
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());
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);
}));
it('should not detect mobile by default', inject(function(isMobile) {
isMobile.any().should.equal(false);
}));
it('should detect mobile if user agent is Android', inject(function(isMobile) {
navigator.__defineGetter__('userAgent', function() {
return 'Android 2.2.3';
});
isMobile.any().should.equal(true);
}));
});
2014-09-02 11:51:05 -03:00
2014-06-30 18:48:48 -03:00
describe("Unit: uriHandler service", function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a uriHandler service', inject(function(uriHandler) {
should.exist(uriHandler);
}));
it('should register', inject(function(uriHandler) {
(function() {
uriHandler.register();
}).should.not.throw();
}));
});
2014-08-28 17:44:40 -03:00
describe('Unit: Rate Service', function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should be injected correctly', inject(function(rateService) {
should.exist(rateService);
}));
it('should be possible to ask if it is available',
inject(function(rateService) {
should.exist(rateService.isAvailable);
})
);
2014-08-28 21:06:49 -03:00
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',
inject(function(rateService) {
rateService.whenAvailable(function() {
(1).should.equal(rateService.fromFiat(2, 'LOL'));
});
})
);
it('should be possible to ask for conversion to fiat',
2014-08-28 17:44:40 -03:00
inject(function(rateService) {
rateService.whenAvailable(function() {
2014-08-28 21:06:49 -03:00
(2).should.equal(rateService.toFiat(1e8, 'LOL'));
2014-08-28 17:44:40 -03:00
});
})
);
});