Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/redux/reducers/Connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
memberIsBlockedForCostReasons,
} from 'src/utilities/institutionBlocks'
import { InstitutionStatus } from 'src/utilities/institutionStatus'
import { getEnvironment, Environments } from 'src/utilities/global'

export const defaultState = {
error: null, // The most recent job request error, if any
Expand Down Expand Up @@ -278,7 +279,7 @@ const selectInstitutionSuccess = (state, action) => {
// 2. Additional product - if the client is offering a product AND the institution has support for the product
// 3. Consent - if the Client has enabled consent
// 4. Institution disabled - if the institution is disabled by the client
// 5. Demo connect guard - if the user is a demo user but the institution is not a demo institution
// 5. Demo connect guard - if the user is a demo user, but the institution is not a demo institution, and the environment is production.
let nextStep = STEPS.ENTER_CREDENTIALS

const canOfferVerification =
Expand All @@ -287,13 +288,21 @@ const selectInstitutionSuccess = (state, action) => {
const canOfferAggregation =
action.payload.additionalProductOption === COMBO_JOB_DATA_TYPES.TRANSACTIONS

const isProdEnvironment = getEnvironment() === Environments.PRODUCTION

if (
action.payload.institution &&
(institutionIsBlockedForCostReasons(action.payload.institution) ||
action.payload.institutionStatus === InstitutionStatus.UNAVAILABLE)
) {
nextStep = STEPS.INSTITUTION_STATUS_DETAILS
} else if (action.payload.user?.is_demo && !action.payload.institution?.is_demo) {
} else if (
action.payload.user?.is_demo &&
!action.payload.institution?.is_demo &&
isProdEnvironment
) {
// Show the demo connect guard screen only when the user is a demo user, the selected institution is not a demo institution, and the environment is production.
// In non-production environments, allow connections to any institution.
nextStep = STEPS.DEMO_CONNECT_GUARD
} else if (canOfferVerification || canOfferAggregation) {
nextStep = STEPS.ADDITIONAL_PRODUCT
Expand Down
44 changes: 35 additions & 9 deletions src/redux/reducers/__tests__/Connect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { JOB_TYPES, JOB_STATUSES } from 'src/const/consts'
import { MicrodepositsStatuses } from 'src/views/microdeposits/const'
import { COMBO_JOB_DATA_TYPES } from 'src/const/comboJobDataTypes'
import { ACTIONABLE_ERROR_CODES } from 'src/views/actionableError/consts'
import * as globalUtilities from 'src/utilities/global'

describe('Connect redux store', () => {
const credential1 = { guid: 'CRD-123' }
Expand Down Expand Up @@ -641,17 +642,42 @@ describe('Connect redux store', () => {
)
})

it('should set the step to DEMO_CONNECT_GUARD when the user is a demo user but the institution is not a demo institution', () => {
const institution = { guid: 'INST-1', is_demo: false, credentials }
const user = { guid: 'USR-1', is_demo: true }
const afterState = reducer(defaultState, {
type: ActionTypes.SELECT_INSTITUTION_SUCCESS,
payload: { institution, user },
describe('demo connect guard', () => {
afterEach(() => {
vi.restoreAllMocks()
})

expect(afterState.location[afterState.location.length - 1].step).toEqual(
STEPS.DEMO_CONNECT_GUARD,
)
it('should set the step to DEMO_CONNECT_GUARD when the user is a demo user, the institution is not a demo institution, and the environment is production', () => {
vi.spyOn(globalUtilities, 'getEnvironment').mockReturnValue(
globalUtilities.Environments.PRODUCTION,
)
const institution = { guid: 'INST-1', is_demo: false, credentials }
const user = { guid: 'USR-1', is_demo: true }
const afterState = reducer(defaultState, {
type: ActionTypes.SELECT_INSTITUTION_SUCCESS,
payload: { institution, user },
})

expect(afterState.location[afterState.location.length - 1].step).toEqual(
STEPS.DEMO_CONNECT_GUARD,
)
})

it('should NOT set the step to DEMO_CONNECT_GUARD when the environment is not production', () => {
vi.spyOn(globalUtilities, 'getEnvironment').mockReturnValue(
globalUtilities.Environments.SANDBOX,
)
const institution = { guid: 'INST-1', is_demo: false, credentials }
const user = { guid: 'USR-1', is_demo: true }
const afterState = reducer(defaultState, {
type: ActionTypes.SELECT_INSTITUTION_SUCCESS,
payload: { institution, user },
})

expect(afterState.location[afterState.location.length - 1].step).not.toEqual(
STEPS.DEMO_CONNECT_GUARD,
)
})
})
})

Expand Down
Loading