Skip to content

Commit

Permalink
test(Coinify): test signup saga
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Jul 2, 2018
1 parent b9d60c6 commit f0b427f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import * as sendBtcSelectors from '../../components/sendBtc/selectors'
import settings from 'config'
import { promptForSecondPassword } from 'services/SagaService'

export default ({ coreSagas }) => {
const logLocation = 'modules/coinify/sagas'
export const logLocation = 'modules/coinify/sagas'

export default ({ coreSagas }) => {
const coinifySignup = function * (data) {
const country = data.payload
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { select } from 'redux-saga/effects'

import { expectSaga, testSaga } from 'redux-saga-test-plan'
import * as matchers from 'redux-saga-test-plan/matchers'
import { throwError } from 'redux-saga-test-plan/providers'
import { coreSagasFactory } from 'blockchain-wallet-v4/src'
import * as actions from '../../actions'
import * as coinifyActions from './actions.js'
import * as selectors from '../../selectors.js'

import coinifySagas, { logLocation } from './sagas'
import * as C from 'services/AlertService'

jest.mock('blockchain-wallet-v4/src/redux/sagas')
const coreSagas = coreSagasFactory()

describe('coinifySagas', () => {
beforeAll(() => {
Math.random = () => 0.5
})

describe('coinify signup', () => {
let { coinifySignup } = coinifySagas({
coreSagas
})

const data = {
payload: {
country: 'FR'
}
}

let saga = testSaga(coinifySignup, data)
const beforeDetermine = 'beforeDetermine'

it('should call core signup with the payload', () => {
saga.next().call(coreSagas.data.coinify.signup, data.payload)
})

it('should select the profile', () => {
saga.next().select(selectors.core.data.coinify.getProfile()).save(beforeDetermine)
})

it('should go to ISX step if no error', () => {
const profile = { id: 1 }
saga
.next(profile)
.call(coreSagas.data.coinify.triggerKYC)
.next()
.put(coinifyActions.coinifyNextStep('isx'))
})

it('should handle an error', () => {
const errorProfile = { error: '{"error": "signup_error"}' }
saga
.restore(beforeDetermine)
.next(errorProfile)
.put(coinifyActions.coinifySignupFailure(JSON.parse(errorProfile.error)))
})

describe('error handling', () => {
const error = new Error('ERROR')
it('should log and display an error', () => {
saga
.restart()
.next()
.throw(error)
.put(actions.logs.logErrorMessage(logLocation, 'coinifySignup', error))
.next()
.put(actions.alerts.displayError(C.COINIFY_SIGNUP_ERROR))
})
})
})
})
10 changes: 10 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/__mocks__/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export default () => ({
handleTrade: jest.fn(),
setProfile: jest.fn(),
verifyMicroDeposits: jest.fn()
},
coinify: {
signup: jest.fn(),
buy: jest.fn(),
initialized: jest.fn(),
getKYC: jest.fn(),
triggerKYC: jest.fn(),
cancelTrade: jest.fn(),
cancelSubscription: jest.fn(),

}
}
})

0 comments on commit f0b427f

Please sign in to comment.