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 some names
  • Loading branch information
thegreatyamori committed Mar 25, 2021
commit b00baf90218cd42e130c3a6103d046ea126eb3a7
4 changes: 2 additions & 2 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('UsersService', () => {
const group = 'admin';
const addGroupURL = `${service.baseUrl}/${userId}/groups/add`;

service.addGroupToUser(userId, group).subscribe();
service.addUserToGroup(userId, group).subscribe();

expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST');
});
Expand All @@ -67,7 +67,7 @@ describe('UsersService', () => {
const group = 'admin';
const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`;

service.removeGroupToUser(userId, group).subscribe();
service.removeUserToGroup(userId, group).subscribe();

expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST');
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export class UsersService {
return this.http.post(url, null);
}

addGroupToUser(userId: string, group: string): Observable<User> {
addUserToGroup(userId: string, group: string): Observable<User> {
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/add`, {
group_name: group,
});
}

removeGroupToUser(userId: string, group: string): Observable<User> {
removeUserToGroup(userId: string, group: string): Observable<User> {
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
group_name: group,
});
Expand Down
36 changes: 18 additions & 18 deletions src/app/modules/users/store/user.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,45 +53,45 @@ describe('UserActions', () => {
expect(action.type).toEqual(actions.UserActionTypes.REVOKE_USER_ROLE_FAIL);
});

it('AddGroupToUser type is UserActionTypes.ADD_GROUP_TO_USER', () => {
it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => {
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');

expect(action.type).toEqual(actions.UserActionTypes.REMOVE_GROUP_TO_USER_FAIL);
expect(action.type).toEqual(actions.UserActionTypes.REMOVE_USER_TO_GROUP_FAIL);
});
});
48 changes: 24 additions & 24 deletions src/app/modules/users/store/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +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',
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',
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',
DEFAULT_USER = '[USER] DEFAULT_USER',
}

Expand Down Expand Up @@ -64,33 +64,33 @@ export class RevokeRoleUserFail implements Action {
constructor(public error: string) {}
}

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;
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) {}
}

export class RemoveGroupToUserFail implements Action {
public readonly type = UserActionTypes.REMOVE_GROUP_TO_USER_FAIL;
export class RemoveUserToGroupFail implements Action {
public readonly type = UserActionTypes.REMOVE_USER_TO_GROUP_FAIL;
constructor(public error: string) {}
}

Expand All @@ -109,9 +109,9 @@ export type UserActions =
| RevokeRoleUser
| RevokeRoleUserSuccess
| RevokeRoleUserFail
| AddGroupToUser
| AddGroupToUserSuccess
| AddGroupToUserFail
| RemoveGroupToUser
| RemoveGroupToUserSuccess
| RemoveGroupToUserFail;
| AddUserToGroup
| AddUserToGroupSuccess
| AddUserToGroupFail
| RemoveUserToGroup
| RemoveUserToGroupSuccess
| RemoveUserToGroupFail;
44 changes: 22 additions & 22 deletions src/app/modules/users/store/user.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,75 +106,75 @@ describe('UserEffects', () => {
});
});

it('action type is ADD_GROUP_TO_USER_SUCCESS when service is executed sucessfully', async () => {
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_GROUP_TO_USER,
type: UserActionTypes.ADD_USER_TO_GROUP,
userId,
groupName,
});

spyOn(toastrService, 'success');
spyOn(service, 'addGroupToUser').and.returnValue(of(user));
spyOn(service, 'addUserToGroup').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);
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({
type: UserActionTypes.ADD_GROUP_TO_USER,
type: UserActionTypes.ADD_USER_TO_GROUP,
userId,
groupName,
});

spyOn(toastrService, 'error');
spyOn(service, 'addGroupToUser').and.returnValue(throwError({ error: { message: 'error' } }));
spyOn(service, 'addUserToGroup').and.returnValue(throwError({ error: { message: 'error' } }));

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({
type: UserActionTypes.REMOVE_GROUP_TO_USER,
type: UserActionTypes.REMOVE_USER_TO_GROUP,
userId,
groupName,
});

spyOn(toastrService, 'success');
spyOn(service, 'removeGroupToUser').and.returnValue(of(user));
spyOn(service, 'removeUserToGroup').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);
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({
type: UserActionTypes.REMOVE_GROUP_TO_USER,
type: UserActionTypes.REMOVE_USER_TO_GROUP,
userId,
groupName,
});

spyOn(toastrService, 'error');
spyOn(service, 'removeGroupToUser').and.returnValue(throwError({ error: { message: 'error' } }));
spyOn(service, 'removeUserToGroup').and.returnValue(throwError({ error: { message: 'error' } }));

effects.removeGroupToUser$.subscribe((action) => {
effects.removeUserToGroup$.subscribe((action) => {
expect(toastrService.error).toHaveBeenCalled();
expect(action.type).toEqual(UserActionTypes.REMOVE_GROUP_TO_USER_FAIL);
expect(action.type).toEqual(UserActionTypes.REMOVE_USER_TO_GROUP_FAIL);
});
});
});
28 changes: 14 additions & 14 deletions src/app/modules/users/store/user.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,36 @@ export class UserEffects {
);

@Effect()
addGroupToUser$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.ADD_GROUP_TO_USER),
map((action: actions.AddGroupToUser) => action),
addUserToGroup$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.ADD_USER_TO_GROUP),
map((action: actions.AddUserToGroup) => action),
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);
return of(new actions.AddGroupToUserFail(error));
return of(new actions.AddUserToGroupFail(error));
})
)
)
);

@Effect()
removeGroupToUser$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.REMOVE_GROUP_TO_USER),
map((action: actions.RemoveGroupToUser) => action),
removeUserToGroup$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.REMOVE_USER_TO_GROUP),
map((action: actions.RemoveUserToGroup) => action),
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);
return of(new actions.RemoveGroupToUserFail(error));
return of(new actions.RemoveUserToGroupFail(error));
})
)
)
Expand Down
Loading