defmodule Outlook.AuthorsTest do
  use Outlook.DataCase

  alias Outlook.Authors

  describe "authors" do
    alias Outlook.Authors.Author

    import Outlook.AuthorsFixtures

    @invalid_attrs %{description: nil, homepage_name: nil, homepage_url: nil, name: nil}

    test "list_authors/0 returns all authors" do
      author = author_fixture()
      assert Authors.list_authors() == [author]
    end

    test "get_author!/1 returns the author with given id" do
      author = author_fixture()
      assert Authors.get_author!(author.id) == author
    end

    test "create_author/1 with valid data creates a author" do
      valid_attrs = %{description: "some description", homepage_name: "some homepage_name", homepage_url: "some homepage_url", name: "some name"}

      assert {:ok, %Author{} = author} = Authors.create_author(valid_attrs)
      assert author.description == "some description"
      assert author.homepage_name == "some homepage_name"
      assert author.homepage_url == "some homepage_url"
      assert author.name == "some name"
    end

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

    test "update_author/2 with valid data updates the author" do
      author = author_fixture()
      update_attrs = %{description: "some updated description", homepage_name: "some updated homepage_name", homepage_url: "some updated homepage_url", name: "some updated name"}

      assert {:ok, %Author{} = author} = Authors.update_author(author, update_attrs)
      assert author.description == "some updated description"
      assert author.homepage_name == "some updated homepage_name"
      assert author.homepage_url == "some updated homepage_url"
      assert author.name == "some updated name"
    end

    test "update_author/2 with invalid data returns error changeset" do
      author = author_fixture()
      assert {:error, %Ecto.Changeset{}} = Authors.update_author(author, @invalid_attrs)
      assert author == Authors.get_author!(author.id)
    end

    test "delete_author/1 deletes the author" do
      author = author_fixture()
      assert {:ok, %Author{}} = Authors.delete_author(author)
      assert_raise Ecto.NoResultsError, fn -> Authors.get_author!(author.id) end
    end

    test "change_author/1 returns a author changeset" do
      author = author_fixture()
      assert %Ecto.Changeset{} = Authors.change_author(author)
    end
  end
end
