Skip to content

Commit

Permalink
test(add ethereum metadata reducers and selectors tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 28, 2018
1 parent 532b125 commit fa9e87a
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { assoc, assocPath, compose, set } from 'ramda'
import { mapped, over } from 'ramda-lens'
import Remote from '../../../remote'
import { KVStoreEntry } from '../../../types'
import { derivationMap, ETHEREUM } from '../config'
import reducer from './reducers'
import * as actions from './actions'

const INITIAL_STATE = Remote.NotAsked

describe('kvStore bch reducers', () => {
const typeId = derivationMap[ETHEREUM]
const ethereumObject = {
ethereum: {
accounts: [
{
addr: 'some address',
label: 'some label'
}
],
last_tx: 'this is the last tx',
last_tx_timestamp: 'this is the last tx timestamp',
legacy_account: 'this is the legacy account',
tx_notes: {
'someTxHash': 'some someTxHash tx note'
}
}
}

const ethereumMetadata = set(KVStoreEntry.value,
ethereumObject,
KVStoreEntry.createEmpty(typeId))

const ethereumMetadataSuccess = Remote.Success(ethereumMetadata)
const valueLens = compose(mapped, KVStoreEntry.value)

it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(INITIAL_STATE)
})

it('should handle FETCH_METADATA_ETHEREUM_LOADING', () => {
const action = actions.fetchMetadataEthereumLoading()
const expectedState = Remote.Loading
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle FETCH_METADATA_ETHEREUM_FAILURE', () => {
const error = 'Cannot load bch metadata'
const action = actions.fetchMetadataEthereumFailure(error)
const expectedState = Remote.Failure(error)
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle FETCH_METADATA_ETHEREUM_SUCCESS', () => {
const action = actions.fetchMetadataEthereumSuccess(ethereumMetadata)
const expectedState = ethereumMetadataSuccess
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle CREATE_METADATA_ETHEREUM', () => {
const action = actions.createMetadataEthereum(ethereumMetadata)
const expectedState = ethereumMetadataSuccess
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle SET_TRANSACTION_NOTE_ETHEREUM', () => {
const txHash = 'someTxHash'
const txNote = 'new tx note'
const action = actions.setTxNotesEthereum(txHash, txNote)
const setTxNote = assocPath(['ethereum', 'tx_notes', txHash], txNote)
const expectedState = over(valueLens, setTxNote, ethereumMetadataSuccess)
expect(reducer(ethereumMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SET_LATEST_TX_ETHEREUM', () => {
const latestTx = 'latest tx'
const action = actions.setLatestTxEthereum(latestTx)
const setCoinifyTrades = assocPath(['ethereum', 'last_tx'], latestTx)
const expectedState = over(valueLens, setCoinifyTrades, ethereumMetadataSuccess)
expect(reducer(ethereumMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SET_LATEST_TX_TIMESTAMP_ETHEREUM', () => {
const latestTimestamp = 42
const action = actions.setLatestTxTimestampEthereum(latestTimestamp)
const setLatestTimestamp = assocPath(['ethereum', 'last_tx_timestamp'], latestTimestamp)
const expectedState = over(valueLens, setLatestTimestamp, ethereumMetadataSuccess)
expect(reducer(ethereumMetadataSuccess, action)).toEqual(expectedState)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { assocPath } from 'ramda'
import Remote from '../../../remote'
import * as selectors from './selectors'

describe('kvstore ethereum selectors', () => {
const accounts = [
{
addr: 'some address',
label: 'some label'
},
{
addr: 'second address',
label: 'second label'
}
]

const ethMetadata = {
value: {
ethereum: {
accounts,
last_tx: 'this is the last tx',
last_tx_timestamp: 'this is the last tx timestamp',
legacy_account: { addr: 'legacy account addr' },
tx_notes: {
'someTxHash': 'some someTxHash tx note'
}
}
}
}

const successState = {
kvStorePath: {
ethereum: Remote.Success(ethMetadata)
}
}

it('getMetadata should return success of metadata', () => {
const expectedResult = Remote.Success(ethMetadata)
expect(selectors.getMetadata(successState)).toEqual(expectedResult)
})

it('getAccounts should return success of accounts', () => {
const expectedResult = Remote.Success(accounts)
expect(selectors.getAccounts(successState)).toEqual(expectedResult)
})

it('getDefaultAccount should return success of default account', () => {
const expectedResult = Remote.Success({
addr: 'some address',
label: 'some label'
})
expect(selectors.getDefaultAccount(successState)).toEqual(expectedResult)
})

it('getDefaultAddress should return success of default account address', () => {
const expectedResult = Remote.Success('some address')
expect(selectors.getDefaultAddress(successState)).toEqual(expectedResult)
})

it('getDefaultLabel should return success of default account label', () => {
const expectedResult = Remote.Success('some label')
expect(selectors.getDefaultLabel(successState)).toEqual(expectedResult)
})

it('getLegacyAccount should return success of legacy account', () => {
const expectedResult = Remote.Success({ addr: 'legacy account addr' })
expect(selectors.getLegacyAccount(successState)).toEqual(expectedResult)
})

it('getLegacyAccountAddress should return success of legacy account address', () => {
const expectedResult = Remote.Success('legacy account addr')
expect(selectors.getLegacyAccountAddress(successState)).toEqual(expectedResult)
})

it('getAccount should return success of account', () => {
const expectedResult = Remote.Success({
addr: 'second address',
label: 'second label'
})
expect(selectors.getAccount(successState, 'second address')).toEqual(expectedResult)
})

it('getAccountLabel should return success of account label', () => {
const expectedResult = Remote.Success('second label')
expect(selectors.getAccountLabel(successState, 'second address')).toEqual(expectedResult)
})

it('getAccountIndex should return success of account index', () => {
const expectedResult = Remote.Success(1)
expect(selectors.getAccountIndex(successState, 'second address')).toEqual(expectedResult)
})

it('getEthereumTxNote should return success of correct eth tx note', () => {
const expectedResult = Remote.Success('some someTxHash tx note')
expect(selectors.getEthereumTxNote(successState, 'someTxHash')).toEqual(expectedResult)
})

it('getLatestTx should return success of latest tx', () => {
const expectedResult = Remote.Success('this is the last tx')
expect(selectors.getLatestTx(successState)).toEqual(expectedResult)
})

it('getLatestTxTimestamp should return success of latest tx timestamp', () => {
const expectedResult = Remote.Success('this is the last tx timestamp')
expect(selectors.getLatestTxTimestamp(successState)).toEqual(expectedResult)
})
})

0 comments on commit fa9e87a

Please sign in to comment.