defmodule Wish.WishlistTest do
  use Wish.DataCase

  alias Wish.Wishlist

  describe "items" do
    alias Wish.Wishlist.Item

    import Wish.WishlistFixtures

    @invalid_attrs %{description: nil, title: nil, url: nil, received: nil, desire: nil}

    test "list_items/0 returns all items" do
      item = item_fixture()
      assert Wishlist.list_items() == [item]
    end

    test "get_item!/1 returns the item with given id" do
      item = item_fixture()
      assert Wishlist.get_item!(item.id) == item
    end

    test "create_item/1 with valid data creates a item" do
      valid_attrs = %{description: "some description", title: "some title", url: "some url", received: true, desire: 42}

      assert {:ok, %Item{} = item} = Wishlist.create_item(valid_attrs)
      assert item.description == "some description"
      assert item.title == "some title"
      assert item.url == "some url"
      assert item.received == true
      assert item.desire == 42
    end

    test "create_item/1 with invalid data returns error changeset" do
      assert {:error, %Ecto.Changeset{}} = Wishlist.create_item(@invalid_attrs)
    end

    test "update_item/2 with valid data updates the item" do
      item = item_fixture()
      update_attrs = %{description: "some updated description", title: "some updated title", url: "some updated url", received: false, desire: 43}

      assert {:ok, %Item{} = item} = Wishlist.update_item(item, update_attrs)
      assert item.description == "some updated description"
      assert item.title == "some updated title"
      assert item.url == "some updated url"
      assert item.received == false
      assert item.desire == 43
    end

    test "update_item/2 with invalid data returns error changeset" do
      item = item_fixture()
      assert {:error, %Ecto.Changeset{}} = Wishlist.update_item(item, @invalid_attrs)
      assert item == Wishlist.get_item!(item.id)
    end

    test "delete_item/1 deletes the item" do
      item = item_fixture()
      assert {:ok, %Item{}} = Wishlist.delete_item(item)
      assert_raise Ecto.NoResultsError, fn -> Wishlist.get_item!(item.id) end
    end

    test "change_item/1 returns a item changeset" do
      item = item_fixture()
      assert %Ecto.Changeset{} = Wishlist.change_item(item)
    end
  end
end
