Added test to transactionHistoryCvs
This commit is contained in:
parent
ae9b79b843
commit
3c238ca064
3 changed files with 80 additions and 13 deletions
|
|
@ -28,12 +28,19 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
|||
|
||||
$scope.generating = true;
|
||||
|
||||
//getTransactionHistoryCSV
|
||||
w.getTransactionHistoryCsv(function(csvContent) {
|
||||
if (csvContent && csvContent !== 'ERROR') {
|
||||
var filename = "copay_history.csv";
|
||||
|
||||
w.getTransactionHistoryCsv(function() {
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
link.setAttribute("download", filename);
|
||||
|
||||
link.click();
|
||||
}
|
||||
$scope.generating = false;
|
||||
$scope.$digest();
|
||||
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2688,16 +2688,17 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
|||
var self = this;
|
||||
self.getTransactionHistory(function(err, res) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
log.debug(err);
|
||||
return cb('ERROR');
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
return cb('Error');
|
||||
return cb('ERROR');
|
||||
}
|
||||
|
||||
var unit = self.settings.unitName;
|
||||
var data = res.items;
|
||||
var filename = "copay_history.csv";
|
||||
|
||||
var csvContent = "data:text/csv;charset=utf-8,";
|
||||
csvContent += "Date,Amount(" + unit + "),Action,AddressTo,Comment";
|
||||
|
||||
|
|
@ -2709,7 +2710,7 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
|||
|
||||
data.forEach(function(it, index) {
|
||||
if (!it) {
|
||||
return cb('Error');
|
||||
return cb('ERROR');
|
||||
}
|
||||
var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.comment);
|
||||
if (self.isShared() && it.actionList) {
|
||||
|
|
@ -2718,14 +2719,9 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
|||
csvContent += index < data.length ? dataString + "\n" : dataString;
|
||||
});
|
||||
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
link.setAttribute("download", filename);
|
||||
|
||||
link.click();
|
||||
|
||||
return cb(null);
|
||||
return cb(csvContent);
|
||||
|
||||
function formatDate(date) {
|
||||
var dateObj = new Date(date);
|
||||
|
|
|
|||
|
|
@ -2472,6 +2472,7 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
// TODO
|
||||
describe.skip('#onPayProPaymentAck', function() {
|
||||
it('should emit', function() {
|
||||
|
|
@ -2484,6 +2485,69 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#getTransactionHistoryCsv', function() {
|
||||
it.only('should return list of txs', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var txs = [{
|
||||
vin: [{
|
||||
addr: 'addr_in_1',
|
||||
valueSat: 1000
|
||||
}],
|
||||
vout: [{
|
||||
scriptPubKey: {
|
||||
addresses: ['addr_out_1'],
|
||||
},
|
||||
value: '0.00000900',
|
||||
}],
|
||||
fees: 0.00000100
|
||||
}, {
|
||||
vin: [{
|
||||
addr: 'addr_in_2',
|
||||
valueSat: 2000
|
||||
}],
|
||||
vout: [{
|
||||
scriptPubKey: {
|
||||
addresses: ['addr_out_2'],
|
||||
},
|
||||
value: '0.00001900',
|
||||
}],
|
||||
fees: 0.00000100
|
||||
}, {
|
||||
vin: [{
|
||||
addr: 'addr_in_1',
|
||||
valueSat: 3000
|
||||
|
||||
}],
|
||||
vout: [{
|
||||
scriptPubKey: {
|
||||
addresses: ['addr_out_2'],
|
||||
},
|
||||
value: '0.00002900',
|
||||
|
||||
}],
|
||||
fees: 0.00000100
|
||||
}];
|
||||
|
||||
w.blockchain.getTransactions = sinon.stub().yields(null, {
|
||||
items: txs,
|
||||
totalItems: txs.length,
|
||||
});
|
||||
w.getAddressesInfo = sinon.stub().returns([{
|
||||
addressStr: 'addr_in_1'
|
||||
}, {
|
||||
addressStr: 'addr_out_2'
|
||||
}]);
|
||||
|
||||
w.getTransactionHistoryCsv(function(data) {
|
||||
data.should.exist;
|
||||
data.should.equal('data:text/csv;charset=utf-8,Date,Amount(bits),Action,AddressTo,Comment,Signers\n,9,sent,"addr_out_1",\n,19,received,,\n,29,moved,"addr_out_2",\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe.skip('#read', function() {
|
||||
var network, blockchain;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue