@@ -206,21 +206,33 @@ describe('workbench results slice', () => {
206
206
} )
207
207
208
208
describe ( 'thunks' , ( ) => {
209
- describe ( 'Standalone Cli command ' , ( ) => {
209
+ describe ( 'Standalone Cli commands ' , ( ) => {
210
210
it ( 'call both sendWBCommandAction and sendWBCommandSuccess when response status is successed' , async ( ) => {
211
211
// Arrange
212
- const commands = [ 'keys *' ]
212
+ const commands = [ 'keys *' , 'set 1 1' ]
213
213
const commandId = `${ Date . now ( ) } `
214
- const data = [ {
215
- command : 'command' ,
216
- databaseId : '123' ,
217
- id : commandId + ( commands . length - 1 ) ,
218
- createdAt : new Date ( ) ,
219
- result : [ {
220
- response : 'test' ,
221
- status : CommandExecutionStatus . Success
222
- } ]
223
- } ]
214
+ const data = [
215
+ {
216
+ command : 'keys *' ,
217
+ databaseId : '123' ,
218
+ id : commandId + ( commands . length - 1 ) ,
219
+ createdAt : new Date ( ) ,
220
+ result : [ {
221
+ response : 'test' ,
222
+ status : CommandExecutionStatus . Success
223
+ } ]
224
+ } ,
225
+ {
226
+ command : 'set 1 1' ,
227
+ databaseId : '123' ,
228
+ id : commandId + ( commands . length - 1 ) ,
229
+ createdAt : new Date ( ) ,
230
+ result : [ {
231
+ response : 'test' ,
232
+ status : CommandExecutionStatus . Success
233
+ } ]
234
+ }
235
+ ]
224
236
const responsePayload = { data, status : 200 }
225
237
226
238
apiService . post = jest . fn ( ) . mockResolvedValue ( responsePayload )
@@ -238,9 +250,9 @@ describe('workbench results slice', () => {
238
250
239
251
it ( 'call both sendWBCommandAction and sendWBCommandSuccess when response status is fail' , async ( ) => {
240
252
// Arrange
241
- const command = 'keys *'
253
+ const commands = [ 'keys *' ]
242
254
const commandId = `${ Date . now ( ) } `
243
- const data = {
255
+ const data = [ {
244
256
command : 'command' ,
245
257
databaseId : '123' ,
246
258
id : commandId ,
@@ -249,17 +261,17 @@ describe('workbench results slice', () => {
249
261
response : 'test' ,
250
262
status : CommandExecutionStatus . Fail
251
263
} ]
252
- }
264
+ } ]
253
265
const responsePayload = { data, status : 200 }
254
266
255
267
apiService . post = jest . fn ( ) . mockResolvedValue ( responsePayload )
256
268
257
269
// Act
258
- await store . dispatch < any > ( sendWBCommandAction ( { command , commandId } ) )
270
+ await store . dispatch < any > ( sendWBCommandAction ( { commands , commandId } ) )
259
271
260
272
// Assert
261
273
const expectedActions = [
262
- sendWBCommand ( { command , commandId } ) ,
274
+ sendWBCommand ( { commands , commandId } ) ,
263
275
sendWBCommandSuccess ( { data, commandId } )
264
276
]
265
277
@@ -268,7 +280,7 @@ describe('workbench results slice', () => {
268
280
269
281
it ( 'call both sendWBCommandAction and processWBCommandFailure when fetch is fail' , async ( ) => {
270
282
// Arrange
271
- const command = 'keys *'
283
+ const commands = [ 'keys *' ]
272
284
const commandId = `${ Date . now ( ) } `
273
285
const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'
274
286
const responsePayload = {
@@ -281,13 +293,13 @@ describe('workbench results slice', () => {
281
293
apiService . post = jest . fn ( ) . mockRejectedValueOnce ( responsePayload )
282
294
283
295
// Act
284
- await store . dispatch < any > ( sendWBCommandAction ( { command , commandId } ) )
296
+ await store . dispatch < any > ( sendWBCommandAction ( { commands , commandId } ) )
285
297
286
298
// Assert
287
299
const expectedActions = [
288
- sendWBCommand ( { command , commandId } ) ,
300
+ sendWBCommand ( { commands , commandId } ) ,
289
301
addErrorNotification ( responsePayload as AxiosError ) ,
290
- processWBCommandFailure ( { command , error : responsePayload . response . data . message } ) ,
302
+ processWBCommandFailure ( { id : commandId , error : responsePayload . response . data . message } ) ,
291
303
]
292
304
expect ( clearStoreActions ( store . getActions ( ) ) ) . toEqual ( clearStoreActions ( expectedActions ) )
293
305
} )
@@ -335,8 +347,8 @@ describe('workbench results slice', () => {
335
347
336
348
it ( 'call both sendWBCommandClusterAction and sendWBCommandSuccess when response status is fail' , async ( ) => {
337
349
// Arrange
338
- const command = 'keys *'
339
- const data = {
350
+ const commands = [ 'keys *' ]
351
+ const data = [ {
340
352
command : 'command' ,
341
353
databaseId : '123' ,
342
354
id : commandId ,
@@ -345,25 +357,25 @@ describe('workbench results slice', () => {
345
357
response : 'test' ,
346
358
status : CommandExecutionStatus . Fail
347
359
} ]
348
- }
360
+ } ]
349
361
const responsePayload = { data, status : 200 }
350
362
351
363
apiService . post = jest . fn ( ) . mockResolvedValue ( responsePayload )
352
364
353
365
// Act
354
- await store . dispatch < any > ( sendWBCommandClusterAction ( { command , options, commandId } ) )
366
+ await store . dispatch < any > ( sendWBCommandClusterAction ( { commands , options, commandId } ) )
355
367
356
368
// Assert
357
369
const expectedActions = [
358
- sendWBCommand ( { command , commandId } ) ,
370
+ sendWBCommand ( { commands , commandId } ) ,
359
371
sendWBCommandSuccess ( { data, commandId } )
360
372
]
361
373
expect ( clearStoreActions ( store . getActions ( ) ) ) . toEqual ( clearStoreActions ( expectedActions ) )
362
374
} )
363
375
364
376
it ( 'call both sendWBCommandClusterAction and processWBCommandFailure when fetch is fail' , async ( ) => {
365
377
// Arrange
366
- const command = 'keys *'
378
+ const commands = [ 'keys *' ]
367
379
const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'
368
380
const responsePayload = {
369
381
response : {
@@ -375,13 +387,13 @@ describe('workbench results slice', () => {
375
387
apiService . post = jest . fn ( ) . mockRejectedValueOnce ( responsePayload )
376
388
377
389
// Act
378
- await store . dispatch < any > ( sendWBCommandAction ( { command , options, commandId } ) )
390
+ await store . dispatch < any > ( sendWBCommandAction ( { commands , options, commandId } ) )
379
391
380
392
// Assert
381
393
const expectedActions = [
382
- sendWBCommand ( { command , commandId } ) ,
394
+ sendWBCommand ( { commands , commandId } ) ,
383
395
addErrorNotification ( responsePayload as AxiosError ) ,
384
- processWBCommandFailure ( { command , error : responsePayload . response . data . message } ) ,
396
+ processWBCommandFailure ( { id : commandId , error : responsePayload . response . data . message } ) ,
385
397
]
386
398
expect ( clearStoreActions ( store . getActions ( ) ) ) . toEqual ( clearStoreActions ( expectedActions ) )
387
399
} )
0 commit comments