import reducer from "../../../store/reducers/candidates/candidatesReducer";
import expect from "expect";
import {
  filterCandidatesError,
  filterCandidatesSuccess,
  fetchAdsCandidatesSuccess,
  fetchAdsCandidatesError,
} from "../../../store/actions/candidates/candidatesActions";
import { mockState } from "../../../mockState";

describe("candidates reducer", () => {
  it("should return the initial state", () => {
    expect(reducer(undefined, {})).toEqual({
      candidates: [],
      adsCandidates: [],
      errorMessage: "",
      pagination: 0,
    });
  });

  it("should set the state error when filterCandidates is called", () => {
    expect(reducer(undefined, filterCandidatesError("Error"))).toEqual({
      candidates: [],
      adsCandidates: [],
      errorMessage: "Error",
      pagination: 0,
    });
  });

  it("should set candidates and pagination", () => {
    expect(
      reducer(
        undefined,
        filterCandidatesSuccess({ items: [mockState.candidates[0]], total: 1 })
      )
    ).toEqual({
      candidates: [mockState.candidates[0]],
      adsCandidates: [],
      errorMessage: "",
      pagination: 1,
    });
  });

  it("should set the state error when fetchAdsCandidates is called ", () => {
    expect(reducer(undefined, fetchAdsCandidatesError("Error"))).toEqual({
      candidates: [],
      adsCandidates: [],
      errorMessage: "Error",
      pagination: 0,
    });
  });

  it("should set adsCandidates", () => {
    expect(
      reducer(
        undefined,
        fetchAdsCandidatesSuccess(mockState.candidates.adsCandidates)
      )
    ).toEqual({
      candidates: [],
      adsCandidates: mockState.candidates.adsCandidates,
      errorMessage: "",
      pagination: 0,
    });
  });
});
