-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(add buysell metadata reducers tests)
- Loading branch information
1 parent
62ae496
commit 8325f88
Showing
3 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/blockchain-wallet-v4/src/redux/kvStore/buySell/reducers.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters