From 78693f4fc672efef64e13d38171dd240a2dae8bd Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:55:58 +0500 Subject: [PATCH] fix: uncaught exception on progressive profiling (#722) VAN-1224 --- .../RedirectLogistration.jsx | 8 +-- src/common-components/data/reducers.js | 12 +++-- .../data/tests/reducers.test.js | 49 +++++++++++++++++++ .../ProgressiveProfiling.jsx | 13 ++--- src/register/RegistrationPage.jsx | 2 +- 5 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/common-components/data/tests/reducers.test.js diff --git a/src/common-components/RedirectLogistration.jsx b/src/common-components/RedirectLogistration.jsx index 1adf7a91..6c332603 100644 --- a/src/common-components/RedirectLogistration.jsx +++ b/src/common-components/RedirectLogistration.jsx @@ -9,7 +9,7 @@ import { setCookie } from '../data/utils'; function RedirectLogistration(props) { const { - finishAuthUrl, redirectUrl, redirectToWelcomePage, success, optionalFields, + finishAuthUrl, redirectUrl, redirectToProgressiveProfilingPage, success, optionalFields, } = props; let finalRedirectUrl = ''; @@ -25,7 +25,7 @@ function RedirectLogistration(props) { } // Redirect to Progressive Profiling after successful registration - if (redirectToWelcomePage) { + if (redirectToProgressiveProfilingPage) { // TODO: Do we still need this cookie? setCookie('van-504-returning-user', true); const registrationResult = { redirectUrl: finalRedirectUrl, success }; @@ -50,7 +50,7 @@ RedirectLogistration.defaultProps = { finishAuthUrl: null, success: false, redirectUrl: '', - redirectToWelcomePage: false, + redirectToProgressiveProfilingPage: false, optionalFields: {}, }; @@ -58,7 +58,7 @@ RedirectLogistration.propTypes = { finishAuthUrl: PropTypes.string, success: PropTypes.bool, redirectUrl: PropTypes.string, - redirectToWelcomePage: PropTypes.bool, + redirectToProgressiveProfilingPage: PropTypes.bool, optionalFields: PropTypes.shape({}), }; diff --git a/src/common-components/data/reducers.js b/src/common-components/data/reducers.js index 139a0b3e..7574e9ed 100644 --- a/src/common-components/data/reducers.js +++ b/src/common-components/data/reducers.js @@ -23,15 +23,21 @@ const reducer = (state = defaultState, action) => { ...state, thirdPartyAuthApiStatus: PENDING_STATE, }; - case THIRD_PARTY_AUTH_CONTEXT.SUCCESS: + case THIRD_PARTY_AUTH_CONTEXT.SUCCESS: { + const extendedProfile = action.payload.optionalFields.extended_profile; + const extendedProfileArray = extendedProfile && JSON.parse(extendedProfile.replaceAll('\'', '"')); return { ...state, - extendedProfile: action.payload.fieldDescriptions.extended_profile, + extendedProfile: extendedProfileArray, fieldDescriptions: action.payload.fieldDescriptions.fields, - optionalFields: action.payload.optionalFields, + optionalFields: { + ...action.payload.optionalFields, + extended_profile: extendedProfileArray, + }, thirdPartyAuthContext: action.payload.thirdPartyAuthContext, thirdPartyAuthApiStatus: COMPLETE_STATE, }; + } case THIRD_PARTY_AUTH_CONTEXT.FAILURE: return { ...state, diff --git a/src/common-components/data/tests/reducers.test.js b/src/common-components/data/tests/reducers.test.js new file mode 100644 index 00000000..ea525d3f --- /dev/null +++ b/src/common-components/data/tests/reducers.test.js @@ -0,0 +1,49 @@ +import { THIRD_PARTY_AUTH_CONTEXT } from '../actions'; +import reducer from '../reducers'; + +describe('common components reducer', () => { + it('should convert extended profile from string to array', () => { + const state = { + extendedProfile: [], + fieldDescriptions: {}, + optionalFields: {}, + thirdPartyAuthApiStatus: null, + thirdPartyAuthContext: { + currentProvider: null, + finishAuthUrl: null, + countryCode: null, + providers: [], + secondaryProviders: [], + pipelineUserDetails: null, + }, + }; + const fieldDescriptions = { + fields: [], + extended_profile: "['state', 'profession']", + }; + const optionalFields = { + fields: [], + extended_profile: "['state', 'profession']", + }; + const thirdPartyAuthContext = { ...state.thirdPartyAuthContext }; + const action = { + type: THIRD_PARTY_AUTH_CONTEXT.SUCCESS, + payload: { fieldDescriptions, optionalFields, thirdPartyAuthContext }, + }; + + expect( + reducer(state, action), + ).toEqual( + { + ...state, + extendedProfile: ['state', 'profession'], + fieldDescriptions: [], + optionalFields: { + fields: [], + extended_profile: ['state', 'profession'], + }, + thirdPartyAuthApiStatus: 'complete', + }, + ); + }); +}); diff --git a/src/progressive-profiling/ProgressiveProfiling.jsx b/src/progressive-profiling/ProgressiveProfiling.jsx index cd92f9f2..944e8156 100644 --- a/src/progressive-profiling/ProgressiveProfiling.jsx +++ b/src/progressive-profiling/ProgressiveProfiling.jsx @@ -46,11 +46,13 @@ const ProgressiveProfiling = (props) => { useEffect(() => { configureAuth(AxiosJwtAuthService, { loggingService: getLoggingService(), config: getConfig() }); - ensureAuthenticatedUser(DASHBOARD_URL).then(() => { - hydrateAuthenticatedUser().then(() => { - setReady(true); - }); - }); + ensureAuthenticatedUser(DASHBOARD_URL) + .then(() => { + hydrateAuthenticatedUser().then(() => { + setReady(true); + }); + }) + .catch(() => {}); if (props.location.state && props.location.state.registrationResult) { setRegistrationResult(props.location.state.registrationResult); @@ -194,7 +196,6 @@ const ProgressiveProfiling = (props) => { }; ProgressiveProfiling.propTypes = { - // eslint-disable-next-line react/no-unused-prop-types formRenderState: PropTypes.string.isRequired, intl: intlShape.isRequired, location: PropTypes.shape({ diff --git a/src/register/RegistrationPage.jsx b/src/register/RegistrationPage.jsx index 1377ba5c..19a060b2 100644 --- a/src/register/RegistrationPage.jsx +++ b/src/register/RegistrationPage.jsx @@ -461,7 +461,7 @@ const RegistrationPage = (props) => { redirectUrl={registrationResult.redirectUrl} finishAuthUrl={finishAuthUrl} optionalFields={optionalFields} - redirectToWelcomePage={ + redirectToProgressiveProfilingPage={ getConfig().ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN && Object.keys(optionalFields).length !== 0 } />