@@ -93,6 +93,70 @@ describe('userReducer', () => {
93
93
expect ( state . isLoading ) . toEqual ( false ) ;
94
94
} ) ;
95
95
96
+ it ( 'on AddUserToGroup, isLoading is true' , ( ) => {
97
+ const userId = 'userId' ;
98
+ const groupName = 'groupName' ;
99
+ const action = new actions . AddUserToGroup ( userId , groupName ) ;
100
+ const state = userReducer ( initialState , action ) ;
101
+
102
+ expect ( state . isLoading ) . toEqual ( true ) ;
103
+ } ) ;
104
+
105
+ it ( 'on AddUserToGroupSuccess, user groups should change' , ( ) => {
106
+ const currentState : UserState = {
107
+ data : [ { id : 'id' , name : 'name' , email : 'email' , groups : null } ] ,
108
+ isLoading : false ,
109
+ message : '' ,
110
+ } ;
111
+ const userWithGroupAdded : User = { id : 'id' , name : 'name' , email : 'email' , groups : [ 'group' ] } ;
112
+ const action = new actions . AddUserToGroupSuccess ( userWithGroupAdded ) ;
113
+ const state = userReducer ( currentState , action ) ;
114
+
115
+ expect ( state . data ) . toEqual ( [ userWithGroupAdded ] ) ;
116
+ expect ( state . isLoading ) . toEqual ( false ) ;
117
+ expect ( state . message ) . toEqual ( 'Add user to group success' ) ;
118
+ } ) ;
119
+
120
+ it ( 'on AddUserToGroupFail, should show a message with an error message' , ( ) => {
121
+ const action = new actions . AddUserToGroupFail ( 'error' ) ;
122
+ const state = userReducer ( initialState , action ) ;
123
+
124
+ expect ( state . message ) . toEqual ( 'Something went wrong adding user to group' ) ;
125
+ expect ( state . isLoading ) . toEqual ( false ) ;
126
+ } ) ;
127
+
128
+ it ( 'on RemoveUserFromGroup, isLoading is true' , ( ) => {
129
+ const userId = 'userId' ;
130
+ const groupName = 'groupName' ;
131
+ const action = new actions . RemoveUserFromGroup ( userId , groupName ) ;
132
+ const state = userReducer ( initialState , action ) ;
133
+
134
+ expect ( state . isLoading ) . toEqual ( true ) ;
135
+ } ) ;
136
+
137
+ it ( 'on RemoveUserFromGroupSuccess, user groups should change' , ( ) => {
138
+ const currentState : UserState = {
139
+ data : [ { id : 'id' , name : 'name' , email : 'email' , groups : [ 'group' ] } ] ,
140
+ isLoading : false ,
141
+ message : '' ,
142
+ } ;
143
+ const userWithGroupRemoved : User = { id : 'id' , name : 'name' , email : 'email' , groups : null } ;
144
+ const action = new actions . RemoveUserFromGroupSuccess ( userWithGroupRemoved ) ;
145
+ const state = userReducer ( currentState , action ) ;
146
+
147
+ expect ( state . data ) . toEqual ( [ userWithGroupRemoved ] ) ;
148
+ expect ( state . isLoading ) . toEqual ( false ) ;
149
+ expect ( state . message ) . toEqual ( 'Remove user from group success' ) ;
150
+ } ) ;
151
+
152
+ it ( 'on RemoveUserFromGroupFail, should show a message with an error message' , ( ) => {
153
+ const action = new actions . RemoveUserFromGroupFail ( 'error' ) ;
154
+ const state = userReducer ( initialState , action ) ;
155
+
156
+ expect ( state . message ) . toEqual ( 'Something went wrong removing user from group' ) ;
157
+ expect ( state . isLoading ) . toEqual ( false ) ;
158
+ } ) ;
159
+
96
160
it ( 'on Default, ' , ( ) => {
97
161
const action = new actions . DefaultUser ( ) ;
98
162
const state = userReducer ( initialState , action ) ;
0 commit comments