1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-10 09:02:50 +00:00
Files
classic-wow-forums/test/myapp/data/thread_test.exs

42 lines
1.2 KiB
Elixir

defmodule MyApp.Data.ThreadTest do
use MyAppWeb.ConnCase, async: true
import MyApp.Data.Thread
import MyApp.Data.TestHelpers
defp new_thread(userID, category_id \\ 1) do
%{
"title" => "test title",
"category_id" => category_id,
"content" => "test content",
"user_id" => userID,
}
end
test "insert: try to insert with no parameters" do
assert insert(%{}) == {:error,
[%{title: "can't be blank"}, %{category_id: "can't be blank"},
%{content: "can't be blank"}, %{user_id: "can't be blank"}]}
end
test "insert: insert as invalid user" do
assert insert(new_thread(9238748)) == {:error, [%{user_id: "does not exist"}]}
end
test "insert: insert as invalid category_id" do
{:ok, user} = new_user()
assert insert(new_thread(user.id, 2342342343)) == {:error, [%{category_id: "does not exist"}]}
end
test "new thread should be inserted" do
{:ok, user} = new_user()
{:ok, thread} = insert(new_thread(user.id))
assert thread.title == "test title"
assert thread.category_id == 1
assert thread.user_id == user.id
assert thread.content == "test content"
end
# TODO: update thread
end