import reducer from "../../../../store/reducers/ad/adsReducer";
import expect from "expect";
import {
  setAds,
  setAdsError,
  setFilteredAds,
  setFilteredAdsError,
} from "../../../../store/actions/ads/adsAction";
import { mockState } from "../../../../mockState";

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

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

  it("should set ads when setAds is called", () => {
    expect(reducer(undefined, setAds(mockState.ads.ads[0]))).toEqual({
      ads: mockState.ads.ads[0],
      errorMessage: "",
    });
  });

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

  it("should set ads when setFilteredAds is called", () => {
    expect(reducer(undefined, setFilteredAds(mockState.ads.ads[0]))).toEqual({
      ads: mockState.ads.ads[0],
      errorMessage: "",
    });
  });
});
