From 5785bc5d5b4b52bd1308f76dbe691a8ec20c0638 Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Wed, 24 Mar 2021 16:01:20 -0500 Subject: [PATCH 1/7] feat: TT-188 add & remove groups to user service --- src/app/modules/users/models/users.ts | 5 +++++ .../modules/users/services/users.service.spec.ts | 16 ++++++++++++++++ src/app/modules/users/services/users.service.ts | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/src/app/modules/users/models/users.ts b/src/app/modules/users/models/users.ts index 604b84970..a87183dda 100644 --- a/src/app/modules/users/models/users.ts +++ b/src/app/modules/users/models/users.ts @@ -7,3 +7,8 @@ export interface User { tenant_id?: string; deleted?: string; } + +export interface UserState extends User { + isLoading: boolean; + error: string; +} diff --git a/src/app/modules/users/services/users.service.spec.ts b/src/app/modules/users/services/users.service.spec.ts index d8d50dbd9..32a30d215 100644 --- a/src/app/modules/users/services/users.service.spec.ts +++ b/src/app/modules/users/services/users.service.spec.ts @@ -52,22 +52,38 @@ describe('UsersService', () => { expect(grantRoleRequest.request.method).toBe('POST'); }); +<<<<<<< HEAD it('add user to group', () => { +======= + it('add group to a User', () => { +>>>>>>> feat: TT-188 add & remove groups to user service const userId = 'userId'; const group = 'admin'; const addGroupURL = `${service.baseUrl}/${userId}/groups/add`; +<<<<<<< HEAD service.addUserToGroup(userId, group).subscribe(); +======= + service.addGroupToUser(userId, group).subscribe(); +>>>>>>> feat: TT-188 add & remove groups to user service expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST'); }); +<<<<<<< HEAD it('remove user from group', () => { +======= + it('remove group to a User', () => { +>>>>>>> feat: TT-188 add & remove groups to user service const userId = 'userId'; const group = 'admin'; const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`; +<<<<<<< HEAD service.removeUserFromGroup(userId, group).subscribe(); +======= + service.removeGroupToUser(userId, group).subscribe(); +>>>>>>> feat: TT-188 add & remove groups to user service expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST'); }); diff --git a/src/app/modules/users/services/users.service.ts b/src/app/modules/users/services/users.service.ts index 40e97fec3..751672443 100644 --- a/src/app/modules/users/services/users.service.ts +++ b/src/app/modules/users/services/users.service.ts @@ -25,13 +25,21 @@ export class UsersService { return this.http.post(url, null); } +<<<<<<< HEAD addUserToGroup(userId: string, group: string): Observable { +======= + addGroupToUser(userId: string, group: string): Observable { +>>>>>>> feat: TT-188 add & remove groups to user service return this.http.post(`${this.baseUrl}/${userId}/groups/add`, { group_name: group, }); } +<<<<<<< HEAD removeUserFromGroup(userId: string, group: string): Observable { +======= + removeGroupToUser(userId: string, group: string): Observable { +>>>>>>> feat: TT-188 add & remove groups to user service return this.http.post(`${this.baseUrl}/${userId}/groups/remove`, { group_name: group, }); From 2409eeb7887536b968178ae5faf406900224cd2c Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Wed, 24 Mar 2021 18:50:59 -0500 Subject: [PATCH 2/7] feat: TT-188 add ngrx flow & test --- src/app/modules/users/models/users.ts | 5 -- .../modules/users/store/user.actions.spec.ts | 43 +++++++++++++ src/app/modules/users/store/user.actions.ts | 48 ++++++++++++++ .../modules/users/store/user.effects.spec.ts | 64 +++++++++++++++++++ src/app/modules/users/store/user.effects.ts | 30 +++++++++ .../modules/users/store/user.reducer.spec.ts | 52 +++++++++++++++ src/app/modules/users/store/user.reducers.ts | 38 +++++++++++ 7 files changed, 275 insertions(+), 5 deletions(-) diff --git a/src/app/modules/users/models/users.ts b/src/app/modules/users/models/users.ts index a87183dda..604b84970 100644 --- a/src/app/modules/users/models/users.ts +++ b/src/app/modules/users/models/users.ts @@ -7,8 +7,3 @@ export interface User { tenant_id?: string; deleted?: string; } - -export interface UserState extends User { - isLoading: boolean; - error: string; -} diff --git a/src/app/modules/users/store/user.actions.spec.ts b/src/app/modules/users/store/user.actions.spec.ts index ae1bb933f..c962880c0 100644 --- a/src/app/modules/users/store/user.actions.spec.ts +++ b/src/app/modules/users/store/user.actions.spec.ts @@ -53,6 +53,7 @@ describe('UserActions', () => { expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_FAIL); }); +<<<<<<< HEAD it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { const userId = 'userId'; const groupName = 'groupName'; @@ -93,5 +94,47 @@ describe('UserActions', () => { const action = new actions.RemoveUserFromGroupFail('error'); expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); +======= + it('AddGroupToUser type is UserActionTypes.ADD_GROUP_TO_USER', () => { + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.AddGroupToUser(userId, groupName); + + expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER); + }); + + it('AddGroupToUserSuccess type is UserActionTypes.ADD_GROUP_TO_USER_SUCCESS', () => { + const payload: User = { id: 'id', email: 'email', name: 'name' }; + const action = new actions.AddGroupToUserSuccess(payload); + + expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER_SUCCESS); + }); + + it('AddGroupToUserFail type is UserActionTypes.ADD_GROUP_TO_USER_FAIL', () => { + const action = new actions.AddGroupToUserFail('error'); + + expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER_FAIL); + }); + + it('RemoveGroupToUser type is UserActionTypes.REMOVE_GROUP_TO_USER', () => { + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.RemoveGroupToUser(userId, groupName); + + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER); + }); + + it('RemoveGroupToUserSuccess type is UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS', () => { + const payload: User = { id: 'id', email: 'email', name: 'name' }; + const action = new actions.RemoveGroupToUserSuccess(payload); + + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS); + }); + + it('RemoveGroupToUserFail type is UserActionTypes.REMOVE_GROUP_TO_USER_FAIL', () => { + const action = new actions.RemoveGroupToUserFail('error'); + + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); +>>>>>>> feat: TT-188 add ngrx flow & test }); }); diff --git a/src/app/modules/users/store/user.actions.ts b/src/app/modules/users/store/user.actions.ts index 674fff5af..5543c11de 100644 --- a/src/app/modules/users/store/user.actions.ts +++ b/src/app/modules/users/store/user.actions.ts @@ -11,12 +11,21 @@ export enum UserActionTypes { 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', +<<<<<<< HEAD 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', REMOVE_USER_FROM_GROUP = '[User] REMOVE_USER_FROM_GROUP', REMOVE_USER_FROM_GROUP_SUCCESS = '[User] REMOVE_USER_FROM_GROUP_SUCCESS', REMOVE_USER_FROM_GROUP_FAIL = '[User] REMOVE_USER_FROM_GROUP_FAIL', +======= + ADD_GROUP_TO_USER = '[User] ADD_GROUP_TO_USER', + ADD_GROUP_TO_USER_SUCCESS = '[User] ADD_GROUP_TO_USER_SUCCESS', + ADD_GROUP_TO_USER_FAIL = '[User] ADD_GROUP_TO_USER_FAIL', + REMOVE_GROUP_TO_USER = '[User] REMOVE_GROUP_TO_USER', + REMOVE_GROUP_TO_USER_SUCCESS = '[User] REMOVE_GROUP_TO_USER_SUCCESS', + REMOVE_GROUP_TO_USER_FAIL = '[User] REMOVE_GROUP_TO_USER_FAIL', +>>>>>>> feat: TT-188 add ngrx flow & test DEFAULT_USER = '[USER] DEFAULT_USER', } @@ -64,6 +73,7 @@ export class RevokeRoleUserFail implements Action { constructor(public error: string) {} } +<<<<<<< HEAD export class AddUserToGroup implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP; constructor(public userId: string, public groupName: string) {} @@ -91,6 +101,35 @@ export class RemoveUserFromGroupSuccess implements Action { export class RemoveUserFromGroupFail implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL; +======= +export class AddGroupToUser implements Action { + public readonly type = UserActionTypes.ADD_GROUP_TO_USER; + constructor(public userId: string, public groupName: string) {} +} + +export class AddGroupToUserSuccess implements Action { + public readonly type = UserActionTypes.ADD_GROUP_TO_USER_SUCCESS; + constructor(readonly payload: User) {} +} + +export class AddGroupToUserFail implements Action { + public readonly type = UserActionTypes.ADD_GROUP_TO_USER_FAIL; + constructor(public error: string) {} +} + +export class RemoveGroupToUser implements Action { + public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER; + constructor(public userId: string, public groupName: string) {} +} + +export class RemoveGroupToUserSuccess implements Action { + public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS; + constructor(readonly payload: User) {} +} + +export class RemoveGroupToUserFail implements Action { + public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_FAIL; +>>>>>>> feat: TT-188 add ngrx flow & test constructor(public error: string) {} } @@ -109,9 +148,18 @@ export type UserActions = | RevokeRoleUser | RevokeRoleUserSuccess | RevokeRoleUserFail +<<<<<<< HEAD | AddUserToGroup | AddUserToGroupSuccess | AddUserToGroupFail | RemoveUserFromGroup | RemoveUserFromGroupSuccess | RemoveUserFromGroupFail; +======= + | AddGroupToUser + | AddGroupToUserSuccess + | AddGroupToUserFail + | RemoveGroupToUser + | RemoveGroupToUserSuccess + | RemoveGroupToUserFail; +>>>>>>> feat: TT-188 add ngrx flow & test diff --git a/src/app/modules/users/store/user.effects.spec.ts b/src/app/modules/users/store/user.effects.spec.ts index 8aea60311..4fffa2518 100644 --- a/src/app/modules/users/store/user.effects.spec.ts +++ b/src/app/modules/users/store/user.effects.spec.ts @@ -106,16 +106,25 @@ describe('UserEffects', () => { }); }); +<<<<<<< HEAD it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.ADD_USER_TO_GROUP, +======= + it('action type is ADD_GROUP_TO_USER_SUCCESS when service is executed sucessfully', async () => { + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.ADD_GROUP_TO_USER, +>>>>>>> feat: TT-188 add ngrx flow & test userId, groupName, }); spyOn(toastrService, 'success'); +<<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(of(user)); effects.addUserToGroup$.subscribe((action) => { @@ -129,11 +138,27 @@ describe('UserEffects', () => { const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.ADD_USER_TO_GROUP, +======= + spyOn(service, 'addGroupToUser').and.returnValue(of(user)); + + effects.addGroupToUser$.subscribe((action) => { + expect(toastrService.success).toHaveBeenCalledWith('Add group to a user success'); + expect(action.type).toEqual(UserActionTypes.ADD_GROUP_TO_USER_SUCCESS); + }); + }); + + it('action type is ADD_GROUP_TO_USER_FAIL when service is executed and fail', async () => { + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.ADD_GROUP_TO_USER, +>>>>>>> feat: TT-188 add ngrx flow & test userId, groupName, }); spyOn(toastrService, 'error'); +<<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); effects.addUserToGroup$.subscribe((action) => { @@ -147,11 +172,27 @@ describe('UserEffects', () => { const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.REMOVE_USER_FROM_GROUP, +======= + spyOn(service, 'addGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); + + effects.addGroupToUser$.subscribe((action) => { + expect(toastrService.error).toHaveBeenCalled(); + expect(action.type).toEqual(UserActionTypes.ADD_GROUP_TO_USER_FAIL); + }); + }); + + it('action type is REMOVE_GROUP_TO_USER_SUCCESS when service is executed succesfully', async () => { + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.REMOVE_GROUP_TO_USER, +>>>>>>> feat: TT-188 add ngrx flow & test userId, groupName, }); spyOn(toastrService, 'success'); +<<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); effects.removeUserFromGroup$.subscribe((action) => { @@ -165,16 +206,39 @@ describe('UserEffects', () => { const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.REMOVE_USER_FROM_GROUP, +======= + spyOn(service, 'removeGroupToUser').and.returnValue(of(user)); + + effects.removeGroupToUser$.subscribe((action) => { + expect(toastrService.success).toHaveBeenCalledWith('Remove group to a user success'); + expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS); + }); + }); + + it('action type is REMOVE_GROUP_TO_USER_FAIL when service is executed succesfully', async () => { + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.REMOVE_GROUP_TO_USER, +>>>>>>> feat: TT-188 add ngrx flow & test userId, groupName, }); spyOn(toastrService, 'error'); +<<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); effects.removeUserFromGroup$.subscribe((action) => { expect(toastrService.error).toHaveBeenCalled(); expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); +======= + spyOn(service, 'removeGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); + + effects.removeGroupToUser$.subscribe((action) => { + expect(toastrService.error).toHaveBeenCalled(); + expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); +>>>>>>> feat: TT-188 add ngrx flow & test }); }); }); diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 613b18456..9df2b4700 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -65,6 +65,7 @@ export class UserEffects { ); @Effect() +<<<<<<< HEAD addUserToGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), map((action: actions.AddUserToGroup) => action), @@ -77,12 +78,27 @@ export class UserEffects { catchError((error) => { this.toastrService.error(error.error.message); return of(new actions.AddUserToGroupFail(error)); +======= + addGroupToUser$: Observable = this.actions$.pipe( + ofType(actions.UserActionTypes.ADD_GROUP_TO_USER), + map((action: actions.AddGroupToUser) => action), + mergeMap((action) => + this.userService.addGroupToUser(action.userId, action.groupName).pipe( + map((response) => { + this.toastrService.success('Add group to a user success'); + return new actions.AddGroupToUserSuccess(response); + }), + catchError((error) => { + this.toastrService.error(error.error.message); + return of(new actions.AddGroupToUserFail(error)); +>>>>>>> feat: TT-188 add ngrx flow & test }) ) ) ); @Effect() +<<<<<<< HEAD removeUserFromGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), map((action: actions.RemoveUserFromGroup) => action), @@ -95,6 +111,20 @@ export class UserEffects { catchError((error) => { this.toastrService.error(error.error.message); return of(new actions.RemoveUserFromGroupFail(error)); +======= + removeGroupToUser$: Observable = this.actions$.pipe( + ofType(actions.UserActionTypes.REMOVE_GROUP_TO_USER), + map((action: actions.RemoveGroupToUser) => action), + mergeMap((action) => + this.userService.removeGroupToUser(action.userId, action.groupName).pipe( + map((response) => { + this.toastrService.success('Remove group to a user success'); + return new actions.RemoveGroupToUserSuccess(response); + }), + catchError((error) => { + this.toastrService.error(error.error.message); + return of(new actions.RemoveGroupToUserFail(error)); +>>>>>>> feat: TT-188 add ngrx flow & test }) ) ) diff --git a/src/app/modules/users/store/user.reducer.spec.ts b/src/app/modules/users/store/user.reducer.spec.ts index 6180cfff4..61f5d8b5a 100644 --- a/src/app/modules/users/store/user.reducer.spec.ts +++ b/src/app/modules/users/store/user.reducer.spec.ts @@ -93,27 +93,43 @@ describe('userReducer', () => { expect(state.isLoading).toEqual(false); }); +<<<<<<< HEAD it('on AddUserToGroup, isLoading is true', () => { const userId = 'userId'; const groupName = 'groupName'; const action = new actions.AddUserToGroup(userId, groupName); +======= + it('on AddGroupToUser, isLoading is true', () => { + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.AddGroupToUser(userId, groupName); +>>>>>>> feat: TT-188 add ngrx flow & test const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); +<<<<<<< HEAD it('on AddUserToGroupSuccess, user groups should change', () => { +======= + it('on AddGroupToUserSuccess, user groups should change', () => { +>>>>>>> feat: TT-188 add ngrx flow & test const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: null }], isLoading: false, message: '', }; const userWithGroupAdded: User = { id: 'id', name: 'name', email: 'email', groups: ['group'] }; +<<<<<<< HEAD const action = new actions.AddUserToGroupSuccess(userWithGroupAdded); +======= + const action = new actions.AddGroupToUserSuccess(userWithGroupAdded); +>>>>>>> feat: TT-188 add ngrx flow & test const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupAdded]); expect(state.isLoading).toEqual(false); +<<<<<<< HEAD expect(state.message).toEqual('Add user to group success'); }); @@ -129,23 +145,49 @@ describe('userReducer', () => { const userId = 'userId'; const groupName = 'groupName'; const action = new actions.RemoveUserFromGroup(userId, groupName); +======= + expect(state.message).toEqual('Add group to a user success'); + }); + + it('on AddGroupToUserFail, should show a message with an error message', () => { + const action = new actions.AddGroupToUserFail('error'); + const state = userReducer(initialState, action); + + expect(state.message).toEqual('Something went wrong adding group to a user'); + expect(state.isLoading).toEqual(false); + }); + + it('on RemoveGroupToUser, isLoading is true', () => { + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.RemoveGroupToUser(userId, groupName); +>>>>>>> feat: TT-188 add ngrx flow & test const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); +<<<<<<< HEAD it('on RemoveUserFromGroupSuccess, user groups should change', () => { +======= + it('on RemoveGroupToUserSuccess, user groups should change', () => { +>>>>>>> feat: TT-188 add ngrx flow & test const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: ['group'] }], isLoading: false, message: '', }; const userWithGroupRemoved: User = { id: 'id', name: 'name', email: 'email', groups: null }; +<<<<<<< HEAD const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); +======= + const action = new actions.RemoveGroupToUserSuccess(userWithGroupRemoved); +>>>>>>> feat: TT-188 add ngrx flow & test const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupRemoved]); expect(state.isLoading).toEqual(false); +<<<<<<< HEAD expect(state.message).toEqual('Remove user from group success'); }); @@ -154,6 +196,16 @@ describe('userReducer', () => { const state = userReducer(initialState, action); expect(state.message).toEqual('Something went wrong removing user from group'); +======= + expect(state.message).toEqual('Remove group to a user success'); + }); + + it('on RemoveGroupToUserFail, should show a message with an error message', () => { + const action = new actions.RemoveGroupToUserFail('error'); + const state = userReducer(initialState, action); + + expect(state.message).toEqual('Something went wrong removing group to a user'); +>>>>>>> feat: TT-188 add ngrx flow & test expect(state.isLoading).toEqual(false); }); diff --git a/src/app/modules/users/store/user.reducers.ts b/src/app/modules/users/store/user.reducers.ts index 8a1c75443..27dda8453 100644 --- a/src/app/modules/users/store/user.reducers.ts +++ b/src/app/modules/users/store/user.reducers.ts @@ -88,18 +88,27 @@ export const userReducer = (state: UserState = initialState, action: UserActions }; } +<<<<<<< HEAD case UserActionTypes.ADD_USER_TO_GROUP: { +======= + case UserActionTypes.ADD_GROUP_TO_USER: { +>>>>>>> feat: TT-188 add ngrx flow & test return { ...state, isLoading: true, }; } +<<<<<<< HEAD case UserActionTypes.ADD_USER_TO_GROUP_SUCCESS: { +======= + case UserActionTypes.ADD_GROUP_TO_USER_SUCCESS: { +>>>>>>> feat: TT-188 add ngrx flow & test const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, +<<<<<<< HEAD message: 'Add user to group success', }; } @@ -112,17 +121,36 @@ export const userReducer = (state: UserState = initialState, action: UserActions } case UserActionTypes.REMOVE_USER_FROM_GROUP: { +======= + message: 'Add group to a user success', + }; + } + case UserActionTypes.ADD_GROUP_TO_USER_FAIL: { + return { + ...state, + isLoading: false, + message: 'Something went wrong adding group to a user', + }; + } + + case UserActionTypes.REMOVE_GROUP_TO_USER: { +>>>>>>> feat: TT-188 add ngrx flow & test return { ...state, isLoading: true, }; } +<<<<<<< HEAD case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { +======= + case UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS: { +>>>>>>> feat: TT-188 add ngrx flow & test const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, +<<<<<<< HEAD message: 'Remove user from group success', }; } @@ -131,6 +159,16 @@ export const userReducer = (state: UserState = initialState, action: UserActions ...state, isLoading: false, message: 'Something went wrong removing user from group', +======= + message: 'Remove group to a user success', + }; + } + case UserActionTypes.REMOVE_GROUP_TO_USER_FAIL: { + return { + ...state, + isLoading: false, + message: 'Something went wrong removing group to a user', +>>>>>>> feat: TT-188 add ngrx flow & test }; } default: From bf896361891aab895fca9f289a60fa98170e86f3 Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Thu, 25 Mar 2021 15:09:06 -0500 Subject: [PATCH 3/7] refactor: TT-188 refactor some names --- .../users/services/users.service.spec.ts | 8 +++ .../modules/users/services/users.service.ts | 8 +++ .../modules/users/store/user.actions.spec.ts | 40 +++++++----- src/app/modules/users/store/user.actions.ts | 44 ++++++++++--- .../modules/users/store/user.effects.spec.ts | 64 +++++++++++++++---- src/app/modules/users/store/user.effects.ts | 32 ++++++++-- .../modules/users/store/user.reducer.spec.ts | 51 +++++++++++++-- src/app/modules/users/store/user.reducers.ts | 34 +++++++++- 8 files changed, 230 insertions(+), 51 deletions(-) diff --git a/src/app/modules/users/services/users.service.spec.ts b/src/app/modules/users/services/users.service.spec.ts index 32a30d215..92bfc50e2 100644 --- a/src/app/modules/users/services/users.service.spec.ts +++ b/src/app/modules/users/services/users.service.spec.ts @@ -61,11 +61,15 @@ describe('UsersService', () => { const group = 'admin'; const addGroupURL = `${service.baseUrl}/${userId}/groups/add`; +<<<<<<< HEAD <<<<<<< HEAD service.addUserToGroup(userId, group).subscribe(); ======= service.addGroupToUser(userId, group).subscribe(); >>>>>>> feat: TT-188 add & remove groups to user service +======= + service.addUserToGroup(userId, group).subscribe(); +>>>>>>> refactor: TT-188 refactor some names expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST'); }); @@ -79,11 +83,15 @@ describe('UsersService', () => { const group = 'admin'; const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`; +<<<<<<< HEAD <<<<<<< HEAD service.removeUserFromGroup(userId, group).subscribe(); ======= service.removeGroupToUser(userId, group).subscribe(); >>>>>>> feat: TT-188 add & remove groups to user service +======= + service.removeUserToGroup(userId, group).subscribe(); +>>>>>>> refactor: TT-188 refactor some names expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST'); }); diff --git a/src/app/modules/users/services/users.service.ts b/src/app/modules/users/services/users.service.ts index 751672443..de15d8321 100644 --- a/src/app/modules/users/services/users.service.ts +++ b/src/app/modules/users/services/users.service.ts @@ -25,21 +25,29 @@ export class UsersService { return this.http.post(url, null); } +<<<<<<< HEAD <<<<<<< HEAD addUserToGroup(userId: string, group: string): Observable { ======= addGroupToUser(userId: string, group: string): Observable { >>>>>>> feat: TT-188 add & remove groups to user service +======= + addUserToGroup(userId: string, group: string): Observable { +>>>>>>> refactor: TT-188 refactor some names return this.http.post(`${this.baseUrl}/${userId}/groups/add`, { group_name: group, }); } +<<<<<<< HEAD <<<<<<< HEAD removeUserFromGroup(userId: string, group: string): Observable { ======= removeGroupToUser(userId: string, group: string): Observable { >>>>>>> feat: TT-188 add & remove groups to user service +======= + removeUserToGroup(userId: string, group: string): Observable { +>>>>>>> refactor: TT-188 refactor some names return this.http.post(`${this.baseUrl}/${userId}/groups/remove`, { group_name: group, }); diff --git a/src/app/modules/users/store/user.actions.spec.ts b/src/app/modules/users/store/user.actions.spec.ts index c962880c0..ac5eecb0c 100644 --- a/src/app/modules/users/store/user.actions.spec.ts +++ b/src/app/modules/users/store/user.actions.spec.ts @@ -53,6 +53,7 @@ describe('UserActions', () => { expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_FAIL); }); +<<<<<<< HEAD <<<<<<< HEAD it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { const userId = 'userId'; @@ -96,45 +97,52 @@ describe('UserActions', () => { expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); ======= it('AddGroupToUser type is UserActionTypes.ADD_GROUP_TO_USER', () => { +======= + it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { +>>>>>>> refactor: TT-188 refactor some names const userId = 'userId'; const groupName = 'groupName'; - const action = new actions.AddGroupToUser(userId, groupName); + const action = new actions.AddUserToGroup(userId, groupName); - expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER); + expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP); }); - it('AddGroupToUserSuccess type is UserActionTypes.ADD_GROUP_TO_USER_SUCCESS', () => { + it('AddUserToGroupSuccess type is UserActionTypes.ADD_USER_TO_GROUP_SUCCESS', () => { const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.AddGroupToUserSuccess(payload); + const action = new actions.AddUserToGroupSuccess(payload); - expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER_SUCCESS); + expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP_SUCCESS); }); - it('AddGroupToUserFail type is UserActionTypes.ADD_GROUP_TO_USER_FAIL', () => { - const action = new actions.AddGroupToUserFail('error'); + it('AddUserToGroupFail type is UserActionTypes.ADD_USER_TO_GROUP_FAIL', () => { + const action = new actions.AddUserToGroupFail('error'); - expect(action.type).toEqual(actions.UserActionTypes.ADD_GROUP_TO_USER_FAIL); + expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP_FAIL); }); - it('RemoveGroupToUser type is UserActionTypes.REMOVE_GROUP_TO_USER', () => { + it('RemoveUserToGroup type is UserActionTypes.REMOVE_USER_TO_GROUP', () => { const userId = 'userId'; const groupName = 'groupName'; - const action = new actions.RemoveGroupToUser(userId, groupName); + const action = new actions.RemoveUserToGroup(userId, groupName); - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER); + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP); }); - it('RemoveGroupToUserSuccess type is UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS', () => { + it('RemoveUserToGroupSuccess type is UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS', () => { const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.RemoveGroupToUserSuccess(payload); + const action = new actions.RemoveUserToGroupSuccess(payload); - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS); + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS); }); - it('RemoveGroupToUserFail type is UserActionTypes.REMOVE_GROUP_TO_USER_FAIL', () => { - const action = new actions.RemoveGroupToUserFail('error'); + it('RemoveUserToGroupFail type is UserActionTypes.REMOVE_USER_TO_GROUP_FAIL', () => { + const action = new actions.RemoveUserToGroupFail('error'); +<<<<<<< HEAD expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); >>>>>>> feat: TT-188 add ngrx flow & test +======= + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); +>>>>>>> refactor: TT-188 refactor some names }); }); diff --git a/src/app/modules/users/store/user.actions.ts b/src/app/modules/users/store/user.actions.ts index 5543c11de..13c9dc88c 100644 --- a/src/app/modules/users/store/user.actions.ts +++ b/src/app/modules/users/store/user.actions.ts @@ -11,6 +11,7 @@ export enum UserActionTypes { 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', +<<<<<<< HEAD <<<<<<< HEAD ADD_USER_TO_GROUP = '[User] ADD_USER_TO_GROUP', ADD_USER_TO_GROUP_SUCCESS = '[User] ADD_USER_TO_GROUP_SUCCESS', @@ -26,6 +27,14 @@ export enum UserActionTypes { REMOVE_GROUP_TO_USER_SUCCESS = '[User] REMOVE_GROUP_TO_USER_SUCCESS', REMOVE_GROUP_TO_USER_FAIL = '[User] REMOVE_GROUP_TO_USER_FAIL', >>>>>>> feat: TT-188 add ngrx flow & test +======= + 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', + REMOVE_USER_TO_GROUP = '[User] REMOVE_USER_TO_GROUP', + REMOVE_USER_TO_GROUP_SUCCESS = '[User] REMOVE_USER_TO_GROUP_SUCCESS', + REMOVE_USER_TO_GROUP_FAIL = '[User] REMOVE_USER_TO_GROUP_FAIL', +>>>>>>> refactor: TT-188 refactor some names DEFAULT_USER = '[USER] DEFAULT_USER', } @@ -73,6 +82,7 @@ export class RevokeRoleUserFail implements Action { constructor(public error: string) {} } +<<<<<<< HEAD <<<<<<< HEAD export class AddUserToGroup implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP; @@ -104,32 +114,41 @@ export class RemoveUserFromGroupFail implements Action { ======= export class AddGroupToUser implements Action { public readonly type = UserActionTypes.ADD_GROUP_TO_USER; +======= +export class AddUserToGroup implements Action { + public readonly type = UserActionTypes.ADD_USER_TO_GROUP; +>>>>>>> refactor: TT-188 refactor some names constructor(public userId: string, public groupName: string) {} } -export class AddGroupToUserSuccess implements Action { - public readonly type = UserActionTypes.ADD_GROUP_TO_USER_SUCCESS; +export class AddUserToGroupSuccess implements Action { + public readonly type = UserActionTypes.ADD_USER_TO_GROUP_SUCCESS; constructor(readonly payload: User) {} } -export class AddGroupToUserFail implements Action { - public readonly type = UserActionTypes.ADD_GROUP_TO_USER_FAIL; +export class AddUserToGroupFail implements Action { + public readonly type = UserActionTypes.ADD_USER_TO_GROUP_FAIL; constructor(public error: string) {} } -export class RemoveGroupToUser implements Action { - public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER; +export class RemoveUserToGroup implements Action { + public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP; constructor(public userId: string, public groupName: string) {} } -export class RemoveGroupToUserSuccess implements Action { - public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS; +export class RemoveUserToGroupSuccess implements Action { + public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS; constructor(readonly payload: User) {} } +<<<<<<< HEAD export class RemoveGroupToUserFail implements Action { public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_FAIL; >>>>>>> feat: TT-188 add ngrx flow & test +======= +export class RemoveUserToGroupFail implements Action { + public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_FAIL; +>>>>>>> refactor: TT-188 refactor some names constructor(public error: string) {} } @@ -148,6 +167,7 @@ export type UserActions = | RevokeRoleUser | RevokeRoleUserSuccess | RevokeRoleUserFail +<<<<<<< HEAD <<<<<<< HEAD | AddUserToGroup | AddUserToGroupSuccess @@ -163,3 +183,11 @@ export type UserActions = | RemoveGroupToUserSuccess | RemoveGroupToUserFail; >>>>>>> feat: TT-188 add ngrx flow & test +======= + | AddUserToGroup + | AddUserToGroupSuccess + | AddUserToGroupFail + | RemoveUserToGroup + | RemoveUserToGroupSuccess + | RemoveUserToGroupFail; +>>>>>>> refactor: TT-188 refactor some names diff --git a/src/app/modules/users/store/user.effects.spec.ts b/src/app/modules/users/store/user.effects.spec.ts index 4fffa2518..65d8cc0f4 100644 --- a/src/app/modules/users/store/user.effects.spec.ts +++ b/src/app/modules/users/store/user.effects.spec.ts @@ -106,6 +106,7 @@ describe('UserEffects', () => { }); }); +<<<<<<< HEAD <<<<<<< HEAD it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { const userId = 'userId'; @@ -119,11 +120,19 @@ describe('UserEffects', () => { actions$ = of({ type: UserActionTypes.ADD_GROUP_TO_USER, >>>>>>> feat: TT-188 add ngrx flow & test +======= + it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.ADD_USER_TO_GROUP, +>>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'success'); +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(of(user)); @@ -140,24 +149,32 @@ describe('UserEffects', () => { type: UserActionTypes.ADD_USER_TO_GROUP, ======= spyOn(service, 'addGroupToUser').and.returnValue(of(user)); +======= + spyOn(service, 'addUserToGroup').and.returnValue(of(user)); +>>>>>>> refactor: TT-188 refactor some names - effects.addGroupToUser$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Add group to a user success'); - expect(action.type).toEqual(UserActionTypes.ADD_GROUP_TO_USER_SUCCESS); + effects.addUserToGroup$.subscribe((action) => { + expect(toastrService.success).toHaveBeenCalledWith('Add user to group success'); + expect(action.type).toEqual(UserActionTypes.ADD_USER_TO_GROUP_SUCCESS); }); }); - it('action type is ADD_GROUP_TO_USER_FAIL when service is executed and fail', async () => { + it('action type is ADD_USER_TO_GROUP_FAIL when service is executed and fail', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ +<<<<<<< HEAD type: UserActionTypes.ADD_GROUP_TO_USER, >>>>>>> feat: TT-188 add ngrx flow & test +======= + type: UserActionTypes.ADD_USER_TO_GROUP, +>>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'error'); +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); @@ -174,24 +191,32 @@ describe('UserEffects', () => { type: UserActionTypes.REMOVE_USER_FROM_GROUP, ======= spyOn(service, 'addGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); +======= + spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); +>>>>>>> refactor: TT-188 refactor some names - effects.addGroupToUser$.subscribe((action) => { + effects.addUserToGroup$.subscribe((action) => { expect(toastrService.error).toHaveBeenCalled(); - expect(action.type).toEqual(UserActionTypes.ADD_GROUP_TO_USER_FAIL); + expect(action.type).toEqual(UserActionTypes.ADD_USER_TO_GROUP_FAIL); }); }); - it('action type is REMOVE_GROUP_TO_USER_SUCCESS when service is executed succesfully', async () => { + it('action type is REMOVE_USER_TO_GROUP_SUCCESS when service is executed succesfully', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ +<<<<<<< HEAD type: UserActionTypes.REMOVE_GROUP_TO_USER, >>>>>>> feat: TT-188 add ngrx flow & test +======= + type: UserActionTypes.REMOVE_USER_TO_GROUP, +>>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'success'); +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); @@ -208,24 +233,32 @@ describe('UserEffects', () => { type: UserActionTypes.REMOVE_USER_FROM_GROUP, ======= spyOn(service, 'removeGroupToUser').and.returnValue(of(user)); +======= + spyOn(service, 'removeUserToGroup').and.returnValue(of(user)); +>>>>>>> refactor: TT-188 refactor some names - effects.removeGroupToUser$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Remove group to a user success'); - expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS); + effects.removeUserToGroup$.subscribe((action) => { + expect(toastrService.success).toHaveBeenCalledWith('Remove user to group success'); + expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS); }); }); - it('action type is REMOVE_GROUP_TO_USER_FAIL when service is executed succesfully', async () => { + it('action type is REMOVE_USER_TO_GROUP_FAIL when service is executed succesfully', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ +<<<<<<< HEAD type: UserActionTypes.REMOVE_GROUP_TO_USER, >>>>>>> feat: TT-188 add ngrx flow & test +======= + type: UserActionTypes.REMOVE_USER_TO_GROUP, +>>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'error'); +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); @@ -234,11 +267,18 @@ describe('UserEffects', () => { expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); ======= spyOn(service, 'removeGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); +======= + spyOn(service, 'removeUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); +>>>>>>> refactor: TT-188 refactor some names - effects.removeGroupToUser$.subscribe((action) => { + effects.removeUserToGroup$.subscribe((action) => { expect(toastrService.error).toHaveBeenCalled(); +<<<<<<< HEAD expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); >>>>>>> feat: TT-188 add ngrx flow & test +======= + expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); +>>>>>>> refactor: TT-188 refactor some names }); }); }); diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 9df2b4700..7c5ccff04 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -65,6 +65,7 @@ export class UserEffects { ); @Effect() +<<<<<<< HEAD <<<<<<< HEAD addUserToGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), @@ -82,22 +83,32 @@ export class UserEffects { addGroupToUser$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.ADD_GROUP_TO_USER), map((action: actions.AddGroupToUser) => action), +======= + addUserToGroup$: Observable = this.actions$.pipe( + ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), + map((action: actions.AddUserToGroup) => action), +>>>>>>> refactor: TT-188 refactor some names mergeMap((action) => - this.userService.addGroupToUser(action.userId, action.groupName).pipe( + this.userService.addUserToGroup(action.userId, action.groupName).pipe( map((response) => { - this.toastrService.success('Add group to a user success'); - return new actions.AddGroupToUserSuccess(response); + this.toastrService.success('Add user to group success'); + return new actions.AddUserToGroupSuccess(response); }), catchError((error) => { this.toastrService.error(error.error.message); +<<<<<<< HEAD return of(new actions.AddGroupToUserFail(error)); >>>>>>> feat: TT-188 add ngrx flow & test +======= + return of(new actions.AddUserToGroupFail(error)); +>>>>>>> refactor: TT-188 refactor some names }) ) ) ); @Effect() +<<<<<<< HEAD <<<<<<< HEAD removeUserFromGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), @@ -115,16 +126,25 @@ export class UserEffects { removeGroupToUser$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.REMOVE_GROUP_TO_USER), map((action: actions.RemoveGroupToUser) => action), +======= + removeUserToGroup$: Observable = this.actions$.pipe( + ofType(actions.UserActionTypes.REMOVE_USER_TO_GROUP), + map((action: actions.RemoveUserToGroup) => action), +>>>>>>> refactor: TT-188 refactor some names mergeMap((action) => - this.userService.removeGroupToUser(action.userId, action.groupName).pipe( + this.userService.removeUserToGroup(action.userId, action.groupName).pipe( map((response) => { - this.toastrService.success('Remove group to a user success'); - return new actions.RemoveGroupToUserSuccess(response); + this.toastrService.success('Remove user to group success'); + return new actions.RemoveUserToGroupSuccess(response); }), catchError((error) => { this.toastrService.error(error.error.message); +<<<<<<< HEAD return of(new actions.RemoveGroupToUserFail(error)); >>>>>>> feat: TT-188 add ngrx flow & test +======= + return of(new actions.RemoveUserToGroupFail(error)); +>>>>>>> refactor: TT-188 refactor some names }) ) ) diff --git a/src/app/modules/users/store/user.reducer.spec.ts b/src/app/modules/users/store/user.reducer.spec.ts index 61f5d8b5a..6be89563f 100644 --- a/src/app/modules/users/store/user.reducer.spec.ts +++ b/src/app/modules/users/store/user.reducer.spec.ts @@ -93,6 +93,7 @@ describe('userReducer', () => { expect(state.isLoading).toEqual(false); }); +<<<<<<< HEAD <<<<<<< HEAD it('on AddUserToGroup, isLoading is true', () => { const userId = 'userId'; @@ -104,31 +105,46 @@ describe('userReducer', () => { const groupName = 'groupName'; const action = new actions.AddGroupToUser(userId, groupName); >>>>>>> feat: TT-188 add ngrx flow & test +======= + it('on AddUserToGroup, isLoading is true', () => { + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.AddUserToGroup(userId, groupName); +>>>>>>> refactor: TT-188 refactor some names const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); +<<<<<<< HEAD <<<<<<< HEAD it('on AddUserToGroupSuccess, user groups should change', () => { ======= it('on AddGroupToUserSuccess, user groups should change', () => { >>>>>>> feat: TT-188 add ngrx flow & test +======= + it('on AddUserToGroupSuccess, user groups should change', () => { +>>>>>>> refactor: TT-188 refactor some names const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: null }], isLoading: false, message: '', }; const userWithGroupAdded: User = { id: 'id', name: 'name', email: 'email', groups: ['group'] }; +<<<<<<< HEAD <<<<<<< HEAD const action = new actions.AddUserToGroupSuccess(userWithGroupAdded); ======= const action = new actions.AddGroupToUserSuccess(userWithGroupAdded); >>>>>>> feat: TT-188 add ngrx flow & test +======= + const action = new actions.AddUserToGroupSuccess(userWithGroupAdded); +>>>>>>> refactor: TT-188 refactor some names const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupAdded]); expect(state.isLoading).toEqual(false); +<<<<<<< HEAD <<<<<<< HEAD expect(state.message).toEqual('Add user to group success'); }); @@ -147,46 +163,62 @@ describe('userReducer', () => { const action = new actions.RemoveUserFromGroup(userId, groupName); ======= expect(state.message).toEqual('Add group to a user success'); +======= + expect(state.message).toEqual('Add user to group success'); +>>>>>>> refactor: TT-188 refactor some names }); - it('on AddGroupToUserFail, should show a message with an error message', () => { - const action = new actions.AddGroupToUserFail('error'); + it('on AddUserToGroupFail, should show a message with an error message', () => { + const action = new actions.AddUserToGroupFail('error'); const state = userReducer(initialState, action); - expect(state.message).toEqual('Something went wrong adding group to a user'); + expect(state.message).toEqual('Something went wrong adding user to group'); expect(state.isLoading).toEqual(false); }); - it('on RemoveGroupToUser, isLoading is true', () => { + it('on RemoveUserToGroup, isLoading is true', () => { const userId = 'userId'; const groupName = 'groupName'; +<<<<<<< HEAD const action = new actions.RemoveGroupToUser(userId, groupName); >>>>>>> feat: TT-188 add ngrx flow & test +======= + const action = new actions.RemoveUserToGroup(userId, groupName); +>>>>>>> refactor: TT-188 refactor some names const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); +<<<<<<< HEAD <<<<<<< HEAD it('on RemoveUserFromGroupSuccess, user groups should change', () => { ======= it('on RemoveGroupToUserSuccess, user groups should change', () => { >>>>>>> feat: TT-188 add ngrx flow & test +======= + it('on RemoveUserToGroupSuccess, user groups should change', () => { +>>>>>>> refactor: TT-188 refactor some names const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: ['group'] }], isLoading: false, message: '', }; const userWithGroupRemoved: User = { id: 'id', name: 'name', email: 'email', groups: null }; +<<<<<<< HEAD <<<<<<< HEAD const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); ======= const action = new actions.RemoveGroupToUserSuccess(userWithGroupRemoved); >>>>>>> feat: TT-188 add ngrx flow & test +======= + const action = new actions.RemoveUserToGroupSuccess(userWithGroupRemoved); +>>>>>>> refactor: TT-188 refactor some names const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupRemoved]); expect(state.isLoading).toEqual(false); +<<<<<<< HEAD <<<<<<< HEAD expect(state.message).toEqual('Remove user from group success'); }); @@ -198,14 +230,21 @@ describe('userReducer', () => { expect(state.message).toEqual('Something went wrong removing user from group'); ======= expect(state.message).toEqual('Remove group to a user success'); +======= + expect(state.message).toEqual('Remove user to group success'); +>>>>>>> refactor: TT-188 refactor some names }); - it('on RemoveGroupToUserFail, should show a message with an error message', () => { - const action = new actions.RemoveGroupToUserFail('error'); + it('on RemoveUserToGroupFail, should show a message with an error message', () => { + const action = new actions.RemoveUserToGroupFail('error'); const state = userReducer(initialState, action); +<<<<<<< HEAD expect(state.message).toEqual('Something went wrong removing group to a user'); >>>>>>> feat: TT-188 add ngrx flow & test +======= + expect(state.message).toEqual('Something went wrong removing user to group'); +>>>>>>> refactor: TT-188 refactor some names expect(state.isLoading).toEqual(false); }); diff --git a/src/app/modules/users/store/user.reducers.ts b/src/app/modules/users/store/user.reducers.ts index 27dda8453..20cb58da6 100644 --- a/src/app/modules/users/store/user.reducers.ts +++ b/src/app/modules/users/store/user.reducers.ts @@ -88,26 +88,35 @@ export const userReducer = (state: UserState = initialState, action: UserActions }; } +<<<<<<< HEAD <<<<<<< HEAD case UserActionTypes.ADD_USER_TO_GROUP: { ======= case UserActionTypes.ADD_GROUP_TO_USER: { >>>>>>> feat: TT-188 add ngrx flow & test +======= + case UserActionTypes.ADD_USER_TO_GROUP: { +>>>>>>> refactor: TT-188 refactor some names return { ...state, isLoading: true, }; } +<<<<<<< HEAD <<<<<<< HEAD case UserActionTypes.ADD_USER_TO_GROUP_SUCCESS: { ======= case UserActionTypes.ADD_GROUP_TO_USER_SUCCESS: { >>>>>>> feat: TT-188 add ngrx flow & test +======= + case UserActionTypes.ADD_USER_TO_GROUP_SUCCESS: { +>>>>>>> refactor: TT-188 refactor some names const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, +<<<<<<< HEAD <<<<<<< HEAD message: 'Add user to group success', }; @@ -123,33 +132,45 @@ export const userReducer = (state: UserState = initialState, action: UserActions case UserActionTypes.REMOVE_USER_FROM_GROUP: { ======= message: 'Add group to a user success', +======= + message: 'Add user to group success', +>>>>>>> refactor: TT-188 refactor some names }; } - case UserActionTypes.ADD_GROUP_TO_USER_FAIL: { + case UserActionTypes.ADD_USER_TO_GROUP_FAIL: { return { ...state, isLoading: false, - message: 'Something went wrong adding group to a user', + message: 'Something went wrong adding user to group', }; } +<<<<<<< HEAD case UserActionTypes.REMOVE_GROUP_TO_USER: { >>>>>>> feat: TT-188 add ngrx flow & test +======= + case UserActionTypes.REMOVE_USER_TO_GROUP: { +>>>>>>> refactor: TT-188 refactor some names return { ...state, isLoading: true, }; } +<<<<<<< HEAD <<<<<<< HEAD case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { ======= case UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS: { >>>>>>> feat: TT-188 add ngrx flow & test +======= + case UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS: { +>>>>>>> refactor: TT-188 refactor some names const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, +<<<<<<< HEAD <<<<<<< HEAD message: 'Remove user from group success', }; @@ -161,14 +182,21 @@ export const userReducer = (state: UserState = initialState, action: UserActions message: 'Something went wrong removing user from group', ======= message: 'Remove group to a user success', +======= + message: 'Remove user to group success', +>>>>>>> refactor: TT-188 refactor some names }; } - case UserActionTypes.REMOVE_GROUP_TO_USER_FAIL: { + case UserActionTypes.REMOVE_USER_TO_GROUP_FAIL: { return { ...state, isLoading: false, +<<<<<<< HEAD message: 'Something went wrong removing group to a user', >>>>>>> feat: TT-188 add ngrx flow & test +======= + message: 'Something went wrong removing user to group', +>>>>>>> refactor: TT-188 refactor some names }; } default: From dc4ebbc94b60fb1a554fba83c09327ac3188ad4a Mon Sep 17 00:00:00 2001 From: thegreatyamori Date: Thu, 25 Mar 2021 19:08:28 -0500 Subject: [PATCH 4/7] refactor: TT-188 refactor 'removeTo' to 'removeFrom' references --- .../users/services/users.service.spec.ts | 12 +++++++ .../modules/users/services/users.service.ts | 4 +++ .../modules/users/store/user.actions.spec.ts | 21 ++++++++---- src/app/modules/users/store/user.actions.ts | 24 ++++++++++++-- .../modules/users/store/user.effects.spec.ts | 33 ++++++++++++++++--- src/app/modules/users/store/user.effects.ts | 16 +++++++-- .../modules/users/store/user.reducer.spec.ts | 26 +++++++++++++-- src/app/modules/users/store/user.reducers.ts | 18 +++++++++- 8 files changed, 134 insertions(+), 20 deletions(-) diff --git a/src/app/modules/users/services/users.service.spec.ts b/src/app/modules/users/services/users.service.spec.ts index 92bfc50e2..9d421a6c1 100644 --- a/src/app/modules/users/services/users.service.spec.ts +++ b/src/app/modules/users/services/users.service.spec.ts @@ -52,11 +52,15 @@ describe('UsersService', () => { expect(grantRoleRequest.request.method).toBe('POST'); }); +<<<<<<< HEAD <<<<<<< HEAD it('add user to group', () => { ======= it('add group to a User', () => { >>>>>>> feat: TT-188 add & remove groups to user service +======= + it('add user to group', () => { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const userId = 'userId'; const group = 'admin'; const addGroupURL = `${service.baseUrl}/${userId}/groups/add`; @@ -74,15 +78,20 @@ describe('UsersService', () => { expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST'); }); +<<<<<<< HEAD <<<<<<< HEAD it('remove user from group', () => { ======= it('remove group to a User', () => { >>>>>>> feat: TT-188 add & remove groups to user service +======= + it('remove user from group', () => { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const userId = 'userId'; const group = 'admin'; const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`; +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD service.removeUserFromGroup(userId, group).subscribe(); @@ -92,6 +101,9 @@ describe('UsersService', () => { ======= service.removeUserToGroup(userId, group).subscribe(); >>>>>>> refactor: TT-188 refactor some names +======= + service.removeUserFromGroup(userId, group).subscribe(); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST'); }); diff --git a/src/app/modules/users/services/users.service.ts b/src/app/modules/users/services/users.service.ts index de15d8321..a3edd5c83 100644 --- a/src/app/modules/users/services/users.service.ts +++ b/src/app/modules/users/services/users.service.ts @@ -39,6 +39,7 @@ export class UsersService { }); } +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD removeUserFromGroup(userId: string, group: string): Observable { @@ -48,6 +49,9 @@ export class UsersService { ======= removeUserToGroup(userId: string, group: string): Observable { >>>>>>> refactor: TT-188 refactor some names +======= + removeUserFromGroup(userId: string, group: string): Observable { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references return this.http.post(`${this.baseUrl}/${userId}/groups/remove`, { group_name: group, }); diff --git a/src/app/modules/users/store/user.actions.spec.ts b/src/app/modules/users/store/user.actions.spec.ts index ac5eecb0c..05f7ccb59 100644 --- a/src/app/modules/users/store/user.actions.spec.ts +++ b/src/app/modules/users/store/user.actions.spec.ts @@ -77,6 +77,7 @@ describe('UserActions', () => { }); it('RemoveUserFromGroup type is UserActionTypes.REMOVE_USER_FROM_GROUP', () => { +<<<<<<< HEAD const userId = 'userId'; const groupName = 'groupName'; const action = new actions.RemoveUserFromGroup(userId, groupName); @@ -121,28 +122,34 @@ describe('UserActions', () => { }); it('RemoveUserToGroup type is UserActionTypes.REMOVE_USER_TO_GROUP', () => { +======= +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const userId = 'userId'; const groupName = 'groupName'; - const action = new actions.RemoveUserToGroup(userId, groupName); + const action = new actions.RemoveUserFromGroup(userId, groupName); - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP); + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP); }); - it('RemoveUserToGroupSuccess type is UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS', () => { + it('RemoveUserFromGroupSuccess type is UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS', () => { const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.RemoveUserToGroupSuccess(payload); + const action = new actions.RemoveUserFromGroupSuccess(payload); - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS); + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS); }); - it('RemoveUserToGroupFail type is UserActionTypes.REMOVE_USER_TO_GROUP_FAIL', () => { - const action = new actions.RemoveUserToGroupFail('error'); + it('RemoveUserFromGroupFail type is UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL', () => { + const action = new actions.RemoveUserFromGroupFail('error'); +<<<<<<< HEAD <<<<<<< HEAD expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); >>>>>>> feat: TT-188 add ngrx flow & test ======= expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); >>>>>>> refactor: TT-188 refactor some names +======= + expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); }); diff --git a/src/app/modules/users/store/user.actions.ts b/src/app/modules/users/store/user.actions.ts index 13c9dc88c..4ac160713 100644 --- a/src/app/modules/users/store/user.actions.ts +++ b/src/app/modules/users/store/user.actions.ts @@ -31,10 +31,16 @@ export enum UserActionTypes { 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', +<<<<<<< HEAD REMOVE_USER_TO_GROUP = '[User] REMOVE_USER_TO_GROUP', REMOVE_USER_TO_GROUP_SUCCESS = '[User] REMOVE_USER_TO_GROUP_SUCCESS', REMOVE_USER_TO_GROUP_FAIL = '[User] REMOVE_USER_TO_GROUP_FAIL', >>>>>>> refactor: TT-188 refactor some names +======= + REMOVE_USER_FROM_GROUP = '[User] REMOVE_USER_FROM_GROUP', + REMOVE_USER_FROM_GROUP_SUCCESS = '[User] REMOVE_USER_FROM_GROUP_SUCCESS', + REMOVE_USER_FROM_GROUP_FAIL = '[User] REMOVE_USER_FROM_GROUP_FAIL', +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references DEFAULT_USER = '[USER] DEFAULT_USER', } @@ -101,6 +107,7 @@ export class AddUserToGroupFail implements Action { export class RemoveUserFromGroup implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP; +<<<<<<< HEAD constructor(public userId: string, public groupName: string) {} } @@ -133,14 +140,17 @@ export class AddUserToGroupFail implements Action { export class RemoveUserToGroup implements Action { public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP; +======= +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references constructor(public userId: string, public groupName: string) {} } -export class RemoveUserToGroupSuccess implements Action { - public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS; +export class RemoveUserFromGroupSuccess implements Action { + public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS; constructor(readonly payload: User) {} } +<<<<<<< HEAD <<<<<<< HEAD export class RemoveGroupToUserFail implements Action { public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_FAIL; @@ -149,6 +159,10 @@ export class RemoveGroupToUserFail implements Action { export class RemoveUserToGroupFail implements Action { public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_FAIL; >>>>>>> refactor: TT-188 refactor some names +======= +export class RemoveUserFromGroupFail implements Action { + public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL; +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references constructor(public error: string) {} } @@ -187,7 +201,13 @@ export type UserActions = | AddUserToGroup | AddUserToGroupSuccess | AddUserToGroupFail +<<<<<<< HEAD | RemoveUserToGroup | RemoveUserToGroupSuccess | RemoveUserToGroupFail; >>>>>>> refactor: TT-188 refactor some names +======= + | RemoveUserFromGroup + | RemoveUserFromGroupSuccess + | RemoveUserFromGroupFail; +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references diff --git a/src/app/modules/users/store/user.effects.spec.ts b/src/app/modules/users/store/user.effects.spec.ts index 65d8cc0f4..8f8e2162b 100644 --- a/src/app/modules/users/store/user.effects.spec.ts +++ b/src/app/modules/users/store/user.effects.spec.ts @@ -185,6 +185,7 @@ describe('UserEffects', () => { }); it('action type is REMOVE_USER_FROM_GROUP_SUCCESS when service is executed succesfully', async () => { +<<<<<<< HEAD const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ @@ -211,12 +212,19 @@ describe('UserEffects', () => { ======= type: UserActionTypes.REMOVE_USER_TO_GROUP, >>>>>>> refactor: TT-188 refactor some names +======= + const userId = 'userId'; + const groupName = 'groupName'; + actions$ = of({ + type: UserActionTypes.REMOVE_USER_FROM_GROUP, +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references userId, groupName, }); spyOn(toastrService, 'success'); <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); @@ -236,29 +244,37 @@ describe('UserEffects', () => { ======= spyOn(service, 'removeUserToGroup').and.returnValue(of(user)); >>>>>>> refactor: TT-188 refactor some names +======= + spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references - effects.removeUserToGroup$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Remove user to group success'); - expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS); + effects.removeUserFromGroup$.subscribe((action) => { + expect(toastrService.success).toHaveBeenCalledWith('Remove user from group success'); + expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS); }); }); - it('action type is REMOVE_USER_TO_GROUP_FAIL when service is executed succesfully', async () => { + it('action type is REMOVE_USER_FROM_GROUP_FAIL when service is executed succesfully', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ +<<<<<<< HEAD <<<<<<< HEAD type: UserActionTypes.REMOVE_GROUP_TO_USER, >>>>>>> feat: TT-188 add ngrx flow & test ======= type: UserActionTypes.REMOVE_USER_TO_GROUP, >>>>>>> refactor: TT-188 refactor some names +======= + type: UserActionTypes.REMOVE_USER_FROM_GROUP, +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references userId, groupName, }); spyOn(toastrService, 'error'); <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); @@ -270,15 +286,22 @@ describe('UserEffects', () => { ======= spyOn(service, 'removeUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); >>>>>>> refactor: TT-188 refactor some names +======= + spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references - effects.removeUserToGroup$.subscribe((action) => { + effects.removeUserFromGroup$.subscribe((action) => { expect(toastrService.error).toHaveBeenCalled(); +<<<<<<< HEAD <<<<<<< HEAD expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); >>>>>>> feat: TT-188 add ngrx flow & test ======= expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); >>>>>>> refactor: TT-188 refactor some names +======= + expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); }); }); diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 7c5ccff04..5daeaf9d9 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -109,6 +109,7 @@ export class UserEffects { @Effect() <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD removeUserFromGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), @@ -131,20 +132,29 @@ export class UserEffects { ofType(actions.UserActionTypes.REMOVE_USER_TO_GROUP), map((action: actions.RemoveUserToGroup) => action), >>>>>>> refactor: TT-188 refactor some names +======= + removeUserFromGroup$: Observable = this.actions$.pipe( + ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), + map((action: actions.RemoveUserFromGroup) => action), +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references mergeMap((action) => - this.userService.removeUserToGroup(action.userId, action.groupName).pipe( + this.userService.removeUserFromGroup(action.userId, action.groupName).pipe( map((response) => { - this.toastrService.success('Remove user to group success'); - return new actions.RemoveUserToGroupSuccess(response); + this.toastrService.success('Remove user from group success'); + return new actions.RemoveUserFromGroupSuccess(response); }), catchError((error) => { this.toastrService.error(error.error.message); +<<<<<<< HEAD <<<<<<< HEAD return of(new actions.RemoveGroupToUserFail(error)); >>>>>>> feat: TT-188 add ngrx flow & test ======= return of(new actions.RemoveUserToGroupFail(error)); >>>>>>> refactor: TT-188 refactor some names +======= + return of(new actions.RemoveUserFromGroupFail(error)); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }) ) ) diff --git a/src/app/modules/users/store/user.reducer.spec.ts b/src/app/modules/users/store/user.reducer.spec.ts index 6be89563f..bcb1488ab 100644 --- a/src/app/modules/users/store/user.reducer.spec.ts +++ b/src/app/modules/users/store/user.reducer.spec.ts @@ -158,6 +158,7 @@ describe('userReducer', () => { }); it('on RemoveUserFromGroup, isLoading is true', () => { +<<<<<<< HEAD const userId = 'userId'; const groupName = 'groupName'; const action = new actions.RemoveUserFromGroup(userId, groupName); @@ -185,11 +186,17 @@ describe('userReducer', () => { ======= const action = new actions.RemoveUserToGroup(userId, groupName); >>>>>>> refactor: TT-188 refactor some names +======= + const userId = 'userId'; + const groupName = 'groupName'; + const action = new actions.RemoveUserFromGroup(userId, groupName); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD it('on RemoveUserFromGroupSuccess, user groups should change', () => { @@ -199,6 +206,9 @@ describe('userReducer', () => { ======= it('on RemoveUserToGroupSuccess, user groups should change', () => { >>>>>>> refactor: TT-188 refactor some names +======= + it('on RemoveUserFromGroupSuccess, user groups should change', () => { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: ['group'] }], isLoading: false, @@ -206,6 +216,7 @@ describe('userReducer', () => { }; const userWithGroupRemoved: User = { id: 'id', name: 'name', email: 'email', groups: null }; <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); ======= @@ -214,11 +225,15 @@ describe('userReducer', () => { ======= const action = new actions.RemoveUserToGroupSuccess(userWithGroupRemoved); >>>>>>> refactor: TT-188 refactor some names +======= + const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupRemoved]); expect(state.isLoading).toEqual(false); <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD expect(state.message).toEqual('Remove user from group success'); }); @@ -233,18 +248,25 @@ describe('userReducer', () => { ======= expect(state.message).toEqual('Remove user to group success'); >>>>>>> refactor: TT-188 refactor some names +======= + expect(state.message).toEqual('Remove user from group success'); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); - it('on RemoveUserToGroupFail, should show a message with an error message', () => { - const action = new actions.RemoveUserToGroupFail('error'); + it('on RemoveUserFromGroupFail, should show a message with an error message', () => { + const action = new actions.RemoveUserFromGroupFail('error'); const state = userReducer(initialState, action); +<<<<<<< HEAD <<<<<<< HEAD expect(state.message).toEqual('Something went wrong removing group to a user'); >>>>>>> feat: TT-188 add ngrx flow & test ======= expect(state.message).toEqual('Something went wrong removing user to group'); >>>>>>> refactor: TT-188 refactor some names +======= + expect(state.message).toEqual('Something went wrong removing user from group'); +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references expect(state.isLoading).toEqual(false); }); diff --git a/src/app/modules/users/store/user.reducers.ts b/src/app/modules/users/store/user.reducers.ts index 20cb58da6..5fef4fb21 100644 --- a/src/app/modules/users/store/user.reducers.ts +++ b/src/app/modules/users/store/user.reducers.ts @@ -145,18 +145,23 @@ export const userReducer = (state: UserState = initialState, action: UserActions }; } +<<<<<<< HEAD <<<<<<< HEAD case UserActionTypes.REMOVE_GROUP_TO_USER: { >>>>>>> feat: TT-188 add ngrx flow & test ======= case UserActionTypes.REMOVE_USER_TO_GROUP: { >>>>>>> refactor: TT-188 refactor some names +======= + case UserActionTypes.REMOVE_USER_FROM_GROUP: { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references return { ...state, isLoading: true, }; } <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { ======= @@ -165,12 +170,16 @@ export const userReducer = (state: UserState = initialState, action: UserActions ======= case UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS: { >>>>>>> refactor: TT-188 refactor some names +======= + case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD message: 'Remove user from group success', }; @@ -185,18 +194,25 @@ export const userReducer = (state: UserState = initialState, action: UserActions ======= message: 'Remove user to group success', >>>>>>> refactor: TT-188 refactor some names +======= + message: 'Remove user from group success', +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }; } - case UserActionTypes.REMOVE_USER_TO_GROUP_FAIL: { + case UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL: { return { ...state, isLoading: false, +<<<<<<< HEAD <<<<<<< HEAD message: 'Something went wrong removing group to a user', >>>>>>> feat: TT-188 add ngrx flow & test ======= message: 'Something went wrong removing user to group', >>>>>>> refactor: TT-188 refactor some names +======= + message: 'Something went wrong removing user from group', +>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }; } default: From 321d8129f25c33042b196a8cbed43c3956daf26f Mon Sep 17 00:00:00 2001 From: wobravo Date: Thu, 25 Mar 2021 16:24:46 -0500 Subject: [PATCH 5/7] fix: TT-190 use add remove groups --- .../users-list/users-list.component.html | 8 +-- .../users-list/users-list.component.ts | 50 +++++++++++++++++-- 2 files changed, 50 insertions(+), 8 deletions(-) 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 bab11ae27..0f88995de 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 @@ -22,14 +22,14 @@
admin test
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 8ac50f8b4..864916486 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 @@ -1,10 +1,11 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActionsSubject, select, Store } from '@ngrx/store'; import { DataTableDirective } from 'angular-datatables'; -import { Observable, Subject, Subscription } from 'rxjs'; -import { delay, filter } from 'rxjs/operators'; +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 { User } from '../../models/users'; -import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes } from '../../store/user.actions'; +import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes, AddUserToGroup, RemoveUserToGroup} from '../../store/user.actions'; import { getIsLoading } from '../../store/user.selectors'; @Component({ @@ -21,8 +22,16 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { @ViewChild(DataTableDirective, { static: false }) dtElement: DataTableDirective; dtOptions: any = {}; + switchGroupsSubscription: Subscription; + isEnableToggleSubscription: Subscription; + isUserRoleToggleOn; + flakyToggle: true; - constructor(private store: Store, private actionsSubject$: ActionsSubject) { + constructor( + private store: Store, + private actionsSubject$: ActionsSubject, + private featureManagerService: FeatureManagerService + ) { this.isLoading$ = store.pipe(delay(0), select(getIsLoading)); } @@ -35,6 +44,24 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { this.rerenderDataTable(); }); + this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => { + this.isUserRoleToggleOn = flag; + console.log('in subscription', this.isUserRoleToggleOn); + }); + + this.switchGroupsSubscription = this.actionsSubject$ + .pipe( + filter( + (action: any) => + action.type === UserActionTypes.ADD_USER_TO_GROUP_SUCCESS || + action.type === UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS + ) + ) + .subscribe((action) => { + this.store.dispatch(new LoadUsers()); + this.rerenderDataTable(); + }); + this.switchRoleSubscription = this.actionsSubject$ .pipe( filter( @@ -55,6 +82,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { ngOnDestroy() { this.loadUsersSubscription.unsubscribe(); this.dtTrigger.unsubscribe(); + this.isEnableToggleSubscription.unsubscribe(); } private rerenderDataTable(): void { @@ -73,4 +101,18 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { ? this.store.dispatch(new RevokeRoleUser(userId, roleId)) : this.store.dispatch(new GrantRoleUser(userId, roleId)); } + + isFeatureToggleActivated() { + return this.featureManagerService.isToggleEnabledForUser('ui-list-technologies').pipe( + map((enabled) => { + return enabled === true ? true : false; + }) + ); + } + + switchGroups(userId: string, userGroups: string[], groupname: string, groupValue: string) { + userGroups.includes(groupValue) + ? this.store.dispatch(new RemoveUserToGroup(userId, groupname)) + : this.store.dispatch(new AddUserToGroup(userId, groupname)); + } } From 14711ce988d43ab91f3aa8506b7f648e7e714ed2 Mon Sep 17 00:00:00 2001 From: Israel Leon Date: Thu, 25 Mar 2021 18:46:17 -0500 Subject: [PATCH 6/7] feat: TT-190 Use add/remove groups endpoints in users section in UI --- .../users-list/users-list.component.html | 23 +++- .../users-list/users-list.component.spec.ts | 127 +++++++++++++++++- .../users-list/users-list.component.ts | 34 ++--- .../users/services/users.service.spec.ts | 36 ----- .../modules/users/services/users.service.ts | 20 --- .../modules/users/store/user.actions.spec.ts | 58 -------- src/app/modules/users/store/user.actions.ts | 96 ------------- .../modules/users/store/user.effects.spec.ts | 127 ------------------ src/app/modules/users/store/user.effects.ts | 60 --------- .../modules/users/store/user.reducer.spec.ts | 113 ---------------- src/app/modules/users/store/user.reducers.ts | 82 ----------- 11 files changed, 162 insertions(+), 614 deletions(-) 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 0f88995de..605a6811c 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 - Roles + {{ isUserGroupsToggleOn ? 'Groups' : 'Roles' }} @@ -19,20 +19,35 @@ {{ user.email }} {{ user.name }} -
+
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 53441835c..642fa0bea 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,17 +1,33 @@ +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'; import { UsersListComponent } from './users-list.component'; -import { UserActionTypes, UserState, LoadUsers, GrantRoleUser, RevokeRoleUser } from '../../store'; +import { + UserActionTypes, + UserState, + LoadUsers, + GrantRoleUser, + RevokeRoleUser, + AddUserToGroup, + RemoveUserFromGroup, +} from '../../store'; 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: [ @@ -19,6 +35,7 @@ describe('UsersListComponent', () => { name: 'name', email: 'email', roles: ['admin', 'test'], + groups: ['time-tracker-admin', 'time-tracker-tester'], id: 'id', tenant_id: 'tenant id', deleted: 'delete', @@ -30,10 +47,20 @@ 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 }], + providers: [ + provideMockStore({ initialState: state }), + { provide: ActionsSubject, useValue: actionSub }, + { provide: FeatureManagerService, useValue: service } + ], }).compileComponents(); }) ); @@ -91,6 +118,27 @@ describe('UsersListComponent', () => { }); }); + const actionsGroupsParams = [ + { actionType: UserActionTypes.ADD_USER_TO_GROUP_SUCCESS }, + { actionType: UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS }, + ]; + + actionsGroupsParams.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 grantRoleTypes = [ { roleId: 'admin', roleValue: 'time-tracker-admin' }, { roleId: 'test', roleValue: 'time-tracker-tester' }, @@ -111,6 +159,25 @@ describe('UsersListComponent', () => { }); }); + const AddGroupTypes = [ + { groupName: 'time-tracker-admin' }, + { groupName: 'time-tracker-tester' } + ]; + + AddGroupTypes.map((param) => { + it(`When user switchGroup to ${param.groupName} and doesn't belong to any group, should add ${param.groupName} group to user`, () => { + const groupName = param.groupName; + const userGroups = []; + const userId = 'userId'; + + spyOn(store, 'dispatch'); + + component.switchGroup(userId, userGroups, groupName); + + expect(store.dispatch).toHaveBeenCalledWith(new AddUserToGroup(userId, groupName)); + }); + }); + const revokeRoleTypes = [ { roleId: 'admin', roleValue: 'time-tracker-admin', userRoles: ['time-tracker-admin'] }, { roleId: 'test', roleValue: 'time-tracker-tester', userRoles: ['time-tracker-tester'] }, @@ -131,6 +198,25 @@ describe('UsersListComponent', () => { }); }); + const removeGroupTypes = [ + { groupName: 'time-tracker-admin', userGroups: ['time-tracker-admin'] }, + { groupName: 'time-tracker-tester', userGroups: ['time-tracker-tester'] }, + ]; + + removeGroupTypes.map((param) => { + it(`When user switchGroup to ${param.groupName} and belongs to group, should remove ${param.groupName} group from user`, () => { + const groupName = param.groupName; + const userGroups = param.userGroups; + const userId = 'userId'; + + spyOn(store, 'dispatch'); + + component.switchGroup(userId, userGroups, groupName); + + expect(store.dispatch).toHaveBeenCalledWith(new RemoveUserFromGroup(userId, groupName)); + }); + }); + it('on success load users, the data of roles should be an array', () => { const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; const action = { @@ -145,6 +231,20 @@ describe('UsersListComponent', () => { }); }); + it('on success load users, the data of groups 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.groups).toEqual(['time-tracker-admin', 'time-tracker-tester']); + }); + }); + it('on success load users, the datatable should be reloaded', async () => { const actionSubject = TestBed.inject(ActionsSubject); const action = { @@ -158,6 +258,27 @@ 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 864916486..06540501f 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 @@ -1,11 +1,18 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActionsSubject, select, Store } from '@ngrx/store'; import { DataTableDirective } from 'angular-datatables'; -import { Observable, Subject, Subscription} from 'rxjs'; +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 { User } from '../../models/users'; -import { GrantRoleUser, LoadUsers, RevokeRoleUser, UserActionTypes, AddUserToGroup, RemoveUserToGroup} from '../../store/user.actions'; +import { + GrantRoleUser, + LoadUsers, + RevokeRoleUser, + UserActionTypes, + AddUserToGroup, + RemoveUserFromGroup, +} from '../../store/user.actions'; import { getIsLoading } from '../../store/user.selectors'; @Component({ @@ -24,8 +31,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { dtOptions: any = {}; switchGroupsSubscription: Subscription; isEnableToggleSubscription: Subscription; - isUserRoleToggleOn; - flakyToggle: true; + isUserGroupsToggleOn: boolean; constructor( private store: Store, @@ -45,8 +51,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { }); this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => { - this.isUserRoleToggleOn = flag; - console.log('in subscription', this.isUserRoleToggleOn); + this.isUserGroupsToggleOn = flag; }); this.switchGroupsSubscription = this.actionsSubject$ @@ -54,12 +59,11 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { filter( (action: any) => action.type === UserActionTypes.ADD_USER_TO_GROUP_SUCCESS || - action.type === UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS + action.type === UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS ) ) .subscribe((action) => { this.store.dispatch(new LoadUsers()); - this.rerenderDataTable(); }); this.switchRoleSubscription = this.actionsSubject$ @@ -102,17 +106,17 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { : this.store.dispatch(new GrantRoleUser(userId, roleId)); } + switchGroup(userId: string, userGroups: string[], groupName: string) { + userGroups.includes(groupName) + ? this.store.dispatch(new RemoveUserFromGroup(userId, groupName)) + : this.store.dispatch(new AddUserToGroup(userId, groupName)); + } + isFeatureToggleActivated() { - return this.featureManagerService.isToggleEnabledForUser('ui-list-technologies').pipe( + return this.featureManagerService.isToggleEnabledForUser('switch-group').pipe( map((enabled) => { return enabled === true ? true : false; }) ); } - - switchGroups(userId: string, userGroups: string[], groupname: string, groupValue: string) { - userGroups.includes(groupValue) - ? this.store.dispatch(new RemoveUserToGroup(userId, groupname)) - : this.store.dispatch(new AddUserToGroup(userId, groupname)); - } } diff --git a/src/app/modules/users/services/users.service.spec.ts b/src/app/modules/users/services/users.service.spec.ts index 9d421a6c1..d8d50dbd9 100644 --- a/src/app/modules/users/services/users.service.spec.ts +++ b/src/app/modules/users/services/users.service.spec.ts @@ -52,58 +52,22 @@ describe('UsersService', () => { expect(grantRoleRequest.request.method).toBe('POST'); }); -<<<<<<< HEAD -<<<<<<< HEAD it('add user to group', () => { -======= - it('add group to a User', () => { ->>>>>>> feat: TT-188 add & remove groups to user service -======= - it('add user to group', () => { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const userId = 'userId'; const group = 'admin'; const addGroupURL = `${service.baseUrl}/${userId}/groups/add`; -<<<<<<< HEAD -<<<<<<< HEAD - service.addUserToGroup(userId, group).subscribe(); -======= - service.addGroupToUser(userId, group).subscribe(); ->>>>>>> feat: TT-188 add & remove groups to user service -======= service.addUserToGroup(userId, group).subscribe(); ->>>>>>> refactor: TT-188 refactor some names expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST'); }); -<<<<<<< HEAD -<<<<<<< HEAD it('remove user from group', () => { -======= - it('remove group to a User', () => { ->>>>>>> feat: TT-188 add & remove groups to user service -======= - it('remove user from group', () => { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const userId = 'userId'; const group = 'admin'; const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`; -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - service.removeUserFromGroup(userId, group).subscribe(); -======= - service.removeGroupToUser(userId, group).subscribe(); ->>>>>>> feat: TT-188 add & remove groups to user service -======= - service.removeUserToGroup(userId, group).subscribe(); ->>>>>>> refactor: TT-188 refactor some names -======= service.removeUserFromGroup(userId, group).subscribe(); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST'); }); diff --git a/src/app/modules/users/services/users.service.ts b/src/app/modules/users/services/users.service.ts index a3edd5c83..40e97fec3 100644 --- a/src/app/modules/users/services/users.service.ts +++ b/src/app/modules/users/services/users.service.ts @@ -25,33 +25,13 @@ export class UsersService { return this.http.post(url, null); } -<<<<<<< HEAD -<<<<<<< HEAD addUserToGroup(userId: string, group: string): Observable { -======= - addGroupToUser(userId: string, group: string): Observable { ->>>>>>> feat: TT-188 add & remove groups to user service -======= - addUserToGroup(userId: string, group: string): Observable { ->>>>>>> refactor: TT-188 refactor some names return this.http.post(`${this.baseUrl}/${userId}/groups/add`, { group_name: group, }); } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - removeUserFromGroup(userId: string, group: string): Observable { -======= - removeGroupToUser(userId: string, group: string): Observable { ->>>>>>> feat: TT-188 add & remove groups to user service -======= - removeUserToGroup(userId: string, group: string): Observable { ->>>>>>> refactor: TT-188 refactor some names -======= removeUserFromGroup(userId: string, group: string): Observable { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references return this.http.post(`${this.baseUrl}/${userId}/groups/remove`, { group_name: group, }); diff --git a/src/app/modules/users/store/user.actions.spec.ts b/src/app/modules/users/store/user.actions.spec.ts index 05f7ccb59..ae1bb933f 100644 --- a/src/app/modules/users/store/user.actions.spec.ts +++ b/src/app/modules/users/store/user.actions.spec.ts @@ -53,8 +53,6 @@ describe('UserActions', () => { expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_FAIL); }); -<<<<<<< HEAD -<<<<<<< HEAD it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { const userId = 'userId'; const groupName = 'groupName'; @@ -77,7 +75,6 @@ describe('UserActions', () => { }); it('RemoveUserFromGroup type is UserActionTypes.REMOVE_USER_FROM_GROUP', () => { -<<<<<<< HEAD const userId = 'userId'; const groupName = 'groupName'; const action = new actions.RemoveUserFromGroup(userId, groupName); @@ -96,60 +93,5 @@ describe('UserActions', () => { const action = new actions.RemoveUserFromGroupFail('error'); expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); -======= - it('AddGroupToUser type is UserActionTypes.ADD_GROUP_TO_USER', () => { -======= - it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => { ->>>>>>> refactor: TT-188 refactor some names - const userId = 'userId'; - const groupName = 'groupName'; - const action = new actions.AddUserToGroup(userId, groupName); - - expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP); - }); - - it('AddUserToGroupSuccess type is UserActionTypes.ADD_USER_TO_GROUP_SUCCESS', () => { - const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.AddUserToGroupSuccess(payload); - - expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP_SUCCESS); - }); - - it('AddUserToGroupFail type is UserActionTypes.ADD_USER_TO_GROUP_FAIL', () => { - const action = new actions.AddUserToGroupFail('error'); - - expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP_FAIL); - }); - - it('RemoveUserToGroup type is UserActionTypes.REMOVE_USER_TO_GROUP', () => { -======= ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references - const userId = 'userId'; - const groupName = 'groupName'; - const action = new actions.RemoveUserFromGroup(userId, groupName); - - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP); - }); - - it('RemoveUserFromGroupSuccess type is UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS', () => { - const payload: User = { id: 'id', email: 'email', name: 'name' }; - const action = new actions.RemoveUserFromGroupSuccess(payload); - - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS); - }); - - it('RemoveUserFromGroupFail type is UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL', () => { - const action = new actions.RemoveUserFromGroupFail('error'); - -<<<<<<< HEAD -<<<<<<< HEAD - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); ->>>>>>> refactor: TT-188 refactor some names -======= - expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); }); diff --git a/src/app/modules/users/store/user.actions.ts b/src/app/modules/users/store/user.actions.ts index 4ac160713..674fff5af 100644 --- a/src/app/modules/users/store/user.actions.ts +++ b/src/app/modules/users/store/user.actions.ts @@ -11,36 +11,12 @@ export enum UserActionTypes { 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', -<<<<<<< HEAD -<<<<<<< HEAD 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', REMOVE_USER_FROM_GROUP = '[User] REMOVE_USER_FROM_GROUP', REMOVE_USER_FROM_GROUP_SUCCESS = '[User] REMOVE_USER_FROM_GROUP_SUCCESS', REMOVE_USER_FROM_GROUP_FAIL = '[User] REMOVE_USER_FROM_GROUP_FAIL', -======= - ADD_GROUP_TO_USER = '[User] ADD_GROUP_TO_USER', - ADD_GROUP_TO_USER_SUCCESS = '[User] ADD_GROUP_TO_USER_SUCCESS', - ADD_GROUP_TO_USER_FAIL = '[User] ADD_GROUP_TO_USER_FAIL', - REMOVE_GROUP_TO_USER = '[User] REMOVE_GROUP_TO_USER', - REMOVE_GROUP_TO_USER_SUCCESS = '[User] REMOVE_GROUP_TO_USER_SUCCESS', - REMOVE_GROUP_TO_USER_FAIL = '[User] REMOVE_GROUP_TO_USER_FAIL', ->>>>>>> feat: TT-188 add ngrx flow & test -======= - 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', -<<<<<<< HEAD - REMOVE_USER_TO_GROUP = '[User] REMOVE_USER_TO_GROUP', - REMOVE_USER_TO_GROUP_SUCCESS = '[User] REMOVE_USER_TO_GROUP_SUCCESS', - REMOVE_USER_TO_GROUP_FAIL = '[User] REMOVE_USER_TO_GROUP_FAIL', ->>>>>>> refactor: TT-188 refactor some names -======= - REMOVE_USER_FROM_GROUP = '[User] REMOVE_USER_FROM_GROUP', - REMOVE_USER_FROM_GROUP_SUCCESS = '[User] REMOVE_USER_FROM_GROUP_SUCCESS', - REMOVE_USER_FROM_GROUP_FAIL = '[User] REMOVE_USER_FROM_GROUP_FAIL', ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references DEFAULT_USER = '[USER] DEFAULT_USER', } @@ -88,8 +64,6 @@ export class RevokeRoleUserFail implements Action { constructor(public error: string) {} } -<<<<<<< HEAD -<<<<<<< HEAD export class AddUserToGroup implements Action { public readonly type = UserActionTypes.ADD_USER_TO_GROUP; constructor(public userId: string, public groupName: string) {} @@ -107,7 +81,6 @@ export class AddUserToGroupFail implements Action { export class RemoveUserFromGroup implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP; -<<<<<<< HEAD constructor(public userId: string, public groupName: string) {} } @@ -118,51 +91,6 @@ export class RemoveUserFromGroupSuccess implements Action { export class RemoveUserFromGroupFail implements Action { public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL; -======= -export class AddGroupToUser implements Action { - public readonly type = UserActionTypes.ADD_GROUP_TO_USER; -======= -export class AddUserToGroup implements Action { - public readonly type = UserActionTypes.ADD_USER_TO_GROUP; ->>>>>>> refactor: TT-188 refactor some names - 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) {} -} - -export class AddUserToGroupFail implements Action { - public readonly type = UserActionTypes.ADD_USER_TO_GROUP_FAIL; - constructor(public error: string) {} -} - -export class RemoveUserToGroup implements Action { - public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP; -======= ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references - 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) {} -} - -<<<<<<< HEAD -<<<<<<< HEAD -export class RemoveGroupToUserFail implements Action { - public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_FAIL; ->>>>>>> feat: TT-188 add ngrx flow & test -======= -export class RemoveUserToGroupFail implements Action { - public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_FAIL; ->>>>>>> refactor: TT-188 refactor some names -======= -export class RemoveUserFromGroupFail implements Action { - public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL; ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references constructor(public error: string) {} } @@ -181,33 +109,9 @@ export type UserActions = | RevokeRoleUser | RevokeRoleUserSuccess | RevokeRoleUserFail -<<<<<<< HEAD -<<<<<<< HEAD - | AddUserToGroup - | AddUserToGroupSuccess - | AddUserToGroupFail - | RemoveUserFromGroup - | RemoveUserFromGroupSuccess - | RemoveUserFromGroupFail; -======= - | AddGroupToUser - | AddGroupToUserSuccess - | AddGroupToUserFail - | RemoveGroupToUser - | RemoveGroupToUserSuccess - | RemoveGroupToUserFail; ->>>>>>> feat: TT-188 add ngrx flow & test -======= | AddUserToGroup | AddUserToGroupSuccess | AddUserToGroupFail -<<<<<<< HEAD - | RemoveUserToGroup - | RemoveUserToGroupSuccess - | RemoveUserToGroupFail; ->>>>>>> refactor: TT-188 refactor some names -======= | RemoveUserFromGroup | RemoveUserFromGroupSuccess | RemoveUserFromGroupFail; ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references diff --git a/src/app/modules/users/store/user.effects.spec.ts b/src/app/modules/users/store/user.effects.spec.ts index 8f8e2162b..8aea60311 100644 --- a/src/app/modules/users/store/user.effects.spec.ts +++ b/src/app/modules/users/store/user.effects.spec.ts @@ -106,34 +106,16 @@ describe('UserEffects', () => { }); }); -<<<<<<< HEAD -<<<<<<< HEAD it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.ADD_USER_TO_GROUP, -======= - it('action type is ADD_GROUP_TO_USER_SUCCESS when service is executed sucessfully', async () => { - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ - type: UserActionTypes.ADD_GROUP_TO_USER, ->>>>>>> feat: TT-188 add ngrx flow & test -======= - it('action type is ADD_USER_TO_GROUP_SUCCESS when service is executed sucessfully', async () => { - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ - type: UserActionTypes.ADD_USER_TO_GROUP, ->>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'success'); -<<<<<<< HEAD -<<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(of(user)); effects.addUserToGroup$.subscribe((action) => { @@ -147,35 +129,11 @@ describe('UserEffects', () => { const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.ADD_USER_TO_GROUP, -======= - spyOn(service, 'addGroupToUser').and.returnValue(of(user)); -======= - spyOn(service, 'addUserToGroup').and.returnValue(of(user)); ->>>>>>> refactor: TT-188 refactor some names - - effects.addUserToGroup$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Add user to group success'); - expect(action.type).toEqual(UserActionTypes.ADD_USER_TO_GROUP_SUCCESS); - }); - }); - - it('action type is ADD_USER_TO_GROUP_FAIL when service is executed and fail', async () => { - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ -<<<<<<< HEAD - type: UserActionTypes.ADD_GROUP_TO_USER, ->>>>>>> feat: TT-188 add ngrx flow & test -======= - type: UserActionTypes.ADD_USER_TO_GROUP, ->>>>>>> refactor: TT-188 refactor some names userId, groupName, }); spyOn(toastrService, 'error'); -<<<<<<< HEAD -<<<<<<< HEAD spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); effects.addUserToGroup$.subscribe((action) => { @@ -185,47 +143,15 @@ describe('UserEffects', () => { }); it('action type is REMOVE_USER_FROM_GROUP_SUCCESS when service is executed succesfully', async () => { -<<<<<<< HEAD - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ - type: UserActionTypes.REMOVE_USER_FROM_GROUP, -======= - spyOn(service, 'addGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); -======= - spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); ->>>>>>> refactor: TT-188 refactor some names - - effects.addUserToGroup$.subscribe((action) => { - expect(toastrService.error).toHaveBeenCalled(); - expect(action.type).toEqual(UserActionTypes.ADD_USER_TO_GROUP_FAIL); - }); - }); - - it('action type is REMOVE_USER_TO_GROUP_SUCCESS when service is executed succesfully', async () => { - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ -<<<<<<< HEAD - type: UserActionTypes.REMOVE_GROUP_TO_USER, ->>>>>>> feat: TT-188 add ngrx flow & test -======= - type: UserActionTypes.REMOVE_USER_TO_GROUP, ->>>>>>> refactor: TT-188 refactor some names -======= const userId = 'userId'; const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.REMOVE_USER_FROM_GROUP, ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references userId, groupName, }); spyOn(toastrService, 'success'); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); effects.removeUserFromGroup$.subscribe((action) => { @@ -239,69 +165,16 @@ describe('UserEffects', () => { const groupName = 'groupName'; actions$ = of({ type: UserActionTypes.REMOVE_USER_FROM_GROUP, -======= - spyOn(service, 'removeGroupToUser').and.returnValue(of(user)); -======= - spyOn(service, 'removeUserToGroup').and.returnValue(of(user)); ->>>>>>> refactor: TT-188 refactor some names -======= - spyOn(service, 'removeUserFromGroup').and.returnValue(of(user)); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references - - effects.removeUserFromGroup$.subscribe((action) => { - expect(toastrService.success).toHaveBeenCalledWith('Remove user from group success'); - expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS); - }); - }); - - it('action type is REMOVE_USER_FROM_GROUP_FAIL when service is executed succesfully', async () => { - const userId = 'userId'; - const groupName = 'groupName'; - actions$ = of({ -<<<<<<< HEAD -<<<<<<< HEAD - type: UserActionTypes.REMOVE_GROUP_TO_USER, ->>>>>>> feat: TT-188 add ngrx flow & test -======= - type: UserActionTypes.REMOVE_USER_TO_GROUP, ->>>>>>> refactor: TT-188 refactor some names -======= - type: UserActionTypes.REMOVE_USER_FROM_GROUP, ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references userId, groupName, }); spyOn(toastrService, 'error'); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); - - effects.removeUserFromGroup$.subscribe((action) => { - expect(toastrService.error).toHaveBeenCalled(); - expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); -======= - spyOn(service, 'removeGroupToUser').and.returnValue(throwError({ error: { message: 'error' } })); -======= - spyOn(service, 'removeUserToGroup').and.returnValue(throwError({ error: { message: 'error' } })); ->>>>>>> refactor: TT-188 refactor some names -======= spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } })); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references effects.removeUserFromGroup$.subscribe((action) => { expect(toastrService.error).toHaveBeenCalled(); -<<<<<<< HEAD -<<<<<<< HEAD - expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_FAIL); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_FAIL); ->>>>>>> refactor: TT-188 refactor some names -======= expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); }); }); diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 5daeaf9d9..613b18456 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -65,8 +65,6 @@ export class UserEffects { ); @Effect() -<<<<<<< HEAD -<<<<<<< HEAD addUserToGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), map((action: actions.AddUserToGroup) => action), @@ -79,64 +77,15 @@ export class UserEffects { catchError((error) => { this.toastrService.error(error.error.message); return of(new actions.AddUserToGroupFail(error)); -======= - addGroupToUser$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.ADD_GROUP_TO_USER), - map((action: actions.AddGroupToUser) => action), -======= - addUserToGroup$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.ADD_USER_TO_GROUP), - map((action: actions.AddUserToGroup) => action), ->>>>>>> refactor: TT-188 refactor some names - mergeMap((action) => - this.userService.addUserToGroup(action.userId, action.groupName).pipe( - map((response) => { - this.toastrService.success('Add user to group success'); - return new actions.AddUserToGroupSuccess(response); - }), - catchError((error) => { - this.toastrService.error(error.error.message); -<<<<<<< HEAD - return of(new actions.AddGroupToUserFail(error)); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - return of(new actions.AddUserToGroupFail(error)); ->>>>>>> refactor: TT-188 refactor some names }) ) ) ); @Effect() -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - removeUserFromGroup$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), - map((action: actions.RemoveUserFromGroup) => action), - mergeMap((action) => - this.userService.removeUserFromGroup(action.userId, action.groupName).pipe( - map((response) => { - this.toastrService.success('Remove user from group success'); - return new actions.RemoveUserFromGroupSuccess(response); - }), - catchError((error) => { - this.toastrService.error(error.error.message); - return of(new actions.RemoveUserFromGroupFail(error)); -======= - removeGroupToUser$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.REMOVE_GROUP_TO_USER), - map((action: actions.RemoveGroupToUser) => action), -======= - removeUserToGroup$: Observable = this.actions$.pipe( - ofType(actions.UserActionTypes.REMOVE_USER_TO_GROUP), - map((action: actions.RemoveUserToGroup) => action), ->>>>>>> refactor: TT-188 refactor some names -======= removeUserFromGroup$: Observable = this.actions$.pipe( ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP), map((action: actions.RemoveUserFromGroup) => action), ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references mergeMap((action) => this.userService.removeUserFromGroup(action.userId, action.groupName).pipe( map((response) => { @@ -145,16 +94,7 @@ export class UserEffects { }), catchError((error) => { this.toastrService.error(error.error.message); -<<<<<<< HEAD -<<<<<<< HEAD - return of(new actions.RemoveGroupToUserFail(error)); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - return of(new actions.RemoveUserToGroupFail(error)); ->>>>>>> refactor: TT-188 refactor some names -======= return of(new actions.RemoveUserFromGroupFail(error)); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }) ) ) diff --git a/src/app/modules/users/store/user.reducer.spec.ts b/src/app/modules/users/store/user.reducer.spec.ts index bcb1488ab..6180cfff4 100644 --- a/src/app/modules/users/store/user.reducer.spec.ts +++ b/src/app/modules/users/store/user.reducer.spec.ts @@ -93,59 +93,27 @@ describe('userReducer', () => { expect(state.isLoading).toEqual(false); }); -<<<<<<< HEAD -<<<<<<< HEAD it('on AddUserToGroup, isLoading is true', () => { const userId = 'userId'; const groupName = 'groupName'; const action = new actions.AddUserToGroup(userId, groupName); -======= - it('on AddGroupToUser, isLoading is true', () => { - const userId = 'userId'; - const groupName = 'groupName'; - const action = new actions.AddGroupToUser(userId, groupName); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - it('on AddUserToGroup, isLoading is true', () => { - const userId = 'userId'; - const groupName = 'groupName'; - const action = new actions.AddUserToGroup(userId, groupName); ->>>>>>> refactor: TT-188 refactor some names const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); -<<<<<<< HEAD -<<<<<<< HEAD - it('on AddUserToGroupSuccess, user groups should change', () => { -======= - it('on AddGroupToUserSuccess, user groups should change', () => { ->>>>>>> feat: TT-188 add ngrx flow & test -======= it('on AddUserToGroupSuccess, user groups should change', () => { ->>>>>>> refactor: TT-188 refactor some names const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: null }], isLoading: false, message: '', }; const userWithGroupAdded: User = { id: 'id', name: 'name', email: 'email', groups: ['group'] }; -<<<<<<< HEAD -<<<<<<< HEAD const action = new actions.AddUserToGroupSuccess(userWithGroupAdded); -======= - const action = new actions.AddGroupToUserSuccess(userWithGroupAdded); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - const action = new actions.AddUserToGroupSuccess(userWithGroupAdded); ->>>>>>> refactor: TT-188 refactor some names const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupAdded]); expect(state.isLoading).toEqual(false); -<<<<<<< HEAD -<<<<<<< HEAD expect(state.message).toEqual('Add user to group success'); }); @@ -158,115 +126,34 @@ describe('userReducer', () => { }); it('on RemoveUserFromGroup, isLoading is true', () => { -<<<<<<< HEAD - const userId = 'userId'; - const groupName = 'groupName'; - const action = new actions.RemoveUserFromGroup(userId, groupName); -======= - expect(state.message).toEqual('Add group to a user success'); -======= - expect(state.message).toEqual('Add user to group success'); ->>>>>>> refactor: TT-188 refactor some names - }); - - it('on AddUserToGroupFail, should show a message with an error message', () => { - const action = new actions.AddUserToGroupFail('error'); - const state = userReducer(initialState, action); - - expect(state.message).toEqual('Something went wrong adding user to group'); - expect(state.isLoading).toEqual(false); - }); - - it('on RemoveUserToGroup, isLoading is true', () => { - const userId = 'userId'; - const groupName = 'groupName'; -<<<<<<< HEAD - const action = new actions.RemoveGroupToUser(userId, groupName); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - const action = new actions.RemoveUserToGroup(userId, groupName); ->>>>>>> refactor: TT-188 refactor some names -======= const userId = 'userId'; const groupName = 'groupName'; const action = new actions.RemoveUserFromGroup(userId, groupName); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const state = userReducer(initialState, action); expect(state.isLoading).toEqual(true); }); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD it('on RemoveUserFromGroupSuccess, user groups should change', () => { -======= - it('on RemoveGroupToUserSuccess, user groups should change', () => { ->>>>>>> feat: TT-188 add ngrx flow & test -======= - it('on RemoveUserToGroupSuccess, user groups should change', () => { ->>>>>>> refactor: TT-188 refactor some names -======= - it('on RemoveUserFromGroupSuccess, user groups should change', () => { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const currentState: UserState = { data: [{ id: 'id', name: 'name', email: 'email', groups: ['group'] }], isLoading: false, message: '', }; const userWithGroupRemoved: User = { id: 'id', name: 'name', email: 'email', groups: null }; -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); -======= - const action = new actions.RemoveGroupToUserSuccess(userWithGroupRemoved); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - const action = new actions.RemoveUserToGroupSuccess(userWithGroupRemoved); ->>>>>>> refactor: TT-188 refactor some names -======= const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const state = userReducer(currentState, action); expect(state.data).toEqual([userWithGroupRemoved]); expect(state.isLoading).toEqual(false); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - expect(state.message).toEqual('Remove user from group success'); - }); - - it('on RemoveUserFromGroupFail, should show a message with an error message', () => { - const action = new actions.RemoveUserFromGroupFail('error'); - const state = userReducer(initialState, action); - - expect(state.message).toEqual('Something went wrong removing user from group'); -======= - expect(state.message).toEqual('Remove group to a user success'); -======= - expect(state.message).toEqual('Remove user to group success'); ->>>>>>> refactor: TT-188 refactor some names -======= expect(state.message).toEqual('Remove user from group success'); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }); it('on RemoveUserFromGroupFail, should show a message with an error message', () => { const action = new actions.RemoveUserFromGroupFail('error'); const state = userReducer(initialState, action); -<<<<<<< HEAD -<<<<<<< HEAD - expect(state.message).toEqual('Something went wrong removing group to a user'); ->>>>>>> feat: TT-188 add ngrx flow & test -======= - expect(state.message).toEqual('Something went wrong removing user to group'); ->>>>>>> refactor: TT-188 refactor some names -======= expect(state.message).toEqual('Something went wrong removing user from group'); ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references expect(state.isLoading).toEqual(false); }); diff --git a/src/app/modules/users/store/user.reducers.ts b/src/app/modules/users/store/user.reducers.ts index 5fef4fb21..8a1c75443 100644 --- a/src/app/modules/users/store/user.reducers.ts +++ b/src/app/modules/users/store/user.reducers.ts @@ -88,36 +88,18 @@ export const userReducer = (state: UserState = initialState, action: UserActions }; } -<<<<<<< HEAD -<<<<<<< HEAD case UserActionTypes.ADD_USER_TO_GROUP: { -======= - case UserActionTypes.ADD_GROUP_TO_USER: { ->>>>>>> feat: TT-188 add ngrx flow & test -======= - case UserActionTypes.ADD_USER_TO_GROUP: { ->>>>>>> refactor: TT-188 refactor some names return { ...state, isLoading: true, }; } -<<<<<<< HEAD -<<<<<<< HEAD - case UserActionTypes.ADD_USER_TO_GROUP_SUCCESS: { -======= - case UserActionTypes.ADD_GROUP_TO_USER_SUCCESS: { ->>>>>>> feat: TT-188 add ngrx flow & test -======= case UserActionTypes.ADD_USER_TO_GROUP_SUCCESS: { ->>>>>>> refactor: TT-188 refactor some names const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, -<<<<<<< HEAD -<<<<<<< HEAD message: 'Add user to group success', }; } @@ -130,89 +112,25 @@ export const userReducer = (state: UserState = initialState, action: UserActions } case UserActionTypes.REMOVE_USER_FROM_GROUP: { -======= - message: 'Add group to a user success', -======= - message: 'Add user to group success', ->>>>>>> refactor: TT-188 refactor some names - }; - } - case UserActionTypes.ADD_USER_TO_GROUP_FAIL: { - return { - ...state, - isLoading: false, - message: 'Something went wrong adding user to group', - }; - } - -<<<<<<< HEAD -<<<<<<< HEAD - case UserActionTypes.REMOVE_GROUP_TO_USER: { ->>>>>>> feat: TT-188 add ngrx flow & test -======= - case UserActionTypes.REMOVE_USER_TO_GROUP: { ->>>>>>> refactor: TT-188 refactor some names -======= - case UserActionTypes.REMOVE_USER_FROM_GROUP: { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references return { ...state, isLoading: true, }; } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { -======= - case UserActionTypes.REMOVE_GROUP_TO_USER_SUCCESS: { ->>>>>>> feat: TT-188 add ngrx flow & test -======= - case UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS: { ->>>>>>> refactor: TT-188 refactor some names -======= case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: { ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references const index = userData.findIndex((user) => user.id === action.payload.id); userData[index] = action.payload; return { data: userData, isLoading: false, -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - message: 'Remove user from group success', - }; - } - case UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL: { - return { - ...state, - isLoading: false, - message: 'Something went wrong removing user from group', -======= - message: 'Remove group to a user success', -======= - message: 'Remove user to group success', ->>>>>>> refactor: TT-188 refactor some names -======= message: 'Remove user from group success', ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }; } case UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL: { return { ...state, isLoading: false, -<<<<<<< HEAD -<<<<<<< HEAD - message: 'Something went wrong removing group to a user', ->>>>>>> feat: TT-188 add ngrx flow & test -======= - message: 'Something went wrong removing user to group', ->>>>>>> refactor: TT-188 refactor some names -======= message: 'Something went wrong removing user from group', ->>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references }; } default: From f86f4731aba5f355d474ceabed03df94f50d5fb4 Mon Sep 17 00:00:00 2001 From: Israel Leon Date: Tue, 30 Mar 2021 15:35:21 -0500 Subject: [PATCH 7/7] feat: TT-190 resolve coments --- .../users-list/users-list.component.html | 4 +- .../users-list/users-list.component.spec.ts | 36 +++++++++++----- .../users-list/users-list.component.ts | 43 ++++++++++--------- 3 files changed, 50 insertions(+), 33 deletions(-) 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 605a6811c..498d5e0dd 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 @@ -22,13 +22,13 @@
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 642fa0bea..efdc37085 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 @@ -12,6 +12,7 @@ import { 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'; @@ -118,12 +119,12 @@ describe('UsersListComponent', () => { }); }); - const actionsGroupsParams = [ + const actionGroupParams = [ { actionType: UserActionTypes.ADD_USER_TO_GROUP_SUCCESS }, { actionType: UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS }, ]; - actionsGroupsParams.map((param) => { + actionGroupParams.map((param) => { it(`When action ${param.actionType} is dispatched should triggered load Users action`, () => { spyOn(store, 'dispatch'); @@ -167,14 +168,21 @@ describe('UsersListComponent', () => { AddGroupTypes.map((param) => { it(`When user switchGroup to ${param.groupName} and doesn't belong to any group, should add ${param.groupName} group to user`, () => { const groupName = param.groupName; - const userGroups = []; - const userId = 'userId'; + const user = { + name: 'name', + email: 'email', + roles: [], + groups: [], + id: 'id', + tenant_id: 'tenant id', + deleted: 'delete', + } ; spyOn(store, 'dispatch'); - component.switchGroup(userId, userGroups, groupName); + component.switchGroup(groupName, user); - expect(store.dispatch).toHaveBeenCalledWith(new AddUserToGroup(userId, groupName)); + expect(store.dispatch).toHaveBeenCalledWith(new AddUserToGroup(user.id, groupName)); }); }); @@ -206,14 +214,22 @@ describe('UsersListComponent', () => { removeGroupTypes.map((param) => { it(`When user switchGroup to ${param.groupName} and belongs to group, should remove ${param.groupName} group from user`, () => { const groupName = param.groupName; - const userGroups = param.userGroups; - const userId = 'userId'; + const user = { + name: 'name', + email: 'email', + roles: [], + groups: param.userGroups, + id: 'id', + tenant_id: 'tenant id', + deleted: 'delete', + } ; + spyOn(store, 'dispatch'); - component.switchGroup(userId, userGroups, groupName); + component.switchGroup(groupName, user); - expect(store.dispatch).toHaveBeenCalledWith(new RemoveUserFromGroup(userId, groupName)); + expect(store.dispatch).toHaveBeenCalledWith(new RemoveUserFromGroup(user.id, groupName)); }); }); 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 06540501f..33ef09035 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 @@ -1,5 +1,5 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; -import { ActionsSubject, select, Store } from '@ngrx/store'; +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'; @@ -54,17 +54,9 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { this.isUserGroupsToggleOn = flag; }); - this.switchGroupsSubscription = this.actionsSubject$ - .pipe( - filter( - (action: any) => - action.type === UserActionTypes.ADD_USER_TO_GROUP_SUCCESS || - action.type === UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS - ) - ) - .subscribe((action) => { - this.store.dispatch(new LoadUsers()); - }); + this.switchGroupsSubscription = this.filterUserGroup().subscribe((action) => { + this.store.dispatch(new LoadUsers()); + }); this.switchRoleSubscription = this.actionsSubject$ .pipe( @@ -106,17 +98,26 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit { : this.store.dispatch(new GrantRoleUser(userId, roleId)); } - switchGroup(userId: string, userGroups: string[], groupName: string) { - userGroups.includes(groupName) - ? this.store.dispatch(new RemoveUserFromGroup(userId, groupName)) - : this.store.dispatch(new AddUserToGroup(userId, groupName)); + switchGroup(groupName: string, user: User): void { + this.store.dispatch( + user.groups.includes(groupName) + ? new RemoveUserFromGroup(user.id, groupName) + : new AddUserToGroup(user.id, groupName) + ); + } + + isFeatureToggleActivated(): Observable { + return this.featureManagerService.isToggleEnabledForUser('switch-group') + .pipe(map((enabled: boolean) => enabled)); } - isFeatureToggleActivated() { - return this.featureManagerService.isToggleEnabledForUser('switch-group').pipe( - map((enabled) => { - return enabled === true ? true : false; - }) + filterUserGroup(): Observable { + return this.actionsSubject$.pipe( + filter( + (action: Action) => + action.type === UserActionTypes.ADD_USER_TO_GROUP_SUCCESS || + action.type === UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS + ) ); } }