1
0
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:
2018-01-06 12:25:50 -06:00
parent 006a7e1fc2
commit 959c44b8f8
7 changed files with 68 additions and 12 deletions

View 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