-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [IOCOM-1822] fims history export saga tests (#6677)
## Short description addition of said tests ## List of changes proposed in this pull request - required saga tests ## How to test automated tests should pass
- Loading branch information
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
ts/features/fims/history/saga/__tests__/handleExportFimsHistorySaga.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
jest.mock("../../../common/analytics"); | ||
import * as E from "fp-ts/Either"; | ||
import { expectSaga, testSaga } from "redux-saga-test-plan"; | ||
import { withRefreshApiCall } from "../../../../fastLogin/saga/utils"; | ||
import { trackExportSucceeded } from "../../../common/analytics"; | ||
import { FimsHistoryClient } from "../../api/client"; | ||
import { fimsHistoryExport } from "../../store/actions"; | ||
import { handleExportFimsHistorySaga } from "../handleExportFimsHistorySaga"; | ||
|
||
describe("handleExportFimsHistorySaga", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.resetAllMocks(); | ||
}); | ||
type ResponseType = Awaited<ReturnType<FimsHistoryClient["requestExport"]>>; | ||
const mockBearerToken = "mockBearerToken"; | ||
const mockAction = fimsHistoryExport.request(); | ||
|
||
it("should correctly pass the bearerToken to the client, dispatch success with payload 'SUCCESS' and track the export success when status is 202", () => { | ||
const response = E.right({ status: 202 }) as ResponseType; | ||
|
||
const resultPromise = Promise.resolve(response); | ||
const mockClient = jest.fn(() => resultPromise); | ||
testSaga( | ||
handleExportFimsHistorySaga, | ||
mockClient, | ||
mockBearerToken, | ||
mockAction | ||
) | ||
.next() | ||
.call(withRefreshApiCall, resultPromise, mockAction) | ||
.next(response) | ||
.put(fimsHistoryExport.success("SUCCESS")) | ||
.next() | ||
.isDone(); | ||
|
||
expect(mockClient).toHaveBeenCalledWith({ | ||
Bearer: `Bearer ${mockBearerToken}` | ||
}); | ||
expect(trackExportSucceeded).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should dispatch success with payload "ALREADY_EXPORTING", but not track an export success when status is 409 ', () => { | ||
const response = E.right({ status: 409 }) as ResponseType; | ||
|
||
const resultPromise = Promise.resolve(response); | ||
const mockClient = jest.fn(() => resultPromise); | ||
testSaga( | ||
handleExportFimsHistorySaga, | ||
mockClient, | ||
mockBearerToken, | ||
mockAction | ||
) | ||
.next() | ||
.call(withRefreshApiCall, resultPromise, mockAction) | ||
.next(response) | ||
.put(fimsHistoryExport.success("ALREADY_EXPORTING")) | ||
.next() | ||
.isDone(); | ||
expect(trackExportSucceeded).toHaveBeenCalledTimes(0); | ||
}); | ||
it("should dispatch failure when status is anything else ", () => { | ||
const response = E.right({ status: 418 }) as ResponseType; | ||
|
||
const resultPromise = Promise.resolve(response); | ||
const mockClient = jest.fn(() => resultPromise); | ||
testSaga( | ||
handleExportFimsHistorySaga, | ||
mockClient, | ||
mockBearerToken, | ||
mockAction | ||
) | ||
.next() | ||
.call(withRefreshApiCall, resultPromise, mockAction) | ||
.next(response) | ||
.put(fimsHistoryExport.failure()) | ||
.next() | ||
.isDone(); | ||
}); | ||
it("should dispatch failure when decoding fails", () => { | ||
const response = E.left({ status: 202 }) as ResponseType; | ||
|
||
const resultPromise = Promise.resolve(response); | ||
const mockClient = jest.fn(() => resultPromise); | ||
testSaga( | ||
handleExportFimsHistorySaga, | ||
mockClient, | ||
mockBearerToken, | ||
mockAction | ||
) | ||
.next() | ||
.call(withRefreshApiCall, resultPromise, mockAction) | ||
.next(response) | ||
.put(fimsHistoryExport.failure()) | ||
.next() | ||
.isDone(); | ||
}); | ||
it("should dispatch failure when promise is rejected", async () => { | ||
const response = E.right({ status: 202 }) as ResponseType; | ||
|
||
const resultPromise = Promise.reject(response); | ||
const mockClient = jest.fn(() => resultPromise); | ||
|
||
return expectSaga( | ||
handleExportFimsHistorySaga, | ||
mockClient, | ||
mockBearerToken, | ||
mockAction | ||
) | ||
.put(fimsHistoryExport.failure()) | ||
.run(); | ||
}); | ||
}); |