@@ -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 = {
0 commit comments