import reducer from "../../../store/reducers/login/loginReducer";
import expect from "expect";
import {
  fetchUserError,
  resetLoginState,
  clearLoginErrors,
  generateTokenSuccess,
  generateTokenError,
} from "../../../store/actions/login/loginActions";

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

  it("should set the state error", () => {
    expect(reducer(undefined, fetchUserError("Error"))).toEqual({
      email: "",
      errorMessage: "Error",
    });
  });

  it("reset login state", () => {
    expect(reducer(undefined, resetLoginState())).toEqual({
      email: "",
      errorMessage: "",
    });
  });

  it("clear login errors", () => {
    fetchUserError("Error");
    expect(reducer(undefined, clearLoginErrors())).toEqual({
      email: "",
      errorMessage: "",
    });
  });

  it("generate token", () => {
    expect(reducer(undefined, generateTokenSuccess("some token"))).toEqual({
      email: "",
      errorMessage: "",
      token: "some token",
    });
  });

  it("generate token error", () => {
    expect(reducer(undefined, generateTokenError("some token error"))).toEqual({
      email: "",
      errorMessage: "some token error",
    });
  });
});
