|
1 | 1 | import { cloneDeep, first } from 'lodash'
|
2 | 2 |
|
| 3 | +import { AxiosError } from 'axios' |
3 | 4 | import { AppDispatch, RootState } from 'uiSrc/slices/store'
|
4 | 5 | import { cleanup, clearStoreActions, initialStateDefault, mockedStore, mockStore, } from 'uiSrc/utils/test-utils'
|
5 | 6 | import { ClusterNodeRole, CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli'
|
6 | 7 | import { apiService } from 'uiSrc/services'
|
7 | 8 | import { cliTexts } from 'uiSrc/constants/cliOutput'
|
8 | 9 | import { cliParseTextResponseWithOffset, cliParseTextResponseWithRedirect } from 'uiSrc/utils/cliHelper'
|
9 | 10 | import ApiErrors from 'uiSrc/constants/apiErrors'
|
10 |
| -import { processCliClient, updateCliClientAction } from 'uiSrc/slices/cli/cli-settings' |
| 11 | +import { processCliClient } from 'uiSrc/slices/cli/cli-settings' |
| 12 | +import { addErrorNotification } from 'uiSrc/slices/app/notifications' |
11 | 13 | import { SendClusterCommandDto, SendClusterCommandResponse } from 'apiSrc/modules/cli/dto/cli.dto'
|
12 | 14 | import reducer, {
|
13 | 15 | concatToOutput,
|
| 16 | + fetchMonitorLog, |
14 | 17 | initialState,
|
15 | 18 | outputSelector,
|
16 | 19 | processUnsupportedCommand,
|
@@ -488,4 +491,54 @@ describe('cliOutput slice', () => {
|
488 | 491 | })
|
489 | 492 | })
|
490 | 493 | })
|
| 494 | + |
| 495 | + describe('fetchMonitorLog', () => { |
| 496 | + it('call both sendCliCommand and sendCliCommandSuccess when fetch is successed', async () => { |
| 497 | + // Arrange |
| 498 | + const fileIdMock = 'fileId' |
| 499 | + const onSuccessActionMock = jest.fn() |
| 500 | + const data = 'test' |
| 501 | + const responsePayload = { data, status: 200 } |
| 502 | + |
| 503 | + apiService.get = jest.fn().mockResolvedValue(responsePayload) |
| 504 | + |
| 505 | + // Act |
| 506 | + await store.dispatch<any>(fetchMonitorLog(fileIdMock, onSuccessActionMock)) |
| 507 | + |
| 508 | + // Assert |
| 509 | + const expectedActions = [ |
| 510 | + sendCliCommand(), |
| 511 | + sendCliCommandSuccess(), |
| 512 | + ] |
| 513 | + expect(store.getActions()).toEqual(expectedActions) |
| 514 | + expect(onSuccessActionMock).toBeCalled() |
| 515 | + }) |
| 516 | + |
| 517 | + it('call both sendCliCommand and sendCliCommandFailure when fetch is fail', async () => { |
| 518 | + // Arrange |
| 519 | + const fileIdMock = 'fileId' |
| 520 | + const onSuccessActionMock = jest.fn() |
| 521 | + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' |
| 522 | + const responsePayload = { |
| 523 | + response: { |
| 524 | + status: 500, |
| 525 | + data: { message: errorMessage }, |
| 526 | + }, |
| 527 | + } |
| 528 | + |
| 529 | + apiService.get = jest.fn().mockRejectedValueOnce(responsePayload) |
| 530 | + |
| 531 | + // Act |
| 532 | + await store.dispatch<any>(fetchMonitorLog(fileIdMock, onSuccessActionMock)) |
| 533 | + |
| 534 | + // Assert |
| 535 | + const expectedActions = [ |
| 536 | + sendCliCommand(), |
| 537 | + addErrorNotification(responsePayload as AxiosError), |
| 538 | + sendCliCommandFailure(responsePayload.response.data.message), |
| 539 | + ] |
| 540 | + expect(store.getActions()).toEqual(expectedActions) |
| 541 | + expect(onSuccessActionMock).not.toBeCalled() |
| 542 | + }) |
| 543 | + }) |
491 | 544 | })
|
0 commit comments