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

Add tests for Ledger export utilities (and fix bugs) (rebased #4429) #4436

Merged
merged 1 commit into from
Oct 2, 2016
Merged

Add tests for Ledger export utilities (and fix bugs) (rebased #4429) #4436

merged 1 commit into from
Oct 2, 2016

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.
  • Ran git rebase -i to squash commits (if needed).

Replaces #4429 .
Follow-up to #4332 and #4346 (comment)

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 & passing

Fixes and miscellaneous:
- add example Ledger transaction data: `test/unit/lib/exampleLedgerData.js`
- fix how `ledgerExportUtil.js#transactionsToCSVDataURL` handled empty input
- use es6 object property notation in `ledgerExportUtil.js` (re: #4346 (comment))

Tests (re: #4346 (comment)):
```
example transaction data ("exampleLedgerData.js")
  ✓ there should be example transactions to test with
  ✓ the first example transaction should have a "ballots" object
  ✓ the first example transaction's "ballots" object should contain >= 1 publisher / vote-count KV pairs

transactionsToCSVDataURL
  ✓ returns a properly formatted data URL string with expected content-type (text/csv)
  ✓ for empty input, returns a CSV data URL containing only a header row
  ✓ given transactions, it returns a data URL containing the expected CSV

getTransactionCSVText
  ✓ for empty input, returns a CSV string containing only the expected header row
  ✓ returns a CSV with the expected header row up to variable currency column
  ✓ returns a CSV with the same number of columns in every row
  ✓ returns a CSV with expected data types for each column in every row
  ✓ returns same CSV for an array containing one transaction and a single transaction object
  ✓ given a transaction, returns a CSV containing the right number of rows: 1 header row, 1 row per publisher, and if addTotalRow===true, 1 row with totals
  ✓ returns CSV text matching the CSV rows returned by getTransactionCSVRows
  ✓ when argument addTotalRow===true, there should be a total row with correct totals for each numeric column

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

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" entry for the transaction object given as input
  each publisher value
    ✓ should have "votes" (type number, >= 0) defined
    ✓ should have "fraction" (type number, >= 0) defined
    ✓ should have "contribution" (type object) defined
    each publisher->contribution entry
      ✓ should have "satoshis" (type number, >= 0) defined
      ✓ should have "fiat" (type number, >= 0) defined
      ✓ should have "currency" (type string) defined

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

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)
```
Auditor: @diracdeltas
@diracdeltas diracdeltas merged commit 3fd5736 into brave:master Oct 2, 2016
@luixxiul luixxiul added this to the 0.12.4dev milestone Oct 2, 2016
@bsclifton
Copy link
Member

@willy-b great job with the tests 😄

@willy-b
Copy link
Contributor Author

willy-b commented Oct 2, 2016

@bsclifton thanks, these are just unit tests though. Still no automated integration / UI tests for Payment History, that's next.

@bsclifton
Copy link
Member

@willy-b unit tests are just as important as web driver tests, IMO- they complement each other very nicely.

Unit tests are great for ensuring the code is working as expected and web driver tests are great for ensuring behaviors we expect still work (preventing regressions). Keep it up 😄

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.

6 participants