import reducer from "../../../store/reducers/user/userDetailsReducer";
import expect from "expect";
import {
  stateUserDetailsSuccess,
  toggleSingleUser,
  userDetailsError,
} from "../../../store/actions/users/usersActions";

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

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

  it("should set the state user", () => {
    expect(
      reducer(undefined, stateUserDetailsSuccess({ name: "User" }))
    ).toEqual({
      user: { name: "User" },
      errorMessage: "",
    });
  });
});

it("should set the state user", () => {
  expect(
    reducer(
      {
        user: { name: "User", isEnabled: true },
        errorMessage: "",
      },
      toggleSingleUser()
    )
  ).toEqual({
    user: { name: "User", isEnabled: false },
    errorMessage: "",
  });
});
