Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: TT-188 refactor 'removeTo' to 'removeFrom' references
  • Loading branch information
thegreatyamori authored and LEON12699 committed Mar 30, 2021
commit dc4ebbc94b60fb1a554fba83c09327ac3188ad4a
12 changes: 12 additions & 0 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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();
Expand All @@ -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');
});
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class UsersService {
});
}

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
removeUserFromGroup(userId: string, group: string): Observable<User> {
Expand All @@ -48,6 +49,9 @@ export class UsersService {
=======
removeUserToGroup(userId: string, group: string): Observable<User> {
>>>>>>> refactor: TT-188 refactor some names
=======
removeUserFromGroup(userId: string, group: string): Observable<User> {
>>>>>>> refactor: TT-188 refactor 'removeTo' to 'removeFrom' references
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
group_name: group,
});
Expand Down
21 changes: 14 additions & 7 deletions src/app/modules/users/store/user.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
});
});
24 changes: 22 additions & 2 deletions src/app/modules/users/store/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down Expand Up @@ -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) {}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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) {}
}

Expand Down Expand Up @@ -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
33 changes: 28 additions & 5 deletions src/app/modules/users/store/user.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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));

Expand All @@ -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' } }));

Expand All @@ -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
});
});
});
16 changes: 13 additions & 3 deletions src/app/modules/users/store/user.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class UserEffects {

@Effect()
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
removeUserFromGroup$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP),
Expand All @@ -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<Action> = 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
})
)
)
Expand Down
Loading