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

Unit tests for Ledger export utilities #4429

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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