From 1bbf92ebdf0e6cc7fbcc6c274176c8bae17d64ce Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Wed, 28 Apr 2021 13:44:11 -0500 Subject: [PATCH 1/2] feat: TT-229 remove code -> FT 'switch group' --- .../guards/admin-guard/admin.guard.spec.ts | 66 +------------------ src/app/guards/admin-guard/admin.guard.ts | 25 ++----- src/app/modules/home/home.component.spec.ts | 32 +-------- src/app/modules/home/home.component.ts | 22 ++----- .../login/services/azure.ad.b2c.service.ts | 5 +- .../sidebar/sidebar.component.spec.ts | 11 ---- .../components/sidebar/sidebar.component.ts | 21 ++---- .../feature-switch-group.service.spec.ts | 34 ---------- .../feature-switch-group.service.ts | 14 ---- src/environments/environment.ts | 3 - 10 files changed, 25 insertions(+), 208 deletions(-) delete mode 100644 src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.spec.ts delete mode 100644 src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.ts diff --git a/src/app/guards/admin-guard/admin.guard.spec.ts b/src/app/guards/admin-guard/admin.guard.spec.ts index 7398b97a7..35c404de0 100644 --- a/src/app/guards/admin-guard/admin.guard.spec.ts +++ b/src/app/guards/admin-guard/admin.guard.spec.ts @@ -2,65 +2,32 @@ import { inject, TestBed } from '@angular/core/testing'; import { Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { of } from 'rxjs'; -import { skip, take } from 'rxjs/operators'; -import { FeatureSwitchGroupService } from 'src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; -import { AzureAdB2CService } from '../../modules/login/services/azure.ad.b2c.service'; import { AdminGuard } from './admin.guard'; describe('AdminGuard', () => { let adminGuard: AdminGuard; - let azureAdB2CService: AzureAdB2CService; let userInfoService: UserInfoService; - let featureSwitchGroupService: FeatureSwitchGroupService; - const azureAdB2CServiceStub = { - isLogin() { - return true; - }, - isAdmin() { - return true; - }, - }; const userInfoServiceStub = { isAdmin: () => of(false), }; - const featureSwitchGroupServiceStub = { - isActivated: () => of(false), - }; - beforeEach(() => { TestBed.configureTestingModule({ imports: [RouterTestingModule], providers: [ - { provide: AzureAdB2CService, useValue: azureAdB2CServiceStub }, { provide: UserInfoService, useValue: userInfoServiceStub }, - { provide: FeatureSwitchGroupService, useValue: featureSwitchGroupServiceStub }, ], }); adminGuard = TestBed.inject(AdminGuard); - azureAdB2CService = TestBed.inject(AzureAdB2CService); userInfoService = TestBed.inject(UserInfoService); - featureSwitchGroupService = TestBed.inject(FeatureSwitchGroupService); }); it('should be created', () => { expect(adminGuard).toBeTruthy(); }); - const roleParams = [{ bool: false }, { bool: true }]; - roleParams.map((param) => { - it(`isAdminBasedInRole return ${param.bool}`, () => { - spyOn(azureAdB2CService, 'isAdmin').and.returnValue(param.bool); - - adminGuard.isAdminBasedInRole().subscribe((enabled) => { - expect(azureAdB2CService.isAdmin).toHaveBeenCalled(); - expect(enabled).toBe(param.bool); - }); - }); - }); - const groupParams = [{ bool: false }, { bool: true }]; groupParams.map((param) => { it(`isAdminBasedInGroup return ${param.bool}`, () => { @@ -73,49 +40,22 @@ describe('AdminGuard', () => { }); }); - const switchToggleParams = [ - { switchGroup: false, chosen: 'isAdminBasedInRole', isAdmin: true }, - { switchGroup: true, chosen: 'isAdminBasedInGroup', isAdmin: false }, - ]; - switchToggleParams.map((param) => { - it(`on switchGroup ${param.switchGroup}, ${param.chosen} should be chosen`, () => { - const switchGroup$ = of(param.switchGroup); - - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(switchGroup$); - - const canActivate = adminGuard.canActivate(); - - featureSwitchGroupService.isActivated().pipe(take(1)); - - canActivate.subscribe((enabled) => { - expect(featureSwitchGroupService.isActivated).toHaveBeenCalled(); - expect(enabled).toBe(param.isAdmin); - }); - }); - }); - const navigateParams = [ - { switchGroup: false, chosen: 'activate the route', isAdmin: true }, - { switchGroup: false, chosen: 'redirect to /login', isAdmin: false }, - { switchGroup: true, chosen: 'activate the route', isAdmin: true }, - { switchGroup: true, chosen: 'redirect to /login', isAdmin: false }, + { chosen: 'activate the route', isAdmin: true }, + { chosen: 'redirect to /login', isAdmin: false } ]; navigateParams.map((param) => { - it(`on isAdmin: ${param.isAdmin} with toggleSwitch: ${param.switchGroup}, should ${param.chosen} `, inject( + it(`on isAdmin: ${param.isAdmin}, should ${param.chosen} `, inject( [Router], (router: Router) => { - const switchGroup$ = of(param.switchGroup); const isAdmin$ = of(param.isAdmin); - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(switchGroup$); - spyOn(adminGuard, 'isAdminBasedInRole').and.returnValue(isAdmin$); spyOn(adminGuard, 'isAdminBasedInGroup').and.returnValue(isAdmin$); spyOn(router, 'navigate').and.stub(); const canActivate = adminGuard.canActivate(); canActivate.subscribe((enabled) => { - expect(featureSwitchGroupService.isActivated).toHaveBeenCalled(); if (!enabled) { expect(router.navigate).toHaveBeenCalledWith(['login']); } else { diff --git a/src/app/guards/admin-guard/admin.guard.ts b/src/app/guards/admin-guard/admin.guard.ts index be0325b5b..ab9cb72df 100644 --- a/src/app/guards/admin-guard/admin.guard.ts +++ b/src/app/guards/admin-guard/admin.guard.ts @@ -1,40 +1,27 @@ import { Injectable } from '@angular/core'; import { Router, CanActivate } from '@angular/router'; -import { Observable, of } from 'rxjs'; -import { map, mergeMap } from 'rxjs/operators'; -import { FeatureSwitchGroupService } from 'src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; -import { AzureAdB2CService } from '../../modules/login/services/azure.ad.b2c.service'; @Injectable({ providedIn: 'root', }) export class AdminGuard implements CanActivate { constructor( - private azureAdB2CService: AzureAdB2CService, private router: Router, private userInfoService: UserInfoService, - private featureSwitchGroup: FeatureSwitchGroupService - ) {} + ) { } canActivate(): Observable { - return this.featureSwitchGroup.isActivated().pipe( - mergeMap((enabled: boolean) => { - return enabled ? this.isAdminBasedInGroup() : this.isAdminBasedInRole(); - }), - map((isAdmin: boolean): boolean => { - if (!isAdmin) { - this.router.navigate(['login']); - } + return this.isAdminBasedInGroup().pipe( + map((isAdmin: boolean) => { + if (!isAdmin) { this.router.navigate(['login']); } return isAdmin; }) ); } - isAdminBasedInRole(): Observable { - return of(this.azureAdB2CService.isAdmin()); - } - isAdminBasedInGroup(): Observable { return this.userInfoService.isAdmin(); } diff --git a/src/app/modules/home/home.component.spec.ts b/src/app/modules/home/home.component.spec.ts index 234c818d7..d7bf4197e 100644 --- a/src/app/modules/home/home.component.spec.ts +++ b/src/app/modules/home/home.component.spec.ts @@ -1,24 +1,18 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; -import { of } from 'rxjs'; import { AzureAdB2CService } from '../login/services/azure.ad.b2c.service'; -import { FeatureSwitchGroupService } from '../shared/feature-toggles/switch-group/feature-switch-group.service'; import { LoadUser } from '../user/store/user.actions'; import { HomeComponent } from './home.component'; describe('HomeComponent', () => { let component: HomeComponent; let azureAdB2CService: AzureAdB2CService; - let featureSwitchGroupService: FeatureSwitchGroupService; let store: MockStore; let fixture: ComponentFixture; const initialState = {}; const azureB2CServiceStub = { getUserId: () => 'user_id', }; - const featureSwitchGroupServiceStub = { - isActivated: () => of(false), - }; beforeEach( waitForAsync(() => { @@ -27,7 +21,6 @@ describe('HomeComponent', () => { providers: [ provideMockStore({ initialState }), { provide: AzureAdB2CService, useValue: azureB2CServiceStub }, - { provide: FeatureSwitchGroupService, useValue: featureSwitchGroupServiceStub }, ], }).compileComponents(); }) @@ -36,7 +29,6 @@ describe('HomeComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(HomeComponent); azureAdB2CService = TestBed.inject(AzureAdB2CService); - featureSwitchGroupService = TestBed.inject(FeatureSwitchGroupService); store = TestBed.inject(MockStore); component = fixture.componentInstance; @@ -48,32 +40,14 @@ describe('HomeComponent', () => { expect(component).toBeTruthy(); }); - it('onInit, if featureSwitchGroup is true LoadUser action is dispatched', () => { + it('onInit, LoadUser action is dispatched', () => { const userId = 'user_id'; - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(of(true)); spyOn(azureAdB2CService, 'getUserId').and.returnValue(userId); spyOn(store, 'dispatch'); component.ngOnInit(); - featureSwitchGroupService.isActivated().subscribe(() => { - expect(featureSwitchGroupService.isActivated).toHaveBeenCalled(); - expect(azureAdB2CService.getUserId).toHaveBeenCalled(); - expect(store.dispatch).toHaveBeenCalledWith(new LoadUser(userId)); - }); - }); - - it('onInit, if featureSwitchGroup is false nothing happens', () => { - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(of(false)); - spyOn(azureAdB2CService, 'getUserId'); - spyOn(store, 'dispatch'); - - component.ngOnInit(); - - featureSwitchGroupService.isActivated().subscribe(() => { - expect(featureSwitchGroupService.isActivated).toHaveBeenCalled(); - expect(azureAdB2CService.getUserId).not.toHaveBeenCalled(); - expect(store.dispatch).not.toHaveBeenCalled(); - }); + expect(azureAdB2CService.getUserId).toHaveBeenCalled(); + expect(store.dispatch).toHaveBeenCalledWith(new LoadUser(userId)); }); }); diff --git a/src/app/modules/home/home.component.ts b/src/app/modules/home/home.component.ts index cfabf7ced..898d16e29 100644 --- a/src/app/modules/home/home.component.ts +++ b/src/app/modules/home/home.component.ts @@ -1,34 +1,22 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; -import { Subscription } from 'rxjs'; import { LoadUser } from 'src/app/modules/user/store/user.actions'; import { AzureAdB2CService } from '../login/services/azure.ad.b2c.service'; -import { FeatureSwitchGroupService } from '../shared/feature-toggles/switch-group/feature-switch-group.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'], }) -export class HomeComponent implements OnInit, OnDestroy { - FTSwitchGroup$: Subscription; +export class HomeComponent implements OnInit { constructor( - private featureSwitchGroup: FeatureSwitchGroupService, private azureAdB2CService: AzureAdB2CService, private store: Store - ) {} + ) { } ngOnInit(): void { - this.FTSwitchGroup$ = this.featureSwitchGroup.isActivated().subscribe((enabled) => { - if (enabled) { - const userId = this.azureAdB2CService.getUserId(); - this.store.dispatch(new LoadUser(userId)); - } - }); - } - - ngOnDestroy() { - this.FTSwitchGroup$.unsubscribe(); + const userId = this.azureAdB2CService.getUserId(); + this.store.dispatch(new LoadUser(userId)); } } diff --git a/src/app/modules/login/services/azure.ad.b2c.service.ts b/src/app/modules/login/services/azure.ad.b2c.service.ts index 29ba51980..96a9e6d66 100644 --- a/src/app/modules/login/services/azure.ad.b2c.service.ts +++ b/src/app/modules/login/services/azure.ad.b2c.service.ts @@ -2,15 +2,13 @@ import { Injectable } from '@angular/core'; import { UserAgentApplication } from 'msal'; import { from, Observable } from 'rxjs'; import { CookieService } from 'ngx-cookie-service'; - import { AUTHORITY, CLIENT_ID, SCOPES } from '../../../../environments/environment'; -import { FeatureSwitchGroupService } from '../../shared/feature-toggles/switch-group/feature-switch-group.service'; @Injectable({ providedIn: 'root', }) export class AzureAdB2CService { - constructor(private cookieService?: CookieService) {} + constructor(private cookieService?: CookieService) { } msalConfig: any = { auth: { @@ -44,6 +42,7 @@ export class AzureAdB2CService { return this.msal.getAccount().name; } + // TODO: inused method isAdmin() { return this.msal.getAccount()?.idToken?.extension_role === 'time-tracker-admin'; } diff --git a/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts b/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts index d3ece9f1a..dea142b49 100644 --- a/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts +++ b/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts @@ -6,7 +6,6 @@ import { Router, Routes } from '@angular/router'; import { TimeClockComponent } from '../../../time-clock/pages/time-clock.component'; import { of } from 'rxjs'; import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service'; -import { FeatureSwitchGroupService } from '../../feature-toggles/switch-group/feature-switch-group.service'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; describe('SidebarComponent', () => { @@ -14,7 +13,6 @@ describe('SidebarComponent', () => { let fixture: ComponentFixture; let azureAdB2CServiceStubInjected; let featureManagerServiceStubInjected: FeatureManagerService; - let featureSwitchGroupService: FeatureSwitchGroupService; let userInfoService: UserInfoService; let router; const routes: Routes = [{ path: 'time-clock', component: TimeClockComponent }]; @@ -32,17 +30,12 @@ describe('SidebarComponent', () => { isAdmin: () => of(true), }; - const featureSwitchGroupServiceStub = { - isActivated: () => of(true), - }; - beforeEach( waitForAsync(() => { TestBed.configureTestingModule({ declarations: [SidebarComponent], providers: [ { provide: AzureAdB2CService, useValue: azureAdB2CServiceStub }, - { provide: FeatureSwitchGroupService, useValue: featureSwitchGroupServiceStub }, { provide: UserInfoService, useValue: userInfoServiceStub }, ], imports: [RouterTestingModule.withRoutes(routes)], @@ -55,7 +48,6 @@ describe('SidebarComponent', () => { fixture = TestBed.createComponent(SidebarComponent); azureAdB2CServiceStubInjected = TestBed.inject(AzureAdB2CService); featureManagerServiceStubInjected = TestBed.inject(FeatureManagerService); - featureSwitchGroupService = TestBed.inject(FeatureSwitchGroupService); userInfoService = TestBed.inject(UserInfoService); component = fixture.componentInstance; fixture.detectChanges(); @@ -67,8 +59,6 @@ describe('SidebarComponent', () => { }); it('admin users have six menu items', () => { - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(of(true)); - component.getSidebarItems().subscribe(() => { const menuItems = component.itemsSidebar; expect(menuItems.length).toBe(6); @@ -76,7 +66,6 @@ describe('SidebarComponent', () => { }); it('non admin users have two menu items', () => { - spyOn(featureSwitchGroupService, 'isActivated').and.returnValue(of(true)); spyOn(userInfoServiceStub, 'isAdmin').and.returnValue(of(false)); component.getSidebarItems().subscribe(() => { diff --git a/src/app/modules/shared/components/sidebar/sidebar.component.ts b/src/app/modules/shared/components/sidebar/sidebar.component.ts index 4a99757f1..fdf51422f 100644 --- a/src/app/modules/shared/components/sidebar/sidebar.component.ts +++ b/src/app/modules/shared/components/sidebar/sidebar.component.ts @@ -1,12 +1,10 @@ -import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { ItemSidebar } from './models/item-sidebar.model'; import { NavigationStart, Router } from '@angular/router'; -import { Observable, of, Subscription } from 'rxjs'; -import { filter, map, mergeMap } from 'rxjs/operators'; +import { Observable, Subscription } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; -import { FeatureSwitchGroupService } from '../../feature-toggles/switch-group/feature-switch-group.service'; @Component({ selector: 'app-sidebar', @@ -16,14 +14,12 @@ import { FeatureSwitchGroupService } from '../../feature-toggles/switch-group/fe export class SidebarComponent implements OnInit, OnDestroy { itemsSidebar: ItemSidebar[] = []; navStart; - FTSwitchGroup$: Subscription; + sidebarItems$: Subscription; constructor( private router: Router, private userInfoService: UserInfoService, - private azureAdB2CService: AzureAdB2CService, private featureManagerService: FeatureManagerService, - private featureSwitchGroup: FeatureSwitchGroupService ) { this.navStart = this.router.events.pipe( filter((evt) => evt instanceof NavigationStart) @@ -32,7 +28,7 @@ export class SidebarComponent implements OnInit, OnDestroy { ngOnInit(): void { this.toggleSideBar(); - this.FTSwitchGroup$ = this.getSidebarItems().subscribe(); + this.sidebarItems$ = this.getSidebarItems().subscribe(); this.toggleListTechnologies(this.itemsSidebar); this.highlightMenuOption(this.router.routerState.snapshot.url); this.navStart.subscribe((evt) => { @@ -40,7 +36,7 @@ export class SidebarComponent implements OnInit, OnDestroy { }); } ngOnDestroy(): void { - this.FTSwitchGroup$.unsubscribe(); + this.sidebarItems$.unsubscribe(); } toggleSideBar() { @@ -51,12 +47,7 @@ export class SidebarComponent implements OnInit, OnDestroy { } getSidebarItems(): Observable { - const isAdminBasedInRole = of(this.azureAdB2CService.isAdmin()); - const isAdminBasedInGroup = this.userInfoService.isAdmin(); - return this.featureSwitchGroup.isActivated().pipe( - mergeMap((enabled) => { - return enabled ? isAdminBasedInGroup : isAdminBasedInRole; - }), + return this.userInfoService.isAdmin().pipe( map((isAdmin) => { if (isAdmin) { this.itemsSidebar = [ diff --git a/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.spec.ts b/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.spec.ts deleted file mode 100644 index 08817b020..000000000 --- a/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { of } from 'rxjs'; -import { FeatureManagerService } from '../feature-toggle-manager.service'; -import { FeatureSwitchGroupService } from './feature-switch-group.service'; - -describe('FeatureSwitchGroupService', () => { - let service: FeatureSwitchGroupService; - let featureManagerService: FeatureManagerService; - - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [{ provide: FeatureManagerService }], - }); - service = TestBed.inject(FeatureSwitchGroupService); - featureManagerService = TestBed.inject(FeatureManagerService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); - - const params = [{ bool: false }, { bool: true }]; - params.map((param) => { - it(`isActivated should return a boolean ${param.bool}`, () => { - const toggleName = 'toggle_switch_test'; - // tslint:disable-next-line: no-shadowed-variable - featureManagerService.isToggleEnabledForUser = (toggleName) => of(param.bool); - - service.isActivated().subscribe((enabled) => { - expect(enabled).toBe(param.bool); - }); - }); - }); -}); diff --git a/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.ts b/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.ts deleted file mode 100644 index 987485aea..000000000 --- a/src/app/modules/shared/feature-toggles/switch-group/feature-switch-group.service.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { TOGGLES } from 'src/environments/environment'; -import { FeatureManagerService } from '../feature-toggle-manager.service'; - -@Injectable({ - providedIn: 'root', -}) -export class FeatureSwitchGroupService { - constructor(private FTManager: FeatureManagerService) {} - isActivated(): Observable { - return this.FTManager.isToggleEnabledForUser(TOGGLES.SWITCH_GROUP); - } -} diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b0c5aaf4a..5b04fe66e 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -22,9 +22,6 @@ export const GROUPS = { ADMIN: 'time-tracker-admin', TESTER: 'time-tracker-tester', }; -export const TOGGLES = { - SWITCH_GROUP: 'switch-group', -}; /* * For easier debugging in development mode, you can import the following file From a2d388cae4a368dfdc45e6d103bd040562455f8b Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Wed, 28 Apr 2021 17:01:12 -0500 Subject: [PATCH 2/2] fix: TT-229 remove code from users-list.component & user ngrx store --- .../users-list/users-list.component.html | 43 ++----- .../users-list/users-list.component.spec.ts | 120 +----------------- .../users-list/users-list.component.ts | 36 +----- .../modules/users/store/user.actions.spec.ts | 36 ------ src/app/modules/users/store/user.actions.ts | 58 ++------- .../modules/users/store/user.effects.spec.ts | 54 -------- src/app/modules/users/store/user.effects.ts | 38 +----- ....reducer.spec.ts => user.reducers.spec.ts} | 64 ---------- src/app/modules/users/store/user.reducers.ts | 51 -------- 9 files changed, 25 insertions(+), 475 deletions(-) rename src/app/modules/users/store/{user.reducer.spec.ts => user.reducers.spec.ts} (60%) diff --git a/src/app/modules/users/components/users-list/users-list.component.html b/src/app/modules/users/components/users-list/users-list.component.html index 498d5e0dd..5fad7083a 100644 --- a/src/app/modules/users/components/users-list/users-list.component.html +++ b/src/app/modules/users/components/users-list/users-list.component.html @@ -10,7 +10,7 @@ User Email Names - {{ isUserGroupsToggleOn ? 'Groups' : 'Roles' }} + Groups @@ -19,35 +19,18 @@ {{ user.email }} {{ user.name }} -
- - admin - - test -
- -
- - admin - - test -
+ + admin + + test diff --git a/src/app/modules/users/components/users-list/users-list.component.spec.ts b/src/app/modules/users/components/users-list/users-list.component.spec.ts index efdc37085..c248db7cf 100644 --- a/src/app/modules/users/components/users-list/users-list.component.spec.ts +++ b/src/app/modules/users/components/users-list/users-list.component.spec.ts @@ -1,4 +1,3 @@ -import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service'; import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; import { NgxPaginationModule } from 'ngx-pagination'; @@ -7,28 +6,17 @@ import { UserActionTypes, UserState, LoadUsers, - GrantRoleUser, - RevokeRoleUser, AddUserToGroup, RemoveUserFromGroup, } from '../../store'; -import { User } from '../../../user/models/user'; import { ActionsSubject } from '@ngrx/store'; import { DataTablesModule } from 'angular-datatables'; -import { Observable, of } from 'rxjs'; -import { FeatureToggleProvider } from 'src/app/modules/shared/feature-toggles/feature-toggle-provider.service'; -import { AppConfigurationClient } from '@azure/app-configuration'; -import { FeatureFilterProvider } from '../../../shared/feature-toggles/filters/feature-filter-provider.service'; -import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service'; describe('UsersListComponent', () => { let component: UsersListComponent; let fixture: ComponentFixture; let store: MockStore; const actionSub: ActionsSubject = new ActionsSubject(); - const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret'; - let service: FeatureManagerService; - let fakeFeatureToggleProvider; const state: UserState = { data: [ @@ -48,19 +36,12 @@ describe('UsersListComponent', () => { beforeEach( waitForAsync(() => { - fakeFeatureToggleProvider = new FeatureToggleProvider( - new AppConfigurationClient(fakeAppConfigurationConnectionString), - new FeatureFilterProvider(new AzureAdB2CService()) - ); - service = new FeatureManagerService(fakeFeatureToggleProvider); - TestBed.configureTestingModule({ imports: [NgxPaginationModule, DataTablesModule], declarations: [UsersListComponent], providers: [ provideMockStore({ initialState: state }), { provide: ActionsSubject, useValue: actionSub }, - { provide: FeatureManagerService, useValue: service } ], }).compileComponents(); }) @@ -98,27 +79,6 @@ describe('UsersListComponent', () => { expect(component.users).toEqual(state.data); }); - const actionsParams = [ - { actionType: UserActionTypes.GRANT_USER_ROLE_SUCCESS }, - { actionType: UserActionTypes.REVOKE_USER_ROLE_SUCCESS }, - ]; - - actionsParams.map((param) => { - it(`When action ${param.actionType} is dispatched should triggered load Users action`, () => { - spyOn(store, 'dispatch'); - - const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; - const action = { - type: param.actionType, - payload: state.data, - }; - - actionSubject.next(action); - - expect(store.dispatch).toHaveBeenCalledWith(new LoadUsers()); - }); - }); - const actionGroupParams = [ { actionType: UserActionTypes.ADD_USER_TO_GROUP_SUCCESS }, { actionType: UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS }, @@ -140,26 +100,6 @@ describe('UsersListComponent', () => { }); }); - const grantRoleTypes = [ - { roleId: 'admin', roleValue: 'time-tracker-admin' }, - { roleId: 'test', roleValue: 'time-tracker-tester' }, - ]; - - grantRoleTypes.map((param) => { - it(`When user switchRole to ${param.roleId} and don't have any role, should grant ${param.roleValue} Role`, () => { - const roleId = param.roleId; - const roleValue = param.roleValue; - const userRoles = []; - const userId = 'userId'; - - spyOn(store, 'dispatch'); - - component.switchRole(userId, userRoles, roleId, roleValue); - - expect(store.dispatch).toHaveBeenCalledWith(new GrantRoleUser(userId, roleId)); - }); - }); - const AddGroupTypes = [ { groupName: 'time-tracker-admin' }, { groupName: 'time-tracker-tester' } @@ -176,7 +116,7 @@ describe('UsersListComponent', () => { id: 'id', tenant_id: 'tenant id', deleted: 'delete', - } ; + }; spyOn(store, 'dispatch'); @@ -186,26 +126,6 @@ describe('UsersListComponent', () => { }); }); - const revokeRoleTypes = [ - { roleId: 'admin', roleValue: 'time-tracker-admin', userRoles: ['time-tracker-admin'] }, - { roleId: 'test', roleValue: 'time-tracker-tester', userRoles: ['time-tracker-tester'] }, - ]; - - revokeRoleTypes.map((param) => { - it(`When user switchRole to ${param.roleId} and have that rol asigned, should revoke ${param.roleValue} Role`, () => { - const roleId = param.roleId; - const roleValue = param.roleValue; - const userRoles = param.userRoles; - const userId = 'userId'; - - spyOn(store, 'dispatch'); - - component.switchRole(userId, userRoles, roleId, roleValue); - - expect(store.dispatch).toHaveBeenCalledWith(new RevokeRoleUser(userId, roleId)); - }); - }); - const removeGroupTypes = [ { groupName: 'time-tracker-admin', userGroups: ['time-tracker-admin'] }, { groupName: 'time-tracker-tester', userGroups: ['time-tracker-tester'] }, @@ -222,8 +142,7 @@ describe('UsersListComponent', () => { id: 'id', tenant_id: 'tenant id', deleted: 'delete', - } ; - + }; spyOn(store, 'dispatch'); @@ -233,20 +152,6 @@ describe('UsersListComponent', () => { }); }); - it('on success load users, the data of roles should be an array', () => { - const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; - const action = { - type: UserActionTypes.LOAD_USERS_SUCCESS, - payload: state.data, - }; - - actionSubject.next(action); - - component.users.map((user) => { - expect(user.roles).toEqual(['admin', 'test']); - }); - }); - it('on success load users, the data of groups should be an array', () => { const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; const action = { @@ -274,27 +179,6 @@ describe('UsersListComponent', () => { expect(component.dtElement.dtInstance.then).toHaveBeenCalled(); }); - it('When Component is created, should call the feature toggle method', () => { - spyOn(component, 'isFeatureToggleActivated').and.returnValue(of(true)); - - component.ngOnInit(); - - expect(component.isFeatureToggleActivated).toHaveBeenCalled(); - expect(component.isUserGroupsToggleOn).toBe(true); - }); - - const toggleValues = [true, false]; - toggleValues.map((toggleValue) => { - it(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => { - spyOn(service, 'isToggleEnabledForUser').and.returnValue(of(toggleValue)); - - const isFeatureToggleActivated: Observable = component.isFeatureToggleActivated(); - - expect(service.isToggleEnabledForUser).toHaveBeenCalled(); - isFeatureToggleActivated.subscribe((value) => expect(value).toEqual(toggleValue)); - }); - }); - afterEach(() => { component.dtTrigger.unsubscribe(); component.loadUsersSubscription.unsubscribe(); diff --git a/src/app/modules/users/components/users-list/users-list.component.ts b/src/app/modules/users/components/users-list/users-list.component.ts index 33ef09035..152c8e4ec 100644 --- a/src/app/modules/users/components/users-list/users-list.component.ts +++ b/src/app/modules/users/components/users-list/users-list.component.ts @@ -2,13 +2,10 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular import { ActionsSubject, select, Store, Action } from '@ngrx/store'; import { DataTableDirective } from 'angular-datatables'; import { Observable, Subject, Subscription } from 'rxjs'; -import { delay, filter, map } from 'rxjs/operators'; -import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service'; +import { delay, filter } from 'rxjs/operators'; import { User } from '../../models/users'; import { - GrantRoleUser, LoadUsers, - RevokeRoleUser, UserActionTypes, AddUserToGroup, RemoveUserFromGroup, @@ -30,13 +27,10 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { dtElement: DataTableDirective; dtOptions: any = {}; switchGroupsSubscription: Subscription; - isEnableToggleSubscription: Subscription; - isUserGroupsToggleOn: boolean; constructor( private store: Store, private actionsSubject$: ActionsSubject, - private featureManagerService: FeatureManagerService ) { this.isLoading$ = store.pipe(delay(0), select(getIsLoading)); } @@ -50,25 +44,9 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { this.rerenderDataTable(); }); - this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => { - this.isUserGroupsToggleOn = flag; - }); - this.switchGroupsSubscription = this.filterUserGroup().subscribe((action) => { this.store.dispatch(new LoadUsers()); }); - - this.switchRoleSubscription = this.actionsSubject$ - .pipe( - filter( - (action: any) => - action.type === UserActionTypes.GRANT_USER_ROLE_SUCCESS || - action.type === UserActionTypes.REVOKE_USER_ROLE_SUCCESS - ) - ) - .subscribe((action) => { - this.store.dispatch(new LoadUsers()); - }); } ngAfterViewInit(): void { @@ -78,7 +56,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { ngOnDestroy() { this.loadUsersSubscription.unsubscribe(); this.dtTrigger.unsubscribe(); - this.isEnableToggleSubscription.unsubscribe(); } private rerenderDataTable(): void { @@ -92,12 +69,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { } } - switchRole(userId: string, userRoles: string[], roleId: string, roleValue: string) { - userRoles.includes(roleValue) - ? this.store.dispatch(new RevokeRoleUser(userId, roleId)) - : this.store.dispatch(new GrantRoleUser(userId, roleId)); - } - switchGroup(groupName: string, user: User): void { this.store.dispatch( user.groups.includes(groupName) @@ -106,11 +77,6 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { ); } - isFeatureToggleActivated(): Observable { - return this.featureManagerService.isToggleEnabledForUser('switch-group') - .pipe(map((enabled: boolean) => enabled)); - } - filterUserGroup(): Observable { return this.actionsSubject$.pipe( filter( diff --git a/src/app/modules/users/store/user.actions.spec.ts b/src/app/modules/users/store/user.actions.spec.ts index ae1bb933f..72adfbd62 100644 --- a/src/app/modules/users/store/user.actions.spec.ts +++ b/src/app/modules/users/store/user.actions.spec.ts @@ -17,42 +17,6 @@ describe('UserActions', () => { expect(action.type).toEqual(actions.UserActionTypes.LOAD_USERS_FAIL); }); - it('GrantRoleUser type is UserActionTypes.GRANT_USER_ROLE', () => { - const UserId = 'UserId'; - const RoleId = 'RoleId'; - const action = new actions.GrantRoleUser(UserId, RoleId); - expect(action.type).toEqual(actions.UserActionTypes.GRANT_USER_ROLE); - }); - - it('GrantRoleUserSuccess type is UserActionTypes.GRANT_USER_ROLE_SUCCESS', () => { - const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.GrantRoleUserSuccess(payload); - expect(action.type).toEqual(actions.UserActionTypes.GRANT_USER_ROLE_SUCCESS); - }); - - it('GrantRoleUserFail type is UserActionTypes.GRANT_USER_ROLE_FAIL', () => { - const action = new actions.GrantRoleUserFail('error'); - expect(action.type).toEqual(actions.UserActionTypes.GRANT_USER_ROLE_FAIL); - }); - - it('RevokeRoleUser type is UserActionTypes.REVOKE_USER_ROLE', () => { - const UserId = 'UserId'; - const RoleId = 'RoleId'; - const action = new actions.RevokeRoleUser(UserId, RoleId); - expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE); - }); - - it('RevokeRoleUserSuccess type is UserActionTypes.REVOKE_USER_ROLE_SUCCESS', () => { - const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.RevokeRoleUserSuccess(payload); - expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_SUCCESS); - }); - - it('RevokeRoleUserFail type is UserActionTypes.REVOKE_USER_ROLE_FAIL', () => { - const action = new actions.RevokeRoleUserFail('error'); - expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_FAIL); - }); - it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { const userId = 'userId'; const groupName = 'groupName'; diff --git a/src/app/modules/users/store/user.actions.ts b/src/app/modules/users/store/user.actions.ts index 674fff5af..41f5b50df 100644 --- a/src/app/modules/users/store/user.actions.ts +++ b/src/app/modules/users/store/user.actions.ts @@ -5,12 +5,6 @@ export enum UserActionTypes { LOAD_USERS = '[User] LOAD_USERS', LOAD_USERS_SUCCESS = '[User] LOAD_USERS_SUCCESS', LOAD_USERS_FAIL = '[User] LOAD_USERS_FAIL', - GRANT_USER_ROLE = '[User] GRANT_USER_ROLE', - GRANT_USER_ROLE_SUCCESS = '[User] GRANT_USER_ROLE_SUCCESS', - GRANT_USER_ROLE_FAIL = '[User] GRANT_USER_ROLE_FAIL', - REVOKE_USER_ROLE = '[User] REVOKE_USER_ROLE', - REVOKE_USER_ROLE_SUCCESS = '[User] REVOKE_USER_ROLE_SUCCESS', - REVOKE_USER_ROLE_FAIL = '[User] REVOKE_USER_ROLE_FAIL', ADD_USER_TO_GROUP = '[User] ADD_USER_TO_GROUP', ADD_USER_TO_GROUP_SUCCESS = '[User] ADD_USER_TO_GROUP_SUCCESS', ADD_USER_TO_GROUP_FAIL = '[User] ADD_USER_TO_GROUP_FAIL', @@ -26,72 +20,42 @@ export class LoadUsers implements Action { export class LoadUsersSuccess implements Action { readonly type = UserActionTypes.LOAD_USERS_SUCCESS; - constructor(readonly payload: User[]) {} + constructor(readonly payload: User[]) { } } export class LoadUsersFail implements Action { public readonly type = UserActionTypes.LOAD_USERS_FAIL; - constructor(public error: string) {} -} - -export class GrantRoleUser implements Action { - public readonly type = UserActionTypes.GRANT_USER_ROLE; - constructor(public userId: string, public roleId: string) {} -} - -export class GrantRoleUserSuccess implements Action { - public readonly type = UserActionTypes.GRANT_USER_ROLE_SUCCESS; - constructor(public payload: User) {} -} - -export class GrantRoleUserFail implements Action { - public readonly type = UserActionTypes.GRANT_USER_ROLE_FAIL; - constructor(public error: string) {} -} - -export class RevokeRoleUser implements Action { - public readonly type = UserActionTypes.REVOKE_USER_ROLE; - constructor(public userId: string, public roleId: string) {} -} - -export class RevokeRoleUserSuccess implements Action { - public readonly type = UserActionTypes.REVOKE_USER_ROLE_SUCCESS; - constructor(public payload: User) {} -} - -export class RevokeRoleUserFail implements Action { - public readonly type = UserActionTypes.REVOKE_USER_ROLE_FAIL; - constructor(public error: string) {} + constructor(public error: string) { } } export class AddUserToGroup implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP; - constructor(public userId: string, public groupName: string) {} + constructor(public userId: string, public groupName: string) { } } export class AddUserToGroupSuccess implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP_SUCCESS; - constructor(readonly payload: User) {} + constructor(readonly payload: User) { } } export class AddUserToGroupFail implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP_FAIL; - constructor(public error: string) {} + constructor(public error: string) { } } export class RemoveUserFromGroup implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP; - constructor(public userId: string, public groupName: string) {} + constructor(public userId: string, public groupName: string) { } } export class RemoveUserFromGroupSuccess implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS; - constructor(readonly payload: User) {} + constructor(readonly payload: User) { } } export class RemoveUserFromGroupFail implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL; - constructor(public error: string) {} + constructor(public error: string) { } } export class DefaultUser implements Action { @@ -103,12 +67,6 @@ export type UserActions = | LoadUsersSuccess | LoadUsersFail | DefaultUser - | GrantRoleUser - | GrantRoleUserSuccess - | GrantRoleUserFail - | RevokeRoleUser - | RevokeRoleUserSuccess - | RevokeRoleUserFail | AddUserToGroup | AddUserToGroupSuccess | AddUserToGroupFail diff --git a/src/app/modules/users/store/user.effects.spec.ts b/src/app/modules/users/store/user.effects.spec.ts index 8aea60311..75fd31d4c 100644 --- a/src/app/modules/users/store/user.effects.spec.ts +++ b/src/app/modules/users/store/user.effects.spec.ts @@ -52,60 +52,6 @@ describe('UserEffects', () => { }); }); - it('action type is GRANT_USER_ROLE_SUCCESS when service is executed sucessfully', async () => { - const userId = 'userId'; - const roleId = 'roleId'; - actions$ = of({ type: UserActionTypes.GRANT_USER_ROLE, userId, roleId }); - const serviceSpy = spyOn(service, 'grantRole'); - spyOn(toastrService, 'success'); - serviceSpy.and.returnValue(of(user)); - - effects.grantUserRole$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Grant User Role Success'); - expect(action.type).toEqual(UserActionTypes.GRANT_USER_ROLE_SUCCESS); - }); - }); - - it('action type is GRANT_USER_ROLE_FAIL when service is executed and fail', async () => { - const userId = 'userId'; - const roleId = 'roleId'; - actions$ = of({ type: UserActionTypes.GRANT_USER_ROLE, userId, roleId }); - spyOn(service, 'grantRole').and.returnValue(throwError({ error: { message: 'error' } })); - spyOn(toastrService, 'error'); - - effects.grantUserRole$.subscribe((action) => { - expect(toastrService.error).toHaveBeenCalled(); - expect(action.type).toEqual(UserActionTypes.GRANT_USER_ROLE_FAIL); - }); - }); - - it('action type is REVOKE_USER_ROLE_SUCCESS when service is executed sucessfully', async () => { - const userId = 'userId'; - const roleId = 'roleId'; - actions$ = of({ type: UserActionTypes.REVOKE_USER_ROLE, userId, roleId }); - const serviceSpy = spyOn(service, 'revokeRole'); - spyOn(toastrService, 'success'); - serviceSpy.and.returnValue(of(user)); - - effects.revokeUserRole$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Revoke User Role Success'); - expect(action.type).toEqual(UserActionTypes.REVOKE_USER_ROLE_SUCCESS); - }); - }); - - it('action type is REVOKE_USER_ROLE_FAIL when service is executed and fail', async () => { - const userId = 'userId'; - const roleId = 'roleId'; - actions$ = of({ type: UserActionTypes.REVOKE_USER_ROLE, userId, roleId }); - spyOn(service, 'revokeRole').and.returnValue(throwError({ error: { message: 'error' } })); - spyOn(toastrService, 'error'); - - effects.revokeUserRole$.subscribe((action) => { - expect(toastrService.error).toHaveBeenCalled(); - expect(action.type).toEqual(UserActionTypes.REVOKE_USER_ROLE_FAIL); - }); - }); - it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { const userId = 'userId'; const groupName = 'groupName'; diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 613b18456..4669058ba 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -10,7 +10,7 @@ import * as actions from './user.actions'; @Injectable() export class UserEffects { - constructor(private actions$: Actions, private userService: UsersService, private toastrService: ToastrService) {} + constructor(private actions$: Actions, private userService: UsersService, private toastrService: ToastrService) { } @Effect() loadUsers$: Observable = this.actions$.pipe( @@ -28,42 +28,6 @@ export class UserEffects { ) ); - @Effect() - grantUserRole$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.GRANT_USER_ROLE), - map((action: actions.GrantRoleUser) => action), - mergeMap((action) => - this.userService.grantRole(action.userId, action.roleId).pipe( - map((response) => { - this.toastrService.success('Grant User Role Success'); - return new actions.GrantRoleUserSuccess(response); - }), - catchError((error) => { - this.toastrService.error(error.error.message); - return of(new actions.GrantRoleUserFail(error)); - }) - ) - ) - ); - - @Effect() - revokeUserRole$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.REVOKE_USER_ROLE), - map((action: actions.RevokeRoleUser) => action), - mergeMap((action) => - this.userService.revokeRole(action.userId, action.roleId).pipe( - map((response) => { - this.toastrService.success('Revoke User Role Success'); - return new actions.RevokeRoleUserSuccess(response); - }), - catchError((error) => { - this.toastrService.error(error.error.message); - return of(new actions.RevokeRoleUserFail(error)); - }) - ) - ) - ); - @Effect() addUserToGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), diff --git a/src/app/modules/users/store/user.reducer.spec.ts b/src/app/modules/users/store/user.reducers.spec.ts similarity index 60% rename from src/app/modules/users/store/user.reducer.spec.ts rename to src/app/modules/users/store/user.reducers.spec.ts index 6180cfff4..2fe736610 100644 --- a/src/app/modules/users/store/user.reducer.spec.ts +++ b/src/app/modules/users/store/user.reducers.spec.ts @@ -29,70 +29,6 @@ describe('userReducer', () => { expect(state.data.length).toBe(0); }); - it('on GrantUserRole, isLoading is true', () => { - const userId = 'userId'; - const roleId = 'roleId'; - const action = new actions.GrantRoleUser(userId, roleId); - const state = userReducer(initialState, action); - - expect(state.isLoading).toEqual(true); - }); - - it('on GrantRoleUserSuccess, user roles should change', () => { - const currentState: UserState = { - data: [{ id: 'id', name: 'name', email: 'email', roles: null }], - isLoading: false, - message: '', - }; - const userGranted: User = { id: 'id', name: 'name', email: 'email', roles: ['admin'] }; - const action = new actions.GrantRoleUserSuccess(userGranted); - const state = userReducer(currentState, action); - - expect(state.data).toEqual([userGranted]); - expect(state.isLoading).toEqual(false); - expect(state.message).toEqual('Grant User Role Success'); - }); - - it('on GrantRoleUserFail, should show a message with an error message', () => { - const action = new actions.GrantRoleUserFail('error'); - const state = userReducer(initialState, action); - - expect(state.message).toEqual('Something went wrong granting user role'); - expect(state.isLoading).toEqual(false); - }); - - it('on RevokeUserRole, isLoading is true', () => { - const userId = 'userId'; - const roleId = 'roleId'; - const action = new actions.RevokeRoleUser(userId, roleId); - const state = userReducer(initialState, action); - - expect(state.isLoading).toEqual(true); - }); - - it('on RevokeRoleUserSuccess, user roles should change', () => { - const currentState: UserState = { - data: [{ id: 'id', name: 'name', email: 'email', roles: ['admin'] }], - isLoading: false, - message: '', - }; - const userRevoked: User = { id: 'id', name: 'name', email: 'email', roles: null }; - const action = new actions.RevokeRoleUserSuccess(userRevoked); - const state = userReducer(currentState, action); - - expect(state.data).toEqual([userRevoked]); - expect(state.isLoading).toEqual(false); - expect(state.message).toEqual('Revoke User Role Success'); - }); - - it('on RevokeRoleUserFail, should show a message with an error message', () => { - const action = new actions.RevokeRoleUserFail('error'); - const state = userReducer(initialState, action); - - expect(state.message).toEqual('Something went wrong revoking user role'); - expect(state.isLoading).toEqual(false); - }); - it('on AddUserToGroup, isLoading is true', () => { const userId = 'userId'; const groupName = 'groupName'; diff --git a/src/app/modules/users/store/user.reducers.ts b/src/app/modules/users/store/user.reducers.ts index 8a1c75443..440f61ce6 100644 --- a/src/app/modules/users/store/user.reducers.ts +++ b/src/app/modules/users/store/user.reducers.ts @@ -37,57 +37,6 @@ export const userReducer = (state: UserState = initialState, action: UserActions message: action.error, }; } - - case UserActionTypes.GRANT_USER_ROLE: { - return { - ...state, - isLoading: true, - }; - } - case UserActionTypes.GRANT_USER_ROLE_SUCCESS: { - const index = userData.findIndex((user) => user.id === action.payload.id); - userData[index] = action.payload; - return { - ...state, - data: userData, - isLoading: false, - message: 'Grant User Role Success', - }; - } - case UserActionTypes.GRANT_USER_ROLE_FAIL: { - return { - ...state, - data: state.data, - isLoading: false, - message: 'Something went wrong granting user role', - }; - } - - case UserActionTypes.REVOKE_USER_ROLE: { - return { - ...state, - isLoading: true, - }; - } - case UserActionTypes.REVOKE_USER_ROLE_SUCCESS: { - const index = userData.findIndex((user) => user.id === action.payload.id); - userData[index] = action.payload; - return { - ...state, - data: userData, - isLoading: false, - message: 'Revoke User Role Success', - }; - } - case UserActionTypes.REVOKE_USER_ROLE_FAIL: { - return { - ...state, - data: state.data, - isLoading: false, - message: 'Something went wrong revoking user role', - }; - } - case UserActionTypes.ADD_USER_TO_GROUP: { return { ...state,