diff --git a/src/redux/reducers/Connect.js b/src/redux/reducers/Connect.js index e3e1b1b823..af41bb818e 100644 --- a/src/redux/reducers/Connect.js +++ b/src/redux/reducers/Connect.js @@ -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 @@ -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 = @@ -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 diff --git a/src/redux/reducers/__tests__/Connect-test.js b/src/redux/reducers/__tests__/Connect-test.js index 84b30b3472..29c84aadfe 100644 --- a/src/redux/reducers/__tests__/Connect-test.js +++ b/src/redux/reducers/__tests__/Connect-test.js @@ -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' } @@ -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, + ) + }) }) })