import reducer from "../../../../store/reducers/pattern/scheduleAppointmentReducer";
import expect from "expect";
import {
  scheduleAppointment,
  scheduleAppointmentError,
  clearNotSentEmailsArray,
} from "../../../../store/actions/scheduleAppointment/scheduleAppointmentActions";

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

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

  it("should set the state success when scheduleAppointment with an empty array as argument is called", () => {
    expect(
      reducer(undefined, scheduleAppointment({ notSentEmails: [] }))
    ).toEqual({
      notSentEmails: [],
      errorMessage: "",
    });
  });

  it("should set the state success when scheduleAppointment with an null as argument is called", () => {
    expect(reducer(undefined, scheduleAppointment(null))).toEqual({
      notSentEmails: null,
      errorMessage: "",
    });
  });

  it("should set the state success when clearNotSentEmailsArray is called", () => {
    expect(
      reducer(
        { notSentEmails: [], errorMessage: "" },
        clearNotSentEmailsArray()
      )
    ).toEqual({
      notSentEmails: null,
      errorMessage: "",
    });
  });
});
