Started on unit tests for wallet history.
This commit is contained in:
parent
d68870f743
commit
2d0e5c5f79
1 changed files with 81 additions and 0 deletions
81
src/js/services/wallet-history.service.spec.js
Normal file
81
src/js/services/wallet-history.service.spec.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
fdescribe('walletHistoryService', function(){
|
||||
var history = [];
|
||||
var historyStringFull;
|
||||
var storageServiceMock;
|
||||
var txFormatServiceMock;
|
||||
var walletHistoryService;
|
||||
|
||||
|
||||
beforeEach(function(){
|
||||
module('ngLodash');
|
||||
module('bitcoincom.services');
|
||||
|
||||
storageServiceMock = jasmine.createSpyObj(['getTxHistory', 'removeTxHistory', 'setTxHistory']);
|
||||
txFormatServiceMock = jasmine.createSpyObj(['processTx']);
|
||||
txFormatServiceMock.processTx.and.callFake(function(coin, tx){
|
||||
return tx;
|
||||
})
|
||||
|
||||
module(function($provide) {
|
||||
$provide.value('storageService', storageServiceMock);
|
||||
$provide.value('txFormatService', txFormatServiceMock);
|
||||
});
|
||||
|
||||
inject(function($injector){
|
||||
walletHistoryService = $injector.get('walletHistoryService');
|
||||
});
|
||||
|
||||
for(var i = 0; i < 100; i++) {
|
||||
history.push({
|
||||
confirmations: i,
|
||||
time: (Date.now() / 1000) - i,
|
||||
txid: 'id' + i.toString()
|
||||
});
|
||||
}
|
||||
historyStringFull = JSON.stringify(history);
|
||||
});
|
||||
|
||||
it('getCachedHistory empty', function() {
|
||||
var returnedErr;
|
||||
var returnedHistory;
|
||||
var walletIdForStorageGet = '';
|
||||
|
||||
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
|
||||
walletIdForStorageGet = walletId;
|
||||
|
||||
cb(null, "[]");
|
||||
});
|
||||
|
||||
walletHistoryService.getCachedTxHistory('wallet1234', function(err, txHistory){
|
||||
returnedErr = err;
|
||||
returnedHistory = txHistory;
|
||||
});
|
||||
|
||||
expect(walletIdForStorageGet).toBe('wallet1234');
|
||||
expect(returnedErr).toBeNull();
|
||||
expect(returnedHistory.length).toBe(0);
|
||||
});
|
||||
|
||||
it('getCachedHistory page full', function() {
|
||||
var returnedErr;
|
||||
var returnedHistory;
|
||||
var walletIdForStorageGet = '';
|
||||
|
||||
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
|
||||
walletIdForStorageGet = walletId;
|
||||
|
||||
cb(null, JSON.stringify(history.slice(0, 50)));
|
||||
});
|
||||
|
||||
walletHistoryService.getCachedTxHistory('wallet1234', function(err, txHistory){
|
||||
returnedErr = err;
|
||||
returnedHistory = txHistory;
|
||||
});
|
||||
|
||||
expect(walletIdForStorageGet).toBe('wallet1234');
|
||||
expect(returnedErr).toBeNull();
|
||||
expect(returnedHistory.length).toBe(50);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue