Skip to content

Commit

Permalink
test(OTL): Throw error when campaign data or token is missing before …
Browse files Browse the repository at this point in the history
…registering campaign
  • Loading branch information
plondon committed Dec 20, 2018
1 parent 789d9cd commit 8ca6c10
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const failedResendError = 'Failed to resend the code'
export const userExistsError = 'User already exists'
export const emailExistsError = 'User with this email already exists'
export const wrongFlowTypeError = 'Wrong flow type'
export const noCampaignDataError = 'User did not come from campaign'
export const noTokenError = 'User has not been created'

export default ({ api, coreSagas }) => {
const {
Expand All @@ -60,26 +62,33 @@ export default ({ api, coreSagas }) => {
const registerUserCampaign = function*(payload) {
const { newUser = false } = payload
const campaign = yield select(selectors.modules.profile.getCampaign)
if (!campaign || isEmpty(campaign)) return
const campaignData = yield call(getCampaignData, campaign)
const token = (yield select(
selectors.modules.profile.getApiToken
)).getOrElse(null)
if (!token) return
try {
yield call(
api.registerUserCampaign,
token,
campaign.name,
campaignData,
newUser
)
if (!campaign || isEmpty(campaign)) throw new Error(noCampaignDataError)
const campaignData = yield call(getCampaignData, campaign)
const token = (yield select(
selectors.modules.profile.getApiToken
)).getOrElse(null)
if (!token) throw new Error(noTokenError)
try {
yield call(
api.registerUserCampaign,
token,
campaign.name,
campaignData,
newUser
)
} catch (e) {
// Todo: use generic confirm modal
// Should NOT be specific to sunriver
yield put(actions.modals.showModal(SUNRIVER_LINK_ERROR_MODAL))

This comment has been minimized.

Copy link
@tony-blockchain

tony-blockchain Dec 20, 2018

Contributor

should we log or rethrow here?

This comment has been minimized.

Copy link
@plondon

plondon Dec 20, 2018

Contributor

Hmm good point. I will add another throw

}
} catch (e) {
// Todo: use generic confirm modal
// Should NOT be specific to sunriver
yield put(actions.modals.showModal(SUNRIVER_LINK_ERROR_MODAL))
yield put(
actions.logs.logErrorMessage(logLocation, 'registerUserCampaign', e)
actions.logs.logErrorMessage(
logLocation,
'registerUserCampaign',
e.message
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
KYC_PROVIDERS,
SUNRIVER_LINK_ERROR_MODAL
} from './model'
import sagas, { logLocation, wrongFlowTypeError } from './sagas'
import sagas, {
logLocation,
wrongFlowTypeError,
noCampaignDataError,
noTokenError
} from './sagas'

const api = {
fetchKycConfig: jest.fn(),
Expand Down Expand Up @@ -249,11 +254,27 @@ describe('registerUserCampaign', () => {
.next()
.select(selectors.modules.profile.getCampaign)
.next(null)
.put(
actions.logs.logErrorMessage(
logLocation,
'registerUserCampaign',
noCampaignDataError
)
)
.next()
.isDone()
testSaga(registerUserCampaign, { newUser })
.next()
.select(selectors.modules.profile.getCampaign)
.next({})
.put(
actions.logs.logErrorMessage(
logLocation,
'registerUserCampaign',
noCampaignDataError
)
)
.next()
.isDone()
})
it("should not continue past selection of token if there's no token", () => {
Expand All @@ -266,6 +287,14 @@ describe('registerUserCampaign', () => {
.next(campaignData)
.select(selectors.modules.profile.getApiToken)
.next(Remote.of(null))
.put(
actions.logs.logErrorMessage(
logLocation,
'registerUserCampaign',
noTokenError
)
)
.next()
.isDone()
})
it('should show error modal and log error if registering fails', () => {
Expand All @@ -289,10 +318,6 @@ describe('registerUserCampaign', () => {
.throw(error)
.put(actions.modals.showModal(SUNRIVER_LINK_ERROR_MODAL))
.next()
.put(
actions.logs.logErrorMessage(logLocation, 'registerUserCampaign', error)
)
.next()
.isDone()
})
})

0 comments on commit 8ca6c10

Please sign in to comment.