Skip to content

Commit

Permalink
Fix App Search and Workplace Search to not crash during error connecting
Browse files Browse the repository at this point in the history
- due to obj type errors
  • Loading branch information
cee-chen committed Sep 21, 2020
1 parent c6200cc commit 5670e0b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ describe('AppLogic', () => {
}),
});
});

it('gracefully handles missing initial data', () => {
AppLogic.actions.initializeAppData({});

expect(AppLogic.values).toEqual({
...DEFAULT_VALUES,
hasInitialized: true,
});
});
});

describe('setOnboardingComplete()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
account: [
{},
{
initializeAppData: (_, { appSearch: account }) => account,
initializeAppData: (_, { appSearch: account }) => account || {},
setOnboardingComplete: (account) => ({
...account,
onboardingComplete: true,
Expand All @@ -49,7 +49,7 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
configuredLimits: [
{},
{
initializeAppData: (_, { configuredLimits }) => configuredLimits.appSearch,
initializeAppData: (_, { configuredLimits }) => configuredLimits?.appSearch || {},
},
],
ilmEnabled: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ describe('AppLogic', () => {

expect(AppLogic.values).toEqual(expectedLogicValues);
});

it('gracefully handles missing initial data', () => {
AppLogic.actions.initializeAppData({});

expect(AppLogic.values).toEqual({
...DEFAULT_VALUES,
hasInitialized: true,
isFederatedAuth: false,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface IAppActions {
initializeAppData(props: IInitialAppData): IInitialAppData;
}

const emptyOrg = {} as IOrganization;
const emptyAccount = {} as IAccount;

export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
path: ['enterprise_search', 'workplace_search', 'app_logic'],
actions: {
Expand All @@ -43,15 +46,15 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
},
],
organization: [
{} as IOrganization,
emptyOrg,
{
initializeAppData: (_, { workplaceSearch }) => workplaceSearch!.organization,
initializeAppData: (_, { workplaceSearch }) => workplaceSearch?.organization || emptyOrg,
},
],
account: [
{} as IAccount,
emptyAccount,
{
initializeAppData: (_, { workplaceSearch }) => workplaceSearch!.account,
initializeAppData: (_, { workplaceSearch }) => workplaceSearch?.account || emptyAccount,
},
],
},
Expand Down

0 comments on commit 5670e0b

Please sign in to comment.