text: import MockAdapter from "axios-mock-adapter";
  import axios from "axios";
  import {
    createMinespaceUser,
    fetchMinespaceUsers,
    deleteMinespaceUser,
  } from "@common/actionCreators/minespaceActionCreator";
  import * as genericActions from "@common/actions/genericActions";
  import { ENVIRONMENT } from "@common/constants/environment";
  import * as API from "@common/constants/API";
  import * as MOCK from "@/tests/mocks/dataMocks";
  
  const dispatch = jest.fn();
  const requestSpy = jest.spyOn(genericActions, "request");
  const successSpy = jest.spyOn(genericActions, "success");
  const errorSpy = jest.spyOn(genericActions, "error");
  const mockAxios = new MockAdapter(axios);
  
  jest.setTimeout(30000);
  
  beforeEach(() => {
    mockAxios.reset();
    dispatch.mockClear();
    requestSpy.mockClear();
    successSpy.mockClear();
    errorSpy.mockClear();
  });
  
  describe("`fetchMinespaceUsers` action creator", () => {
    const url = ENVIRONMENT.apiUrl + API.MINESPACE_USER;
    it("Request successful, dispatches `success` with correct response", () => {
      const mockResponse = { data: { success: true } };
      mockAxios.onGet(url).reply(200, mockResponse);
      return fetchMinespaceUsers()(dispatch).then(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(successSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(5);
      });
    });
  
    it("Request failure, dispatches `error` with correct response", () => {
      mockAxios.onGet(url, MOCK.createMockHeader()).reply(418, MOCK.ERROR);
      return fetchMinespaceUsers()(dispatch).then(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(errorSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(4);
      });
    });
  });
  
  describe("`createMinespaceUser` action creator", () => {
    const mock_email = "Mock@mock.com";
    const mine_guids = ["12345-6789"];
    const url = ENVIRONMENT.apiUrl + API.MINESPACE_USER;
    const mockPayload = { email: mock_email, mine_guids };
    it("Request successful, dispatches `success` with correct response", () => {
      const mockResponse = { data: { success: true } };
      mockAxios.onPost(url, mockPayload).reply(200, mockResponse);
      return createMinespaceUser(mockPayload)(dispatch).then(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(successSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(4);
      });
    });
  
    it("Request failure, dispatches `error` with correct response", () => {
      mockAxios.onPost(url).reply(418, MOCK.ERROR);
      return createMinespaceUser({})(dispatch).catch(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(errorSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(4);
      });
    });
  });
  
  describe("`deleteMinespaceUser` action creator", () => {
    const minespaceUserId = "2";
    const url = `${ENVIRONMENT.apiUrl + API.MINESPACE_USER}/${minespaceUserId}`;
    it("Request successful, dispatches `success` with correct response", () => {
      const mockResponse = { data: { success: true } };
      mockAxios.onDelete(url).reply(200, mockResponse);
      return deleteMinespaceUser(minespaceUserId)(dispatch).then(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(successSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(4);
      });
    });
  
    it("Request failure, dispatches `error` with correct response", () => {
      mockAxios.onDelete(url).reply(418, MOCK.ERROR);
      return deleteMinespaceUser("")(dispatch).catch(() => {
        expect(requestSpy).toHaveBeenCalledTimes(1);
        expect(errorSpy).toHaveBeenCalledTimes(1);
        expect(dispatch).toHaveBeenCalledTimes(4);
      });
    });
  });
  