@@ -13,10 +13,15 @@ import reducer, {
13
13
instancesSelector ,
14
14
fetchConnectedInstanceAction ,
15
15
checkConnectToRdiInstanceAction ,
16
- } from 'uiSrc/slices/rdi/instances'
16
+ editInstanceAction ,
17
+ defaultInstanceChanging ,
18
+ defaultInstanceChangingSuccess ,
19
+ defaultInstanceChangingFailure ,
20
+ updateConnectedInstance } from 'uiSrc/slices/rdi/instances'
17
21
import { apiService } from 'uiSrc/services'
18
22
import { addErrorNotification , IAddInstanceErrorPayload } from 'uiSrc/slices/app/notifications'
19
23
import { RdiInstance } from 'uiSrc/slices/interfaces'
24
+ import { Rdi } from 'apiSrc/modules/rdi/models'
20
25
21
26
let store : typeof mockedStore
22
27
@@ -160,6 +165,31 @@ describe('rdi instances slice', () => {
160
165
} )
161
166
} )
162
167
168
+ describe ( 'updateConnectedInstance' , ( ) => {
169
+ it ( 'should properly update connected instance' , ( ) => {
170
+ // Arrange
171
+ const state = {
172
+ ...initialState ,
173
+ connectedInstance : {
174
+ ...initialState . connectedInstance ,
175
+ ...mockRdiInstance ,
176
+ }
177
+ }
178
+
179
+ // Act
180
+ const nextState = reducer ( initialState , updateConnectedInstance ( mockRdiInstance as Rdi ) )
181
+
182
+ // Assert
183
+ const rootState = Object . assign ( initialStateDefault , {
184
+ rdi : {
185
+ instances : nextState
186
+ } ,
187
+ } )
188
+
189
+ expect ( instancesSelector ( rootState ) ) . toEqual ( state )
190
+ } )
191
+ } )
192
+
163
193
// thunks
164
194
165
195
describe ( 'thunks' , ( ) => {
@@ -210,6 +240,55 @@ describe('rdi instances slice', () => {
210
240
} )
211
241
} )
212
242
243
+ describe ( 'editInstanceAction' , ( ) => {
244
+ it ( 'succeed to edit data and calls a success callback' , async ( ) => {
245
+ const onSuccess = jest . fn ( )
246
+ const responsePayload = { data : mockRdiInstance , status : 200 }
247
+
248
+ apiService . patch = jest . fn ( ) . mockResolvedValue ( responsePayload )
249
+
250
+ // Act
251
+ await store . dispatch < any > (
252
+ editInstanceAction ( '123' , mockRdiInstance , onSuccess )
253
+ )
254
+
255
+ // Assert
256
+ const expectedActions = [
257
+ defaultInstanceChanging ( ) ,
258
+ defaultInstanceChangingSuccess ( ) ,
259
+ ]
260
+
261
+ expect ( store . getActions ( ) ) . toEqual ( expect . arrayContaining ( expectedActions ) )
262
+ expect ( onSuccess ) . toBeCalledWith ( mockRdiInstance )
263
+ } )
264
+
265
+ it ( 'failed to edit data' , async ( ) => {
266
+ const errorMessage = 'Something was wrong!'
267
+ const responsePayload = {
268
+ response : {
269
+ status : 500 ,
270
+ data : { message : errorMessage } ,
271
+ } ,
272
+ }
273
+
274
+ apiService . patch = jest . fn ( ) . mockRejectedValue ( responsePayload )
275
+
276
+ // Act
277
+ await store . dispatch < any > (
278
+ editInstanceAction ( '123' , mockRdiInstance )
279
+ )
280
+
281
+ // Assert
282
+ const expectedActions = [
283
+ defaultInstanceChanging ( ) ,
284
+ defaultInstanceChangingFailure ( errorMessage ) ,
285
+ addErrorNotification ( responsePayload as AxiosError ) ,
286
+ ]
287
+
288
+ expect ( store . getActions ( ) ) . toEqual ( expectedActions )
289
+ } )
290
+ } )
291
+
213
292
describe ( 'checkConnectToRdiInstanceAction' , ( ) => {
214
293
it ( 'succeed to fetch data' , async ( ) => {
215
294
const responsePayload = { status : 200 }
0 commit comments