fix: uncaught exception on progressive profiling (#729)

VAN-1224
This commit is contained in:
Syed Sajjad Hussain Shah
2023-01-06 16:42:08 +05:00
committed by GitHub
parent 72510047d8
commit e8282d6d4a
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 = Object.keys(extendedProfile).length !== 0 ? extendedProfile : [];
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 empty extended profile object 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: {},
};
const optionalFields = {
fields: [],
extended_profile: {},
};
const thirdPartyAuthContext = { ...state.thirdPartyAuthContext };
const action = {
type: THIRD_PARTY_AUTH_CONTEXT.SUCCESS,
payload: { fieldDescriptions, optionalFields, thirdPartyAuthContext },
};
expect(
reducer(state, action),
).toEqual(
{
...state,
extendedProfile: [],
fieldDescriptions: [],
optionalFields: {
fields: [],
extended_profile: [],
},
thirdPartyAuthApiStatus: 'complete',
},
);
});
});