Skip to content

Commit

Permalink
Change logic to fetch role mappings data after enabling RBAC (#130127)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger authored Apr 13, 2022
1 parent bed793a commit bbbb8ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ describe('RoleMappingsLogic', () => {
});
});

it('setRoleMappings', () => {
RoleMappingsLogic.actions.setRoleMappings({ roleMappings: [asRoleMapping] });

expect(RoleMappingsLogic.values.roleMappings).toEqual([asRoleMapping]);
expect(RoleMappingsLogic.values.dataLoading).toEqual(false);
});

describe('setElasticsearchUser', () => {
it('sets user', () => {
RoleMappingsLogic.actions.setElasticsearchUser(elasticsearchUsers[0]);
Expand Down Expand Up @@ -323,7 +316,10 @@ describe('RoleMappingsLogic', () => {
describe('listeners', () => {
describe('enableRoleBasedAccess', () => {
it('calls API and sets values', async () => {
const setRoleMappingsSpy = jest.spyOn(RoleMappingsLogic.actions, 'setRoleMappings');
const initializeRoleMappingsSpy = jest.spyOn(
RoleMappingsLogic.actions,
'initializeRoleMappings'
);
http.post.mockReturnValue(Promise.resolve(mappingsServerProps));
RoleMappingsLogic.actions.enableRoleBasedAccess();

Expand All @@ -333,7 +329,7 @@ describe('RoleMappingsLogic', () => {
'/internal/app_search/role_mappings/enable_role_based_access'
);
await nextTick();
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
expect(initializeRoleMappingsSpy).toHaveBeenCalled();
});

itShowsServerErrorAsFlashMessage(http.post, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ const emptyUser = { username: '', email: '' } as ElasticsearchUser;
interface RoleMappingsActions extends RoleMappingsBaseActions {
setRoleMapping(roleMapping: ASRoleMapping): { roleMapping: ASRoleMapping };
setSingleUserRoleMapping(data?: UserMapping): { singleUserRoleMapping: UserMapping };
setRoleMappings({ roleMappings }: { roleMappings: ASRoleMapping[] }): {
roleMappings: ASRoleMapping[];
};
setRoleMappingsData(data: RoleMappingsServerDetails): RoleMappingsServerDetails;
handleAccessAllEnginesChange(selected: boolean): { selected: boolean };
handleEngineSelectionChange(engineNames: string[]): { engineNames: string[] };
Expand Down Expand Up @@ -322,8 +319,8 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
const route = '/internal/app_search/role_mappings/enable_role_based_access';

try {
const response = await http.post<{ roleMappings: ASRoleMapping[] }>(route);
actions.setRoleMappings(response);
await http.post<{ roleMappings: ASRoleMapping[] }>(route);
actions.initializeRoleMappings();
} catch (e) {
flashAPIErrors(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ describe('RoleMappingsLogic', () => {
});
});

it('setRoleMappings', () => {
RoleMappingsLogic.actions.setRoleMappings({ roleMappings: [wsRoleMapping] });

expect(RoleMappingsLogic.values.roleMappings).toEqual([wsRoleMapping]);
expect(RoleMappingsLogic.values.dataLoading).toEqual(false);
});

describe('setElasticsearchUser', () => {
it('sets user', () => {
RoleMappingsLogic.actions.setElasticsearchUser(elasticsearchUsers[0]);
Expand Down Expand Up @@ -283,7 +276,10 @@ describe('RoleMappingsLogic', () => {
describe('listeners', () => {
describe('enableRoleBasedAccess', () => {
it('calls API and sets values', async () => {
const setRoleMappingsSpy = jest.spyOn(RoleMappingsLogic.actions, 'setRoleMappings');
const initializeRoleMappingsSpy = jest.spyOn(
RoleMappingsLogic.actions,
'initializeRoleMappings'
);
http.post.mockReturnValue(Promise.resolve(mappingsServerProps));
RoleMappingsLogic.actions.enableRoleBasedAccess();

Expand All @@ -293,7 +289,7 @@ describe('RoleMappingsLogic', () => {
'/internal/workplace_search/org/role_mappings/enable_role_based_access'
);
await nextTick();
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
expect(initializeRoleMappingsSpy).toHaveBeenCalled();
});

itShowsServerErrorAsFlashMessage(http.post, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ interface RoleMappingsActions extends RoleMappingsBaseActions {
setDefaultGroup(availableGroups: RoleGroup[]): { availableGroups: RoleGroup[] };
setRoleMapping(roleMapping: WSRoleMapping): { roleMapping: WSRoleMapping };
setSingleUserRoleMapping(data?: UserMapping): { singleUserRoleMapping: UserMapping };
setRoleMappings({ roleMappings }: { roleMappings: WSRoleMapping[] }): {
roleMappings: WSRoleMapping[];
};
setRoleMappingsData(data: RoleMappingsServerDetails): RoleMappingsServerDetails;
handleAllGroupsSelectionChange(selected: boolean): { selected: boolean };
handleGroupSelectionChange(groupIds: string[]): { groupIds: string[] };
Expand Down Expand Up @@ -322,10 +319,8 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
const route = '/internal/workplace_search/org/role_mappings/enable_role_based_access';

try {
const response = await http.post<{
roleMappings: WSRoleMapping[];
}>(route);
actions.setRoleMappings(response);
await http.post<{ roleMappings: WSRoleMapping[] }>(route);
actions.initializeRoleMappings();
} catch (e) {
flashAPIErrors(e);
}
Expand Down

0 comments on commit bbbb8ea

Please sign in to comment.