Skip to content

Commit

Permalink
fix(BuySell): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jul 10, 2018
1 parent 532c778 commit 1c2808f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const INITIAL_STATE = {
coinifyBusy: Remote.NotAsked,
step: null,
checkoutStep: 'checkout',
signupComplete: null
signupComplete: null,
payment: Remote.NotAsked
}

const ERROR = 'error'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { coreSagasFactory, Remote } from 'blockchain-wallet-v4/src'
import * as actions from '../../actions'
import * as coinifyActions from './actions.js'
import * as selectors from '../../selectors.js'
import * as sendBtcSelectors from '../../components/sendBtc/selectors'
import settings from 'config'
import coinifySagas, { logLocation } from './sagas'
import coinifySagas, { logLocation, sellDescription } from './sagas'
import * as C from 'services/AlertService'
import * as sendBtcActions from '../../components/sendBtc/actions'
import { merge } from 'ramda'

jest.mock('blockchain-wallet-v4/src/redux/sagas')
Expand Down Expand Up @@ -520,6 +518,11 @@ describe('coinifySagas', () => {
saga.next(limits)
})

it('should select the state', () => {
const values = { currency: 'GBP' }
saga.next(values).select()
})

it('should dispatch an action to fetch a rate quote with the new currency', () => {
const values = { currency: 'GBP' }
saga.next(values).put(actions.core.data.coinify.fetchRateQuote('GBP'))
Expand Down Expand Up @@ -561,6 +564,11 @@ describe('coinifySagas', () => {
saga.next(limits)
})

it('should select the state', () => {
const values = { currency: 'EUR' }
saga.next(values).select()
})

it('should clear coinifyCheckoutError', () => {
const values = { currency: 'EUR' }
saga.next(values).put(coinifyActions.clearCoinifyCheckoutError())
Expand Down Expand Up @@ -616,6 +624,11 @@ describe('coinifySagas', () => {
saga.next(limits)
})

it('should select the state', () => {
const values = { currency: 'EUR' }
saga.next(values).select()
})

it('should fetch a quote', () => {
const values = { currency: 'EUR' }
saga.next(values).call(coreSagas.data.coinify.fetchQuote,
Expand Down Expand Up @@ -672,9 +685,18 @@ describe('coinifySagas', () => {
saga.next(limits)
})

it('should fetch a quote', () => {
it('should select the state', () => {
const values = { currency: 'EUR' }
saga.next(values).call(coreSagas.data.coinify.fetchQuote,
saga.next(values).select()
})

it('should fetch a quote', () => {
const state = {
coinify: {
payment: Remote.of({ effectiveBalance: 250000000 })
}
}
saga.next(state).call(coreSagas.data.coinify.fetchQuote,
{
quote: {
amount: action.payload * 100,
Expand All @@ -686,14 +708,9 @@ describe('coinifySagas', () => {
)
})

it('should select the payment', () => {
const leftResult = { quoteAmount: 200000 }
saga.next(leftResult).select(sendBtcSelectors.getPayment)
})

it('should clear any checkout error', () => {
const payment = Remote.of({ effectiveBalance: 250000000 })
saga.next(payment).put(coinifyActions.clearCoinifyCheckoutError())
const leftResult = { quoteAmount: 200000 }
saga.next(leftResult).put(coinifyActions.clearCoinifyCheckoutError())
})

it('should initialize the form with the new values', () => {
Expand Down Expand Up @@ -735,21 +752,29 @@ describe('coinifySagas', () => {
saga.next(limits)
})

it('should select the payment', () => {
it('should select the state', () => {
const values = { currency: 'EUR' }
saga.next(values).select(sendBtcSelectors.getPayment).save(saveToRestore)
saga.next(values).select().save(saveToRestore)
})

it('should clear checkout error', () => {
const payment = Remote.of({ effectiveBalance: 250000000 })
saga.next(payment).put(coinifyActions.setCoinifyCheckoutError('under_min'))
const state = {
coinify: {
payment: Remote.of({ effectiveBalance: 250000000 })
}
}
saga.next(state).put(coinifyActions.setCoinifyCheckoutError('under_min'))
})

it('should set limits error', () => {
const payment = Remote.of({ effectiveBalance: 0.0123 })
const state = {
coinify: {
payment: Remote.of({ effectiveBalance: 0.0123 })
}
}
saga
.restore(saveToRestore)
.next(payment)
.next(state)
.put(coinifyActions.setCoinifyCheckoutError('effective_max_under_min'))
})

Expand Down Expand Up @@ -982,16 +1007,20 @@ describe('coinifySagas', () => {
saga.next().call(coreSagas.data.coinify.sell)
})

it('should select the payment', () => {
it('should select the state', () => {
const trade = mockSellTrade
saga.next(trade).select(sendBtcSelectors.getPayment)
saga.next(trade).select()
})

it('should create payment', () => {
const p = Remote.of(null)
saga.next(p)
const state = {
coinify: {
payment: Remote.of(null)
}
}
saga.next(state)
expect(coreSagas.payment.btc.create).toHaveBeenCalledTimes(1)
expect(coreSagas.payment.btc.create).toHaveBeenCalledWith({ payment: p.getOrElse({}), network: settings.NETWORK })
expect(coreSagas.payment.btc.create).toHaveBeenCalledWith({ payment: state.coinify.payment.getOrElse({}), network: settings.NETWORK })
})

it('should update the payment amount', () => {
Expand All @@ -1001,13 +1030,8 @@ describe('coinifySagas', () => {
expect(paymentMock.amount).toHaveBeenCalledWith(500)
})

it('should select the state to check for a qa address', () => {
saga.next(paymentMock).select()
})

it('should set payment.to to the trade receiveAddress', () => {
const state = {}
saga.next(state)
saga.next(paymentMock)

expect(paymentMock.to).toHaveBeenCalledTimes(1)
expect(paymentMock.to).toHaveBeenCalledWith(tradeReceiveAddress)
Expand All @@ -1017,7 +1041,7 @@ describe('coinifySagas', () => {
saga.next(paymentMock)

expect(paymentMock.description).toHaveBeenCalledTimes(1)
expect(paymentMock.description).toHaveBeenCalledWith('Exchange Trade COINIFY=56789')
expect(paymentMock.description).toHaveBeenCalledWith(`${sellDescription}56789`)
})

it('should call payment.build', () => {
Expand All @@ -1026,10 +1050,6 @@ describe('coinifySagas', () => {
expect(paymentMock.build).toHaveBeenCalledTimes(1)
})

it('should update payment success', () => {
saga.next(paymentMock).put(sendBtcActions.sendBtcPaymentUpdatedSuccess(paymentMock.value()))
})

it('should call payment.sign with the second password', () => {
saga.next(paymentMock)

Expand All @@ -1043,8 +1063,12 @@ describe('coinifySagas', () => {
expect(paymentMock.publish).toHaveBeenCalledTimes(1)
})

it('should update payment success again', () => {
saga.next(paymentMock).put(sendBtcActions.sendBtcPaymentUpdatedSuccess(paymentMock.value()))
it('should fetch btc data', () => {
saga.next(paymentMock).put(actions.core.data.bitcoin.fetchData())
})

it('should set a tx note', () => {
saga.next(paymentMock).put(actions.core.wallet.setTransactionNote(paymentMock.value().txId, paymentMock.value().description))
})

it('should set success state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as actions from './actions'
const INITIAL_STATE = {
sfoxBusy: Remote.NotAsked,
qaSellAddress: null,
siftScienceEnabled: false
siftScienceEnabled: false,
payment: Remote.NotAsked
}

describe('sfox reducers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import * as selectors from '../../selectors.js'
import sfoxSagas, { logLocation } from './sagas'
import * as C from 'services/AlertService'
import { promptForSecondPassword } from 'services/SagaService'
import * as sendBtcSelectors from '../../components/sendBtc/selectors'
import * as sendBtcActions from '../../components/sendBtc/actions'
import settings from 'config'

jest.mock('blockchain-wallet-v4/src/redux/sagas')
Expand Down Expand Up @@ -427,16 +425,20 @@ describe('sfoxSagas', () => {
saga.next(quote).call(coreSagas.data.sfox.handleSellTrade, quote)
})

it('should select the payment', () => {
it('should select the state', () => {
const trade = mockSellTrade
saga.next(trade).select(sendBtcSelectors.getPayment)
saga.next(trade).select()
})

it('should create payment', () => {
const p = Remote.of(null)
saga.next(p)
const state = {
sfoxSignup: {
payment: Remote.of(null)
}
}
saga.next(state)
expect(coreSagas.payment.btc.create).toHaveBeenCalledTimes(1)
expect(coreSagas.payment.btc.create).toHaveBeenCalledWith({ payment: p.getOrElse({}), network: settings.NETWORK_BITCOIN })
expect(coreSagas.payment.btc.create).toHaveBeenCalledWith({ payment: state.sfoxSignup.payment.getOrElse({}), network: settings.NETWORK_BITCOIN })
})

it('should update the payment amount', () => {
Expand All @@ -446,13 +448,8 @@ describe('sfoxSagas', () => {
expect(paymentMock.amount).toHaveBeenCalledWith(100)
})

it('should select the state to check for a qa address', () => {
saga.next(paymentMock).select()
})

it('should set payment.to to the trade receiveAddress', () => {
const state = {}
saga.next(state)
saga.next(paymentMock)

expect(paymentMock.to).toHaveBeenCalledTimes(1)
expect(paymentMock.to).toHaveBeenCalledWith(tradeReceiveAddress)
Expand Down Expand Up @@ -484,8 +481,12 @@ describe('sfoxSagas', () => {
expect(paymentMock.publish).toHaveBeenCalledTimes(1)
})

it('should update payment success', () => {
saga.next(paymentMock).put(sendBtcActions.sendBtcPaymentUpdatedSuccess(paymentMock.value()))
it('should fetch btc data', () => {
saga.next(paymentMock).put(actions.core.data.bitcoin.fetchData())
})

it('should set a tx note', () => {
saga.next(paymentMock).put(actions.core.wallet.setTransactionNote(paymentMock.value().txId, paymentMock.value().description))
})

it('should set success state', () => {
Expand Down

0 comments on commit 1c2808f

Please sign in to comment.