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 authored and LEON12699 committed Mar 30, 2021
commit bf896361891aab895fca9f289a60fa98170e86f3
8 changes: 8 additions & 0 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
});
Expand Down
8 changes: 8 additions & 0 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@ export class UsersService {
return this.http.post(url, null);
}

<<<<<<< HEAD
<<<<<<< HEAD
addUserToGroup(userId: string, group: string): Observable<User> {
=======
addGroupToUser(userId: string, group: string): Observable<User> {
>>>>>>> feat: TT-188 add & remove groups to user service
=======
addUserToGroup(userId: string, group: string): Observable<User> {
>>>>>>> refactor: TT-188 refactor some names
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/add`, {
group_name: group,
});
}

<<<<<<< HEAD
<<<<<<< HEAD
removeUserFromGroup(userId: string, group: string): Observable<User> {
=======
removeGroupToUser(userId: string, group: string): Observable<User> {
>>>>>>> feat: TT-188 add & remove groups to user service
=======
removeUserToGroup(userId: string, group: string): Observable<User> {
>>>>>>> refactor: TT-188 refactor some names
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
group_name: group,
});
Expand Down
40 changes: 24 additions & 16 deletions src/app/modules/users/store/user.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
});
});
44 changes: 36 additions & 8 deletions src/app/modules/users/store/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
}

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

Expand All @@ -148,6 +167,7 @@ export type UserActions =
| RevokeRoleUser
| RevokeRoleUserSuccess
| RevokeRoleUserFail
<<<<<<< HEAD
<<<<<<< HEAD
| AddUserToGroup
| AddUserToGroupSuccess
Expand All @@ -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
64 changes: 52 additions & 12 deletions src/app/modules/users/store/user.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));

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

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

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

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