defmodule Wild.BookReadsTest do
  use Wild.DataCase

  alias Wild.BookReads

  describe "book_reads" do
    alias Wild.BookReads.BookRead

    import Wild.BookReadsFixtures

    @invalid_attrs %{progress: nil, rating: nil, thoughts: nil, read_start: nil, read_finish: nil}

    test "list_book_reads/0 returns all book_reads" do
      book_read = book_read_fixture()
      assert BookReads.list_book_reads() == [book_read]
    end

    test "get_book_read!/1 returns the book_read with given id" do
      book_read = book_read_fixture()
      assert BookReads.get_book_read!(book_read.id) == book_read
    end

    test "create_book_read/1 with valid data creates a book_read" do
      valid_attrs = %{progress: 42, rating: 42, thoughts: "some thoughts", read_start: ~U[2025-01-08 10:31:00Z], read_finish: ~U[2025-01-08 10:31:00Z]}

      assert {:ok, %BookRead{} = book_read} = BookReads.create_book_read(valid_attrs)
      assert book_read.progress == 42
      assert book_read.rating == 42
      assert book_read.thoughts == "some thoughts"
      assert book_read.read_start == ~U[2025-01-08 10:31:00Z]
      assert book_read.read_finish == ~U[2025-01-08 10:31:00Z]
    end

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

    test "update_book_read/2 with valid data updates the book_read" do
      book_read = book_read_fixture()
      update_attrs = %{progress: 43, rating: 43, thoughts: "some updated thoughts", read_start: ~U[2025-01-09 10:31:00Z], read_finish: ~U[2025-01-09 10:31:00Z]}

      assert {:ok, %BookRead{} = book_read} = BookReads.update_book_read(book_read, update_attrs)
      assert book_read.progress == 43
      assert book_read.rating == 43
      assert book_read.thoughts == "some updated thoughts"
      assert book_read.read_start == ~U[2025-01-09 10:31:00Z]
      assert book_read.read_finish == ~U[2025-01-09 10:31:00Z]
    end

    test "update_book_read/2 with invalid data returns error changeset" do
      book_read = book_read_fixture()
      assert {:error, %Ecto.Changeset{}} = BookReads.update_book_read(book_read, @invalid_attrs)
      assert book_read == BookReads.get_book_read!(book_read.id)
    end

    test "delete_book_read/1 deletes the book_read" do
      book_read = book_read_fixture()
      assert {:ok, %BookRead{}} = BookReads.delete_book_read(book_read)
      assert_raise Ecto.NoResultsError, fn -> BookReads.get_book_read!(book_read.id) end
    end

    test "change_book_read/1 returns a book_read changeset" do
      book_read = book_read_fixture()
      assert %Ecto.Changeset{} = BookReads.change_book_read(book_read)
    end
  end
end
