import reducer from "../../../store/reducers/candidate/candidateReducer";
import expect from "expect";
import {
  fetchCandidateSuccess,
  fetchCandidateError,
  createCandidateCommentSuccess,
  createCandidateCommentError,
  deleteCandidateError,
  deleteCandidateSuccess,
} from "../../../store/actions/candidate/candidateActions";
import { mockState } from "../../../mockState";

describe("candidate reducer", () => {
  it("should return the initial state", () => {
    expect(reducer(undefined, {})).toEqual({
      candidate: {},
      errorMessage: "",
    });
  });

  it("should set the state error when fetchCandidateError is called", () => {
    expect(reducer(undefined, fetchCandidateError("Error"))).toEqual({
      candidate: {},
      errorMessage: "Error",
    });
  });

  it("should set candidate when fetchCandidateSuccess is called", () => {
    expect(
      reducer(undefined, fetchCandidateSuccess(mockState.candidate.candidate))
    ).toEqual({
      candidate: mockState.candidate.candidate,
      errorMessage: "",
    });
  });

  it("should set the state error when createCandidateCommentError is called", () => {
    expect(reducer(undefined, createCandidateCommentError("Error"))).toEqual({
      candidate: {},
      errorMessage: "Error",
    });
  });

  // problem with comparing dateOfSending property of two states
  // it("should add new comment for canidate", () => {
  //   const obj = {
  //     myObj: { content: "sfsdfsd" },
  //     user: mockState.user.user,
  //   };
  //   expect(
  //     reducer(
  //       { candidate: mockState.candidate.candidate, errorMessage: "" },
  //       createCandidateCommentSuccess(obj)
  //     )
  //   ).toEqual({
  //     candidate: { ...mockState.candidate.candidate, obj },
  //     errorMessage: "",
  //   });
  // });

  it("should set the state error when deleteCandidateError is called", () => {
    expect(reducer(undefined, deleteCandidateError("Error"))).toEqual({
      candidate: {},
      errorMessage: "Error",
    });
  });

  it("should set candidate when deleteCandidateSuccess is called", () => {
    fetchCandidateSuccess(mockState.candidate.candidate);
    expect(reducer(undefined, deleteCandidateSuccess())).toEqual({
      candidate: {},
      errorMessage: "",
    });
  });
});
