mirror of https://github.com/BTCPrivate/copay.git
Adds tests for csv download
This commit is contained in:
parent
9709d6b64a
commit
aa076d7ccd
|
@ -590,6 +590,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.hasUnsafeConfirmed = true;
|
||||
}
|
||||
|
||||
if (tx.note) {
|
||||
delete tx.note.encryptedEditedByName;
|
||||
delete tx.note.encryptedBody;
|
||||
}
|
||||
|
||||
if (!txHistoryUnique[tx.txid]) {
|
||||
ret.push(tx);
|
||||
txHistoryUnique[tx.txid] = true;
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesHistory',
|
||||
function($scope, $log, $timeout, storageService, go, profileService, platformInfo, lodash) {
|
||||
function($scope, $log, $timeout, storageService, go, profileService, lodash) {
|
||||
var fc = profileService.focusedClient;
|
||||
var c = fc.credentials;
|
||||
var isCordova = platformInfo.isCordova;
|
||||
this.csvReady = false;
|
||||
|
||||
|
||||
this.csvHistory = function() {
|
||||
if (isCordova) return;
|
||||
this.csvHistory = function(cb) {
|
||||
|
||||
function formatDate(date) {
|
||||
var dateObj = new Date(date);
|
||||
|
@ -25,7 +23,6 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
|
|||
}
|
||||
|
||||
function formatString(str) {
|
||||
console.log('[index.js.710:str:]', str); //TODO
|
||||
if (!str) return '';
|
||||
|
||||
if (str.indexOf('"') !== -1) {
|
||||
|
@ -55,85 +52,96 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
|
|||
}
|
||||
|
||||
allTxs.push(txsFromLocal);
|
||||
console.log('[preferencesHistory.js.56:allTxs:]',allTxs); //TODO
|
||||
return cb(null, lodash.flatten(allTxs));
|
||||
});
|
||||
}
|
||||
|
||||
var fc = profileService.focusedClient;
|
||||
var c = fc.credentials;
|
||||
if (!fc.isComplete()) return;
|
||||
|
||||
if (!fc.isComplete())
|
||||
return;
|
||||
|
||||
var self = this;
|
||||
var allTxs = [];
|
||||
|
||||
console.log('[preferencesHistory.js.68]'); //TODO
|
||||
$log.debug('Generating CSV from History');
|
||||
|
||||
getHistory(function(err, txs) {
|
||||
console.log('[preferencesHistory.js.71:txs:]',txs); //TODO
|
||||
if (err || !txs || !txs[0]) {
|
||||
$log.warn('Failed to generate CSV:', err);
|
||||
return;
|
||||
} else {
|
||||
$log.debug('Wallet Transaction History Length:', txs.length);
|
||||
|
||||
self.satToUnit = 1 / self.unitToSatoshi;
|
||||
var data = txs;
|
||||
var satToBtc = 1 / 100000000;
|
||||
self.csvContent = [];
|
||||
self.csvFilename = 'Copay-' + (self.alias || self.walletName) + '.csv';
|
||||
self.csvHeader = ['Date', 'Destination', 'Description', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers'];
|
||||
|
||||
var _amount, _note, _copayers, _creator, _comment;
|
||||
data.forEach(function(it, index) {
|
||||
var amount = it.amount;
|
||||
|
||||
if (it.action == 'moved')
|
||||
amount = 0;
|
||||
|
||||
_copayers = '';
|
||||
_creator = '';
|
||||
|
||||
if (it.actions && it.actions.length > 1) {
|
||||
for (var i = 0; i < it.actions.length; i++) {
|
||||
_copayers += it.actions[i].copayerName + ':' + it.actions[i].type + ' - ';
|
||||
}
|
||||
_creator = (it.creatorName && it.creatorName != 'undefined') ? it.creatorName : '';
|
||||
}
|
||||
_amount = (it.action == 'sent' ? '-' : '') + (amount * satToBtc).toFixed(8);
|
||||
_note = it.message || '';
|
||||
_comment = it.note ? it.note.body : '';
|
||||
|
||||
if (it.action == 'moved')
|
||||
_note += ' Moved:' + (it.amount * satToBtc).toFixed(8)
|
||||
|
||||
self.csvContent.push({
|
||||
'Date': formatDate(it.time * 1000),
|
||||
'Destination': formatString(it.addressTo),
|
||||
'Description': _note,
|
||||
'Amount': _amount,
|
||||
'Currency': 'BTC',
|
||||
'Txid': it.txid,
|
||||
'Creator': _creator,
|
||||
'Copayers': _copayers,
|
||||
'Comment': _comment
|
||||
});
|
||||
|
||||
if (it.fees && (it.action == 'moved' || it.action == 'sent')) {
|
||||
var _fee = (it.fees * satToBtc).toFixed(8)
|
||||
self.csvContent.push({
|
||||
'Date': formatDate(it.time * 1000),
|
||||
'Destination': 'Bitcoin Network Fees',
|
||||
'Description': '',
|
||||
'Amount': '-' + _fee,
|
||||
'Currency': 'BTC',
|
||||
'Txid': '',
|
||||
'Creator': '',
|
||||
'Copayers': ''
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
self.csvReady = true;
|
||||
if (cb) return cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[preferencesHistory.js.77]', txs); //TODO
|
||||
$log.debug('Wallet Transaction History Length:', txs.length);
|
||||
|
||||
self.satToUnit = 1 / self.unitToSatoshi;
|
||||
var data = txs;
|
||||
var satToBtc = 1 / 100000000;
|
||||
self.csvContent = [];
|
||||
self.csvFilename = 'Copay-' + (self.alias || self.walletName) + '.csv';
|
||||
self.csvHeader = ['Date', 'Destination', 'Description', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers'];
|
||||
|
||||
var _amount, _note, _copayers, _creator, _comment;
|
||||
data.forEach(function(it, index) {
|
||||
var amount = it.amount;
|
||||
|
||||
if (it.action == 'moved')
|
||||
amount = 0;
|
||||
|
||||
_copayers = '';
|
||||
_creator = '';
|
||||
|
||||
if (it.actions && it.actions.length > 1) {
|
||||
for (var i = 0; i < it.actions.length; i++) {
|
||||
_copayers += it.actions[i].copayerName + ':' + it.actions[i].type + ' - ';
|
||||
}
|
||||
_creator = (it.creatorName && it.creatorName != 'undefined') ? it.creatorName : '';
|
||||
}
|
||||
_amount = (it.action == 'sent' ? '-' : '') + (amount * satToBtc).toFixed(8);
|
||||
_note = it.message || '';
|
||||
_comment = it.note ? it.note.body : '';
|
||||
|
||||
if (it.action == 'moved')
|
||||
_note += ' Moved:' + (it.amount * satToBtc).toFixed(8)
|
||||
|
||||
self.csvContent.push({
|
||||
'Date': formatDate(it.time * 1000),
|
||||
'Destination': formatString(it.addressTo),
|
||||
'Description': _note,
|
||||
'Amount': _amount,
|
||||
'Currency': 'BTC',
|
||||
'Txid': it.txid,
|
||||
'Creator': _creator,
|
||||
'Copayers': _copayers,
|
||||
'Comment': _comment
|
||||
});
|
||||
|
||||
if (it.fees && (it.action == 'moved' || it.action == 'sent')) {
|
||||
var _fee = (it.fees * satToBtc).toFixed(8)
|
||||
self.csvContent.push({
|
||||
'Date': formatDate(it.time * 1000),
|
||||
'Destination': 'Bitcoin Network Fees',
|
||||
'Description': '',
|
||||
'Amount': '-' + _fee,
|
||||
'Currency': 'BTC',
|
||||
'Txid': '',
|
||||
'Creator': '',
|
||||
'Copayers': ''
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[preferencesHistory.js.131]'); //TODO
|
||||
self.csvReady = true;
|
||||
if (cb)
|
||||
return cb();
|
||||
return;
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
describe('Preferences History Controller', function() {
|
||||
|
||||
var walletService;
|
||||
|
||||
var txHistory = '[{"txid":"bf31ecaa8e10ce57f9a889fc4c893b40ff57b016dd763957d942e21ed55fc62c","action":"received","amount":120000,"fees":4862,"time":1464969291,"confirmations":8,"outputs":[{"amount":120000,"address":"2N4HgtF9cJSzxhVkj5gbKxwJSKWBmnb9FNJ","message":null}],"note":{"body":"just a comment","editedBy":"31a8c3c0be9ffbb9f257c95f3fd2f73a59cf81e40199ba5918417270db8c4cdb","editedByName":"2-2","editedOn":1464969101},"message":null,"creatorName":"","hasUnconfirmedInputs":false,"amountStr":"1,200 bits","alternativeAmountStr":"0.68 USD","feeStr":"49 bits","safeConfirmed":"6+"}]';
|
||||
|
||||
describe('Complete 1-1 wallet', function() {
|
||||
beforeEach(function(done) {
|
||||
mocks.init(FIXTURES, 'preferencesHistory', {
|
||||
loadProfile: PROFILE.testnet1of1,
|
||||
loadStorage: {
|
||||
'txsHistory-66d3afc9-7d76-4b25-850e-aa62fcc53a7d': txHistory,
|
||||
},
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
mocks.clear({}, done);
|
||||
});
|
||||
|
||||
it('should export csv', function(done) {
|
||||
ctrl.csvHistory(function(err) {
|
||||
should.not.exist(err);
|
||||
ctrl.csvReady.should.equal(true);
|
||||
JSON.stringify(ctrl.csvContent).should.equal('[{"Date":"2016-06-03T15:54:51.000Z","Destination":"","Description":"","Amount":"0.00120000","Currency":"BTC","Txid":"bf31ecaa8e10ce57f9a889fc4c893b40ff57b016dd763957d942e21ed55fc62c","Creator":"","Copayers":"","Comment":"just a comment"}]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -105,7 +105,7 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
|||
var headers = JSON.stringify(bwc._getHeaders(method, url, args));
|
||||
|
||||
// Fixes BWC version... TODO
|
||||
headers=headers.replace(/bwc-\d\.\d\.\d/,'bwc-2.4.0')
|
||||
headers = headers.replace(/bwc-\d\.\d\.\d/, 'bwc-2.4.0')
|
||||
var x = method + url + JSON.stringify(args) + headers;
|
||||
var sjcl = $delegate.getSJCL();
|
||||
return sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(x));
|
||||
|
@ -163,7 +163,7 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
|||
});
|
||||
module('copayApp.controllers');
|
||||
|
||||
inject(function($rootScope, $controller, $injector, _configService_, _profileService_, _storageService_) {
|
||||
inject(function($rootScope, $controller, $injector, lodash, _configService_, _profileService_, _storageService_) {
|
||||
scope = $rootScope.$new();
|
||||
storageService = _storageService_;
|
||||
|
||||
|
@ -198,6 +198,13 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
|||
if (opts.initController)
|
||||
startController();
|
||||
|
||||
|
||||
if (opts.loadStorage) {
|
||||
lodash.each(opts.loadStorage, function(v, k) {
|
||||
localStorage.setItem(k, v);
|
||||
});
|
||||
}
|
||||
|
||||
if (opts.loadProfile) {
|
||||
|
||||
localStorage.setItem('profile', JSON.stringify(opts.loadProfile));
|
||||
|
|
Loading…
Reference in New Issue