text: import mockFetch from "cross-fetch";
  import * as ActionTypes from "../constants/actionTypes";
  import * as ActionCreators from "./nodes";
  
  jest.mock("cross-fetch");
  
  describe("Actions", () => {
    const dispatch = jest.fn();
  
    afterAll(() => {
      dispatch.mockClear();
      mockFetch.mockClear();
    });
  
    const node = {
      url: "http://localhost:3002",
      online: false,
      name: null,
      blocks: undefined
    };
  
    it("should fetch the node status", async () => {
      mockFetch.mockReturnValueOnce(
        Promise.resolve({
          status: 200,
          json() {
            return Promise.resolve({ node_name: "Secret Lowlands" });
          },
        })
      );
      await ActionCreators.checkNodeStatus(node)(dispatch);
      const expected = [
        {
          type: ActionTypes.CHECK_NODE_STATUS_START,
          node,
        },
        {
          type: ActionTypes.CHECK_NODE_STATUS_SUCCESS,
          node,
          res: { node_name: "Secret Lowlands" },
        },
      ];
  
      expect(dispatch.mock.calls.flat()).toEqual(expected);
    });
  
    it("should fail to fetch the node status", async () => {
      mockFetch.mockReturnValueOnce(
        Promise.resolve({
          status: 400,
        })
      );
      await ActionCreators.checkNodeStatus(node)(dispatch);
      const expected = [
        {
          type: ActionTypes.CHECK_NODE_STATUS_START,
          node,
        },
        {
          type: ActionTypes.CHECK_NODE_STATUS_FAILURE,
          node,
        },
      ];
  
      expect(dispatch.mock.calls.flat()).toEqual(expected);
    });
  
    it("should fetch the node block", async () => {
      mockFetch.mockReturnValueOnce(
        Promise.resolve({
          status: 200,
          json() {
            return Promise.resolve({ data: [{id: '0'}] });
          },
        })
      );
      await ActionCreators.getNodeBlocks(node)(dispatch);
      const expected = [
        {
          type: ActionTypes.GET_NODE_BLOCKS_SUCCESS,
          node,
          res: [{id: '0'}],
        },
      ];
  
      expect(dispatch.mock.calls.flat()).toEqual(expected);
    });
  
    it("should fail to fetch the node blocks", async () => {
      mockFetch.mockReturnValueOnce(
        Promise.resolve({
          status: 400,
        })
      );
      await ActionCreators.getNodeBlocks(node)(dispatch);
      const expected = [
        {
          type: ActionTypes.GET_NODE_BLOCKS_FAILURE,
          node,
        },
      ];
  
      expect(dispatch.mock.calls.flat()).toEqual(expected);
    });
  
  
  });
  
  