defmodule Outlook.ArticlesTest do
  use Outlook.DataCase

  alias Outlook.Articles

  describe "articles" do
    alias Outlook.Articles.Article

    import Outlook.ArticlesFixtures

    @invalid_attrs %{content: nil, date: nil, language: nil, title: nil, url: nil}

    test "list_articles/0 returns all articles" do
      article = article_fixture()
      assert Articles.list_articles() == [article]
    end

    test "get_article!/1 returns the article with given id" do
      article = article_fixture()
      assert Articles.get_article!(article.id) == article
    end

    test "create_article/1 with valid data creates a article" do
      valid_attrs = %{content: "some content", date: ~U[2022-12-25 16:16:00Z], language: "some language", title: "some title", url: "some url"}

      assert {:ok, %Article{} = article} = Articles.create_article(valid_attrs)
      assert article.content == "some content"
      assert article.date == ~U[2022-12-25 16:16:00Z]
      assert article.language == "some language"
      assert article.title == "some title"
      assert article.url == "some url"
    end

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

    test "update_article/2 with valid data updates the article" do
      article = article_fixture()
      update_attrs = %{content: "some updated content", date: ~U[2022-12-26 16:16:00Z], language: "some updated language", title: "some updated title", url: "some updated url"}

      assert {:ok, %Article{} = article} = Articles.update_article(article, update_attrs)
      assert article.content == "some updated content"
      assert article.date == ~U[2022-12-26 16:16:00Z]
      assert article.language == "some updated language"
      assert article.title == "some updated title"
      assert article.url == "some updated url"
    end

    test "update_article/2 with invalid data returns error changeset" do
      article = article_fixture()
      assert {:error, %Ecto.Changeset{}} = Articles.update_article(article, @invalid_attrs)
      assert article == Articles.get_article!(article.id)
    end

    test "delete_article/1 deletes the article" do
      article = article_fixture()
      assert {:ok, %Article{}} = Articles.delete_article(article)
      assert_raise Ecto.NoResultsError, fn -> Articles.get_article!(article.id) end
    end

    test "change_article/1 returns a article changeset" do
      article = article_fixture()
      assert %Ecto.Changeset{} = Articles.change_article(article)
    end
  end
end
