mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
end point tests figured out
This commit is contained in:
51
test/myapp_web/controllers/thread_controller_test.exs
Normal file
51
test/myapp_web/controllers/thread_controller_test.exs
Normal file
@@ -0,0 +1,51 @@
|
||||
defmodule MyAppWeb.ThreadControllerTest do
|
||||
use MyAppWeb.ConnCase, async: true
|
||||
import MyAppWeb.ThreadController
|
||||
import MyApp.Data.TestHelpers
|
||||
|
||||
test "insert new thread should fail" do
|
||||
{:ok, user} = new_user()
|
||||
new_conn = build_conn()
|
||||
|> put_req_header("authorization", "Bearer " <> user.token)
|
||||
|
||||
conn = post(new_conn, "/api/thread")
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
|
||||
assert body["error"]["message"] == [
|
||||
%{"title" => "can't be blank"},
|
||||
%{"category_id" => "can't be blank"},
|
||||
%{"content" => "can't be blank"},
|
||||
]
|
||||
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t"})
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
assert body["error"]["message"] == [
|
||||
%{"category_id" => "can't be blank"},
|
||||
%{"content" => "can't be blank"},
|
||||
]
|
||||
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 1})
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
assert body["error"]["message"] == [%{"content" => "can't be blank"}]
|
||||
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 100000, "content" => "t"})
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
assert body["error"]["message"] == [%{"category_id" => "does not exist"}]
|
||||
end
|
||||
|
||||
test "insert new thread should succeed" do
|
||||
{:ok, user} = new_user()
|
||||
new_conn = build_conn()
|
||||
|> put_req_header("authorization", "Bearer " <> user.token)
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 1, "content" => "t"})
|
||||
body = conn |> response(200) |> Poison.decode!
|
||||
|
||||
data = body["data"]
|
||||
assert data["user_id"] == user.id
|
||||
assert data["category_id"] == 1
|
||||
assert data["title"] == "t"
|
||||
assert data["content"] == "t"
|
||||
end
|
||||
|
||||
# TODO: update thread / delete thread
|
||||
end
|
||||
Reference in New Issue
Block a user