Skip to content

Commit e5356d1

Browse files
refactor: TT-188 refactor 'removeTo' to 'removeFrom' references
1 parent b00baf9 commit e5356d1

File tree

8 files changed

+56
-56
lines changed

8 files changed

+56
-56
lines changed

src/app/modules/users/services/users.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('UsersService', () => {
5252
expect(grantRoleRequest.request.method).toBe('POST');
5353
});
5454

55-
it('add group to a User', () => {
55+
it('add user to group', () => {
5656
const userId = 'userId';
5757
const group = 'admin';
5858
const addGroupURL = `${service.baseUrl}/${userId}/groups/add`;
@@ -62,12 +62,12 @@ describe('UsersService', () => {
6262
expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST');
6363
});
6464

65-
it('remove group to a User', () => {
65+
it('remove user from group', () => {
6666
const userId = 'userId';
6767
const group = 'admin';
6868
const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`;
6969

70-
service.removeUserToGroup(userId, group).subscribe();
70+
service.removeUserFromGroup(userId, group).subscribe();
7171

7272
expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST');
7373
});

src/app/modules/users/services/users.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class UsersService {
3131
});
3232
}
3333

34-
removeUserToGroup(userId: string, group: string): Observable<User> {
34+
removeUserFromGroup(userId: string, group: string): Observable<User> {
3535
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
3636
group_name: group,
3737
});

src/app/modules/users/store/user.actions.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,24 @@ describe('UserActions', () => {
7474
expect(action.type).toEqual(actions.UserActionTypes.ADD_USER_TO_GROUP_FAIL);
7575
});
7676

77-
it('RemoveUserToGroup type is UserActionTypes.REMOVE_USER_TO_GROUP', () => {
77+
it('RemoveUserFromGroup type is UserActionTypes.REMOVE_USER_FROM_GROUP', () => {
7878
const userId = 'userId';
7979
const groupName = 'groupName';
80-
const action = new actions.RemoveUserToGroup(userId, groupName);
80+
const action = new actions.RemoveUserFromGroup(userId, groupName);
8181

82-
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP);
82+
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP);
8383
});
8484

85-
it('RemoveUserToGroupSuccess type is UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS', () => {
85+
it('RemoveUserFromGroupSuccess type is UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS', () => {
8686
const payload: User = { id: 'id', email: 'email', name: 'name' };
87-
const action = new actions.RemoveUserToGroupSuccess(payload);
87+
const action = new actions.RemoveUserFromGroupSuccess(payload);
8888

89-
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS);
89+
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS);
9090
});
9191

92-
it('RemoveUserToGroupFail type is UserActionTypes.REMOVE_USER_TO_GROUP_FAIL', () => {
93-
const action = new actions.RemoveUserToGroupFail('error');
92+
it('RemoveUserFromGroupFail type is UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL', () => {
93+
const action = new actions.RemoveUserFromGroupFail('error');
9494

95-
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_FAIL);
95+
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL);
9696
});
9797
});

src/app/modules/users/store/user.actions.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export enum UserActionTypes {
1414
ADD_USER_TO_GROUP = '[User] ADD_USER_TO_GROUP',
1515
ADD_USER_TO_GROUP_SUCCESS = '[User] ADD_USER_TO_GROUP_SUCCESS',
1616
ADD_USER_TO_GROUP_FAIL = '[User] ADD_USER_TO_GROUP_FAIL',
17-
REMOVE_USER_TO_GROUP = '[User] REMOVE_USER_TO_GROUP',
18-
REMOVE_USER_TO_GROUP_SUCCESS = '[User] REMOVE_USER_TO_GROUP_SUCCESS',
19-
REMOVE_USER_TO_GROUP_FAIL = '[User] REMOVE_USER_TO_GROUP_FAIL',
17+
REMOVE_USER_FROM_GROUP = '[User] REMOVE_USER_FROM_GROUP',
18+
REMOVE_USER_FROM_GROUP_SUCCESS = '[User] REMOVE_USER_FROM_GROUP_SUCCESS',
19+
REMOVE_USER_FROM_GROUP_FAIL = '[User] REMOVE_USER_FROM_GROUP_FAIL',
2020
DEFAULT_USER = '[USER] DEFAULT_USER',
2121
}
2222

@@ -79,18 +79,18 @@ export class AddUserToGroupFail implements Action {
7979
constructor(public error: string) {}
8080
}
8181

82-
export class RemoveUserToGroup implements Action {
83-
public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP;
82+
export class RemoveUserFromGroup implements Action {
83+
public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP;
8484
constructor(public userId: string, public groupName: string) {}
8585
}
8686

87-
export class RemoveUserToGroupSuccess implements Action {
88-
public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS;
87+
export class RemoveUserFromGroupSuccess implements Action {
88+
public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS;
8989
constructor(readonly payload: User) {}
9090
}
9191

92-
export class RemoveUserToGroupFail implements Action {
93-
public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_FAIL;
92+
export class RemoveUserFromGroupFail implements Action {
93+
public readonly type = UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL;
9494
constructor(public error: string) {}
9595
}
9696

@@ -112,6 +112,6 @@ export type UserActions =
112112
| AddUserToGroup
113113
| AddUserToGroupSuccess
114114
| AddUserToGroupFail
115-
| RemoveUserToGroup
116-
| RemoveUserToGroupSuccess
117-
| RemoveUserToGroupFail;
115+
| RemoveUserFromGroup
116+
| RemoveUserFromGroupSuccess
117+
| RemoveUserFromGroupFail;

src/app/modules/users/store/user.effects.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,39 +142,39 @@ describe('UserEffects', () => {
142142
});
143143
});
144144

145-
it('action type is REMOVE_USER_TO_GROUP_SUCCESS when service is executed succesfully', async () => {
145+
it('action type is REMOVE_USER_FROM_GROUP_SUCCESS when service is executed succesfully', async () => {
146146
const userId = 'userId';
147147
const groupName = 'groupName';
148148
actions$ = of({
149-
type: UserActionTypes.REMOVE_USER_TO_GROUP,
149+
type: UserActionTypes.REMOVE_USER_FROM_GROUP,
150150
userId,
151151
groupName,
152152
});
153153

154154
spyOn(toastrService, 'success');
155-
spyOn(service, 'removeUserToGroup').and.returnValue(of(user));
155+
spyOn(service, 'removeUserFromGroup').and.returnValue(of(user));
156156

157-
effects.removeUserToGroup$.subscribe((action) => {
158-
expect(toastrService.success).toHaveBeenCalledWith('Remove user to group success');
159-
expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS);
157+
effects.removeUserFromGroup$.subscribe((action) => {
158+
expect(toastrService.success).toHaveBeenCalledWith('Remove user from group success');
159+
expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS);
160160
});
161161
});
162162

163-
it('action type is REMOVE_USER_TO_GROUP_FAIL when service is executed succesfully', async () => {
163+
it('action type is REMOVE_USER_FROM_GROUP_FAIL when service is executed succesfully', async () => {
164164
const userId = 'userId';
165165
const groupName = 'groupName';
166166
actions$ = of({
167-
type: UserActionTypes.REMOVE_USER_TO_GROUP,
167+
type: UserActionTypes.REMOVE_USER_FROM_GROUP,
168168
userId,
169169
groupName,
170170
});
171171

172172
spyOn(toastrService, 'error');
173-
spyOn(service, 'removeUserToGroup').and.returnValue(throwError({ error: { message: 'error' } }));
173+
spyOn(service, 'removeUserFromGroup').and.returnValue(throwError({ error: { message: 'error' } }));
174174

175-
effects.removeUserToGroup$.subscribe((action) => {
175+
effects.removeUserFromGroup$.subscribe((action) => {
176176
expect(toastrService.error).toHaveBeenCalled();
177-
expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_FAIL);
177+
expect(action.type).toEqual(UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL);
178178
});
179179
});
180180
});

src/app/modules/users/store/user.effects.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ export class UserEffects {
8383
);
8484

8585
@Effect()
86-
removeUserToGroup$: Observable<Action> = this.actions$.pipe(
87-
ofType(actions.UserActionTypes.REMOVE_USER_TO_GROUP),
88-
map((action: actions.RemoveUserToGroup) => action),
86+
removeUserFromGroup$: Observable<Action> = this.actions$.pipe(
87+
ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP),
88+
map((action: actions.RemoveUserFromGroup) => action),
8989
mergeMap((action) =>
90-
this.userService.removeUserToGroup(action.userId, action.groupName).pipe(
90+
this.userService.removeUserFromGroup(action.userId, action.groupName).pipe(
9191
map((response) => {
92-
this.toastrService.success('Remove user to group success');
93-
return new actions.RemoveUserToGroupSuccess(response);
92+
this.toastrService.success('Remove user from group success');
93+
return new actions.RemoveUserFromGroupSuccess(response);
9494
}),
9595
catchError((error) => {
9696
this.toastrService.error(error.error.message);
97-
return of(new actions.RemoveUserToGroupFail(error));
97+
return of(new actions.RemoveUserFromGroupFail(error));
9898
})
9999
)
100100
)

src/app/modules/users/store/user.reducer.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,35 +125,35 @@ describe('userReducer', () => {
125125
expect(state.isLoading).toEqual(false);
126126
});
127127

128-
it('on RemoveUserToGroup, isLoading is true', () => {
128+
it('on RemoveUserFromGroup, isLoading is true', () => {
129129
const userId = 'userId';
130130
const groupName = 'groupName';
131-
const action = new actions.RemoveUserToGroup(userId, groupName);
131+
const action = new actions.RemoveUserFromGroup(userId, groupName);
132132
const state = userReducer(initialState, action);
133133

134134
expect(state.isLoading).toEqual(true);
135135
});
136136

137-
it('on RemoveUserToGroupSuccess, user groups should change', () => {
137+
it('on RemoveUserFromGroupSuccess, user groups should change', () => {
138138
const currentState: UserState = {
139139
data: [{ id: 'id', name: 'name', email: 'email', groups: ['group'] }],
140140
isLoading: false,
141141
message: '',
142142
};
143143
const userWithGroupRemoved: User = { id: 'id', name: 'name', email: 'email', groups: null };
144-
const action = new actions.RemoveUserToGroupSuccess(userWithGroupRemoved);
144+
const action = new actions.RemoveUserFromGroupSuccess(userWithGroupRemoved);
145145
const state = userReducer(currentState, action);
146146

147147
expect(state.data).toEqual([userWithGroupRemoved]);
148148
expect(state.isLoading).toEqual(false);
149-
expect(state.message).toEqual('Remove user to group success');
149+
expect(state.message).toEqual('Remove user from group success');
150150
});
151151

152-
it('on RemoveUserToGroupFail, should show a message with an error message', () => {
153-
const action = new actions.RemoveUserToGroupFail('error');
152+
it('on RemoveUserFromGroupFail, should show a message with an error message', () => {
153+
const action = new actions.RemoveUserFromGroupFail('error');
154154
const state = userReducer(initialState, action);
155155

156-
expect(state.message).toEqual('Something went wrong removing user to group');
156+
expect(state.message).toEqual('Something went wrong removing user from group');
157157
expect(state.isLoading).toEqual(false);
158158
});
159159

src/app/modules/users/store/user.reducers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,26 @@ export const userReducer = (state: UserState = initialState, action: UserActions
111111
};
112112
}
113113

114-
case UserActionTypes.REMOVE_USER_TO_GROUP: {
114+
case UserActionTypes.REMOVE_USER_FROM_GROUP: {
115115
return {
116116
...state,
117117
isLoading: true,
118118
};
119119
}
120-
case UserActionTypes.REMOVE_USER_TO_GROUP_SUCCESS: {
120+
case UserActionTypes.REMOVE_USER_FROM_GROUP_SUCCESS: {
121121
const index = userData.findIndex((user) => user.id === action.payload.id);
122122
userData[index] = action.payload;
123123
return {
124124
data: userData,
125125
isLoading: false,
126-
message: 'Remove user to group success',
126+
message: 'Remove user from group success',
127127
};
128128
}
129-
case UserActionTypes.REMOVE_USER_TO_GROUP_FAIL: {
129+
case UserActionTypes.REMOVE_USER_FROM_GROUP_FAIL: {
130130
return {
131131
...state,
132132
isLoading: false,
133-
message: 'Something went wrong removing user to group',
133+
message: 'Something went wrong removing user from group',
134134
};
135135
}
136136
default:

0 commit comments

Comments
 (0)