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
5 changes: 0 additions & 5 deletions src/app/modules/users/models/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ export interface User {
tenant_id?: string;
deleted?: string;
}

export interface UserState extends User {
isLoading: boolean;
error: string;
}
43 changes: 43 additions & 0 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
it('AddUserToGroup type is UserActionTypes.ADD_USER_TO_GROUP', () => {
const userId = 'userId';
const groupName = 'groupName';
Expand Down Expand Up @@ -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
});
});
48 changes: 48 additions & 0 deletions src/app/modules/users/store/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

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

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

@Effect()
<<<<<<< HEAD
addUserToGroup$: Observable<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.ADD_USER_TO_GROUP),
map((action: actions.AddUserToGroup) => action),
Expand All @@ -77,12 +78,27 @@ export class UserEffects {
catchError((error) => {
this.toastrService.error(error.error.message);
return of(new actions.AddUserToGroupFail(error));
=======
addGroupToUser$: Observable<Action> = 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<Action> = this.actions$.pipe(
ofType(actions.UserActionTypes.REMOVE_USER_FROM_GROUP),
map((action: actions.RemoveUserFromGroup) => action),
Expand All @@ -95,6 +111,20 @@ export class UserEffects {
catchError((error) => {
this.toastrService.error(error.error.message);
return of(new actions.RemoveUserFromGroupFail(error));
=======
removeGroupToUser$: Observable<Action> = 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
})
)
)
Expand Down
Loading