fix: uncaught exception on progressive profiling (#722)

VAN-1224
This commit is contained in:
Syed Sajjad Hussain Shah
2023-01-05 16:55:58 +05:00
committed by GitHub
parent 186484defa
commit 78693f4fc6
5 changed files with 70 additions and 14 deletions

View File

@@ -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,

View File

@@ -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',
},
);
});
});