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

Unit tests for Ledger export utilities #4429

wants to merge 6 commits into from

Conversation

willy-b
Copy link
Contributor

@willy-b willy-b commented Oct 2, 2016

  • Submitted a ticket for my issue if one did not already exist.

Follow-up to #4332 and #4346 (comment)

  • Ran git rebase -i to squash commits (if needed).

Test Plan:

  • Run all unit tests -- OR just the added ledgerExportUtilTest.jswith:
NODE_ENV=test mocha --compilers js:babel-register --recursive test/unit/lib/ledgerExportUtilTest.js
  • Observe ledgerExportUtilTest tests running (and passing)

cc/ @diracdeltas

Willy Bruns added 6 commits October 1, 2016 16:50
- add example Ledger transaction data `test/unit/lib/exampleLedgerData.js`
- add tests for `ledgerExportUtil.js#transactionsToCSVDataURL` (re: #4346 (comment))
- add tests for `ledgerExportUtil.js#getTransactionCSVText`
- fix how `ledgerExportUtil.js#transactionsToCSVDataURL` handled empty input
- add sanity check tests on example transaction data
- use es6 object property notation in `ledgerExportUtil.js` (re: #4346 (comment))
…rtUtil.js

Wrote failing placeholder tests (`describe` and `it` blocks) for remaining ledgerExportUtil methods w/out tests:
  getTransactionCSVRows
  getPublisherVoteData
  getTransactionsByViewingIds
  getTotalContribution

these tests fail with message "not yet impl"
added tests for #getTransactionCSVRows:
```
getTransactionCSVRows
  ✓ for empty input, returns an array containing only the expected CSV header row
  ✓ returns a CSV row array, where the first row is the expected header row up to the currency column (which varies)
  ✓ returns a CSV row array with the same number of columns in every row
  ✓ returns a CSV row array with expected data types for each column in every row
  ✓ returns the same output for a single transaction input as an array of 1 element and a plain transaction object
  ✓ given a transaction, returns an array containing the right number of CSV rows: 1 header row, 1 row per publisher, and if addTotalRow===true, 1 row with totals
  ✓ when argument addTotalRow===true, there should be a total row with correct totals for each numeric column
  	Sum for column Votes (#1) across 10 rows (=43) matches expected value (43)
  	Sum for column Fraction (#2) across 10 rows (=1) matches expected value (1)
  	Sum for column BTC (#3) across 10 rows (=0.0000813917) matches expected value (0.0000813917)
```
also split out shared helper methods for getTransactionCSVText/getTransactionCSVRows

Auditors: @diracdeltas
Impl tests for ledgerExportUtil3getPublisherVoteData:
```
getPublisherVoteData
  ✓ should return a publisher data object with 1 key per publisher
  ✓ the sum of the "fraction" value across all publisher entries should be 1
  ✓ the sum of the "votes" value across all publisher entries should be equal to the overall "votes" y for the transaction object given as input
  each publisher value
    ✓ should have "votes" (type number) defined
    ✓ should have "fraction" (type number) defined
    ✓ should have "contribution" (type object) defined
    each publisher->contribution entry
      ✓ should have "satoshis" (type number) defined
      ✓ should have "fiat" (type number) defined
      ✓ should have "currency" (type string) defined
```
Auditors: @diracdeltas
Impl tests for getTransactionsByViewingIds:
```
getTransactionsByViewingIds
  ✓ given a single viewingId as a string, it returns an array containing just that transaction (if it exists)
  ✓ given viewingIds as an array, it filters a transactions array for those transactions
```
Auditors: @diracdeltas
Impl tests for getTotalContribution:
```
getTotalContribution
  ✓ returns a total contribution object
  total contribution object
    ✓ has a key "satoshis" with value of type number (>= 0)
    ✓ has a key "fiat" associated with an object containing two subkeys, "amount" (number) and "currency" (string)
    ✓ has a key, fee with value of type number (>= 0)
```
Auditors: @diracdeltas

assert.equal(sum, expectedTotal, `Sum for column ${colIdx} across ${rows.length} rows does not match expected value`)
let columnNames = CSV_HEADER_ROW_PREFIX_COLUMNS.concat(['Fiat'])
console.log(`\tSum for column ${columnNames[colIdx]} (#${colIdx}) across ${rows.length} rows (=${sum}) matches expected total (${expectedTotal})`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this logging

@diracdeltas
Copy link
Member

lgtm after rebase, thanks for the tests!

@willy-b
Copy link
Contributor Author

willy-b commented Oct 2, 2016

Sweet, thanks.
Closing this in favor of PR for rebased branch: #4436

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants