Skip to content

Commit

Permalink
test(add buysell metadata reducers tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 28, 2018
1 parent 62ae496 commit 8325f88
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const fetchMetadataBuySellSuccess = (data) => ({ type: AT.FETCH_METADATA_
export const fetchMetadataBuySellFailure = (error) => ({ type: AT.FETCH_METADATA_BUYSELL_FAILURE, payload: error })

// create
export const createMetadataBuysell = (data) => ({ type: AT.CREATE_METADATA_BUYSELL, payload: data })
export const createMetadataBuySell = (data) => ({ type: AT.CREATE_METADATA_BUYSELL, payload: data })

export const sfoxSetProfileBuySell = (payload) => ({ type: AT.SFOX_SET_PROFILE_BUYSELL, payload })
export const coinifySetProfileBuySell = (payload) => ({ type: AT.COINIFY_SET_PROFILE_BUYSELL, payload })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { assoc, assocPath, compose, set } from 'ramda'
import { mapped, over } from 'ramda-lens'
import Remote from '../../../remote'
import { KVStoreEntry } from '../../../types'
import { derivationMap, BUYSELL } from '../config'
import reducer from './reducers'
import * as actions from './actions'

const INITIAL_STATE = Remote.NotAsked

describe('kvStore bch reducers', () => {
const typeId = derivationMap[BUYSELL]
const buySellObject = {
sfox: {
trades: []
},
coinify: {
trades: []
}
}

const buySellMetadata = set(KVStoreEntry.value,
buySellObject,
KVStoreEntry.createEmpty(typeId))

const buySellMetadataSuccess = Remote.Success(buySellMetadata)
const valueLens = compose(mapped, KVStoreEntry.value)

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

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

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

it('should handle FETCH_METADATA_BUYSELL_SUCCESS', () => {
const action = actions.fetchMetadataBuySellSuccess(buySellMetadata)
const expectedState = buySellMetadataSuccess
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle CREATE_METADATA_BUYSELL', () => {
const action = actions.createMetadataBuySell(buySellMetadata)
const expectedState = buySellMetadataSuccess
expect(reducer(undefined, action)).toEqual(expectedState)
})

it('should handle UPDATE_METADATA_BUYSELL', () => {
const action = actions.updateMetadataBuySell(buySellObject)
const expectedState = buySellMetadataSuccess
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SET_SFOX_TRADES_BUYSELL', () => {
const trades = [1, 2, 3]
const action = actions.setSfoxTradesBuySell(trades)
const setSfoxTrades = assocPath(['sfox', 'trades'], trades)
const expectedState = over(valueLens, setSfoxTrades, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SET_COINIFY_TRADES_BUYSELL true', () => {
const trades = [5, 4, 0]
const action = actions.setCoinifyTradesBuySell(trades)
const setCoinifyTrades = assocPath(['coinify', 'trades'], trades)
const expectedState = over(valueLens, setCoinifyTrades, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle SFOX_SET_PROFILE_BUYSELL false', () => {
const payload = {
token: 'some sfox token',
account: {
id: 42
}
}
const action = actions.sfoxSetProfileBuySell(payload)
const setSfoxProfile = compose(
assocPath(['sfox', 'account_token'], payload.token),
assocPath(['sfox', 'user'], payload.account.id)
)
const expectedState = over(valueLens, setSfoxProfile, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle COINIFY_SET_PROFILE_BUYSELL', () => {
const payload = {
offlineToken: 'some coinify token',
trader: {
id: 42
}
}
const action = actions.coinifySetProfileBuySell(payload)
const setCoinifyProfile = compose(
assocPath(['coinify', 'offline_token'], payload.offlineToken),
assocPath(['coinify', 'user'], payload.trader.id)
)
const expectedState = over(valueLens, setCoinifyProfile, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle WIPE_EXTERNAL', () => {
const action = actions.wipeExternal()
const wipe = assoc('coinify', { trades: [] })
const expectedState = over(valueLens, wipe, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})

it('should handle WIPE_EXTERNAL_SFOX', () => {
const action = actions.wipeExternalSfox()
const wipe = assoc('sfox', { trades: [] })
const expectedState = over(valueLens, wipe, buySellMetadataSuccess)
expect(reducer(buySellMetadataSuccess, action)).toEqual(expectedState)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default ({ api }) => {
}
}
const newkv = set(KVStoreEntry.value, newBuysellEntry, kv)
yield put(A.createMetadataBuysell(newkv))
yield put(A.createMetadataBuySell(newkv))
}

const fetchMetadataBuySell = function * () {
Expand Down

0 comments on commit 8325f88

Please sign in to comment.