Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4436 from willy-b/ledger-export-util-tests-rebase…
Browse files Browse the repository at this point in the history
…-again

Add tests for Ledger export utilities (and fix bugs) (rebased #4429)
  • Loading branch information
diracdeltas authored Oct 2, 2016
2 parents ec065b9 + 4699e52 commit 3fd5736
Show file tree
Hide file tree
Showing 3 changed files with 480 additions and 10 deletions.
24 changes: 14 additions & 10 deletions js/lib/ledgerExportUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ let getPublisherVoteData = function getPublisherVoteData (transactions, viewingI
*
* @param {Object[]} transactions - array of transactions
* @param {string[]=} viewingIds - OPTIONAL array/string with one or more viewingIds to filter transactions by (if empty, uses all tx)
* @param (boolean=) addTotalRow - OPTIONAL boolean indicating whether to add a TOTALS row (defaults false)
* @param {boolean=} addTotalRow - OPTIONAL boolean indicating whether to add a TOTALS row (defaults false)
**/
let getTransactionCSVRows = function (transactions, viewingIds, addTotalRow) {
let txContribData = getPublisherVoteData(transactions, viewingIds)
Expand All @@ -213,7 +213,8 @@ let getTransactionCSVRows = function (transactions, viewingIds, addTotalRow) {
return (a && typeof a === 'string' ? a : '').localeCompare(b && typeof b === 'string' ? b : '')
})

var currency = txContribData[publishers[0]].contribution.currency
var currency = (publishers.length ? txContribData[publishers[0]].contribution.currency : 'USD')

var headerRow = ['Publisher', 'Votes', 'Fraction', 'BTC', currency].join(',')

var totalsRow = {
Expand Down Expand Up @@ -248,7 +249,8 @@ let getTransactionCSVRows = function (transactions, viewingIds, addTotalRow) {
].join(',')
}))

if (addTotalRow) {
// note: do NOT add a total row if only header row is present (no data case)
if (addTotalRow && rows.length > 1) {
rows.push([
totalsRow.label,
totalsRow.votes,
Expand All @@ -269,17 +271,19 @@ let getTransactionCSVRows = function (transactions, viewingIds, addTotalRow) {
*
* @param {Object[]} transactions - array of transactions
* @param {string[]=} viewingIds - OPTIONAL array/string with one or more viewingIds to filter transactions by (if empty, uses all tx)
* @param (boolean=) addTotalRow - OPTIONAL boolean indicating whether to add a TOTALS row (defaults false)
* @param {boolean=} addTotalRow - OPTIONAL boolean indicating whether to add a TOTALS row (defaults false)
*
* returns a CSV with only a header row if input is empty or invalid
**/
let getTransactionCSVText = function (transactions, viewingIds, addTotalRow) {
return getTransactionCSVRows(transactions, viewingIds, addTotalRow).join('\n')
}

module.exports = {
transactionsToCSVDataURL: transactionsToCSVDataURL,
getTransactionCSVText: getTransactionCSVText,
getTransactionCSVRows: getTransactionCSVRows,
getPublisherVoteData: getPublisherVoteData,
getTransactionsByViewingIds: getTransactionsByViewingIds,
getTotalContribution: getTotalContribution
transactionsToCSVDataURL,
getTransactionCSVText,
getTransactionCSVRows,
getPublisherVoteData,
getTransactionsByViewingIds,
getTotalContribution
}
3 changes: 3 additions & 0 deletions test/unit/lib/exampleLedgerData.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3fd5736

Please sign in to comment.