diff --git a/src/app/modules/users/components/users-list/users-list.component.spec.ts b/src/app/modules/users/components/users-list/users-list.component.spec.ts index c04bc6894..8cd39d44a 100644 --- a/src/app/modules/users/components/users-list/users-list.component.spec.ts +++ b/src/app/modules/users/components/users-list/users-list.component.spec.ts @@ -14,7 +14,17 @@ describe('UsersListComponent', () => { const actionSub: ActionsSubject = new ActionsSubject(); const state: UserState = { - data: [{ name: 'name', email: 'email', role: 'role', id: 'id', tenant_id: 'tenant id', deleted: 'delete' }], + data: [ + { + name: 'name', + email: 'email', + role: null, + roles: ['admin', 'test'], + id: 'id', + tenant_id: 'tenant id', + deleted: 'delete', + }, + ], isLoading: false, message: '', }; @@ -59,6 +69,51 @@ describe('UsersListComponent', () => { expect(component.users).toEqual(state.data); }); + it('on success load users, the data of roles should be an array and role null', () => { + const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; + const action = { + type: UserActionTypes.LOAD_USERS_SUCCESS, + payload: state.data, + }; + + actionSubject.next(action); + + component.users.map((user) => { + expect(user.role).toEqual(null); + expect(user.roles).toEqual(['admin', 'test']); + }); + }); + + it('on success load users, the data of roles should be null and role a string', () => { + const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject; + const mockState: UserState = { + data: [ + { + name: 'name', + email: 'email', + role: 'admin', + roles: null, + id: 'id', + tenant_id: 'tenant id', + deleted: 'delete', + }, + ], + isLoading: false, + message: '', + }; + const action = { + type: UserActionTypes.LOAD_USERS_SUCCESS, + payload: mockState.data, + }; + + actionSubject.next(action); + + component.users.map((user) => { + expect(user.role).toEqual('admin'); + expect(user.roles).toEqual(null); + }); + }); + it('on success load users, the datatable should be reloaded', async () => { const actionSubject = TestBed.inject(ActionsSubject); const action = { diff --git a/src/app/modules/users/models/users.ts b/src/app/modules/users/models/users.ts index 3a7670f51..481fe3d5d 100644 --- a/src/app/modules/users/models/users.ts +++ b/src/app/modules/users/models/users.ts @@ -2,6 +2,7 @@ export interface User { name: string; email: string; role?: string; + roles?: string[]; id: string; tenant_id?: string; deleted?: string;