Skip to content

Commit 8058078

Browse files
authored
TT-111 fix: Add a roles field in Users (#614)
* TT-111 fix: Add a roles field in Users * TT-111 fix: add a test to check new model of users * TT-111 fix: add a new test for user roles
1 parent 9efe61b commit 8058078

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/app/modules/users/components/users-list/users-list.component.spec.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ describe('UsersListComponent', () => {
1414
const actionSub: ActionsSubject = new ActionsSubject();
1515

1616
const state: UserState = {
17-
data: [{ name: 'name', email: 'email', role: 'role', id: 'id', tenant_id: 'tenant id', deleted: 'delete' }],
17+
data: [
18+
{
19+
name: 'name',
20+
email: 'email',
21+
role: null,
22+
roles: ['admin', 'test'],
23+
id: 'id',
24+
tenant_id: 'tenant id',
25+
deleted: 'delete',
26+
},
27+
],
1828
isLoading: false,
1929
message: '',
2030
};
@@ -59,6 +69,51 @@ describe('UsersListComponent', () => {
5969
expect(component.users).toEqual(state.data);
6070
});
6171

72+
it('on success load users, the data of roles should be an array and role null', () => {
73+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
74+
const action = {
75+
type: UserActionTypes.LOAD_USERS_SUCCESS,
76+
payload: state.data,
77+
};
78+
79+
actionSubject.next(action);
80+
81+
component.users.map((user) => {
82+
expect(user.role).toEqual(null);
83+
expect(user.roles).toEqual(['admin', 'test']);
84+
});
85+
});
86+
87+
it('on success load users, the data of roles should be null and role a string', () => {
88+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
89+
const mockState: UserState = {
90+
data: [
91+
{
92+
name: 'name',
93+
email: 'email',
94+
role: 'admin',
95+
roles: null,
96+
id: 'id',
97+
tenant_id: 'tenant id',
98+
deleted: 'delete',
99+
},
100+
],
101+
isLoading: false,
102+
message: '',
103+
};
104+
const action = {
105+
type: UserActionTypes.LOAD_USERS_SUCCESS,
106+
payload: mockState.data,
107+
};
108+
109+
actionSubject.next(action);
110+
111+
component.users.map((user) => {
112+
expect(user.role).toEqual('admin');
113+
expect(user.roles).toEqual(null);
114+
});
115+
});
116+
62117
it('on success load users, the datatable should be reloaded', async () => {
63118
const actionSubject = TestBed.inject(ActionsSubject);
64119
const action = {

src/app/modules/users/models/users.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface User {
22
name: string;
33
email: string;
44
role?: string;
5+
roles?: string[];
56
id: string;
67
tenant_id?: string;
78
deleted?: string;

0 commit comments

Comments
 (0)