@@ -540,4 +540,66 @@ defmodule Eventos.EventsTest do
|
||||
assert %Ecto.Changeset{} = Events.change_track(track)
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments" do
|
||||
alias Eventos.Events.Comment
|
||||
|
||||
@valid_attrs %{text: "some text", url: "some url"}
|
||||
@update_attrs %{text: "some updated text", url: "some updated url"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
||||
def comment_fixture(attrs \\ %{}) do
|
||||
{:ok, comment} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Events.create_comment()
|
||||
|
||||
comment
|
||||
end
|
||||
|
||||
test "list_comments/0 returns all comments" do
|
||||
comment = comment_fixture()
|
||||
assert Events.list_comments() == [comment]
|
||||
end
|
||||
|
||||
test "get_comment!/1 returns the comment with given id" do
|
||||
comment = comment_fixture()
|
||||
assert Events.get_comment!(comment.id) == comment
|
||||
end
|
||||
|
||||
test "create_comment/1 with valid data creates a comment" do
|
||||
assert {:ok, %Comment{} = comment} = Events.create_comment(@valid_attrs)
|
||||
assert comment.text == "some text"
|
||||
assert comment.url == "some url"
|
||||
end
|
||||
|
||||
test "create_comment/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Events.create_comment(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_comment/2 with valid data updates the comment" do
|
||||
comment = comment_fixture()
|
||||
assert {:ok, comment} = Events.update_comment(comment, @update_attrs)
|
||||
assert %Comment{} = comment
|
||||
assert comment.text == "some updated text"
|
||||
assert comment.url == "some updated url"
|
||||
end
|
||||
|
||||
test "update_comment/2 with invalid data returns error changeset" do
|
||||
comment = comment_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Events.update_comment(comment, @invalid_attrs)
|
||||
assert comment == Events.get_comment!(comment.id)
|
||||
end
|
||||
|
||||
test "delete_comment/1 deletes the comment" do
|
||||
comment = comment_fixture()
|
||||
assert {:ok, %Comment{}} = Events.delete_comment(comment)
|
||||
assert_raise Ecto.NoResultsError, fn -> Events.get_comment!(comment.id) end
|
||||
end
|
||||
|
||||
test "change_comment/1 returns a comment changeset" do
|
||||
comment = comment_fixture()
|
||||
assert %Ecto.Changeset{} = Events.change_comment(comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user