Skip to content

Commit

Permalink
test: [IOCOM-1822] fims history export saga tests (#6677)
Browse files Browse the repository at this point in the history
## 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
forrest57 authored Feb 3, 2025
1 parent 313e6ab commit 211d849
Showing 1 changed file with 112 additions and 0 deletions.
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();
});
});

0 comments on commit 211d849

Please sign in to comment.