mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-10 09:02:50 +00:00
little bit of everything - it's been a long day
This commit is contained in:
@@ -7,21 +7,14 @@ defmodule MyAppWeb.ReplyControllerTest do
|
||||
new_conn = build_conn()
|
||||
|> put_req_header("authorization", "Bearer " <> user.token)
|
||||
|
||||
conn = post(new_conn, "/api/reply")
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
{:badmatch, {:error, data}} = conn = catch_error(post(new_conn, "/api/reply"))
|
||||
assert data == [%{thread_id: "can't be blank"}, %{content: "can't be blank"}]
|
||||
|
||||
assert body["error"]["message"] == [
|
||||
%{"thread_id" => "can't be blank"},
|
||||
%{"content" => "can't be blank"},
|
||||
]
|
||||
{:badmatch, {:error, data}} = conn = catch_error(post(new_conn, "/api/reply", %{"content" => "t"}))
|
||||
assert data == [%{thread_id: "can't be blank"}]
|
||||
|
||||
conn = post(new_conn, "/api/reply", %{"content" => "t"})
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
assert body["error"]["message"] == [%{"thread_id" => "can't be blank"}]
|
||||
|
||||
conn = post(new_conn, "/api/reply", %{"content" => "t", "thread_id" => 1})
|
||||
body = conn |> response(400) |> Poison.decode!
|
||||
assert body["error"]["message"] == [%{"thread_id" => "does not exist"}]
|
||||
{:badmatch, {:error, data}} = conn = catch_error(post(new_conn, "/api/reply", %{"content" => "t", "thread_id" => 1}))
|
||||
assert data == [%{thread_id: "does not exist"}]
|
||||
end
|
||||
|
||||
test "insert new reply should succeed" do
|
||||
@@ -30,7 +23,7 @@ defmodule MyAppWeb.ReplyControllerTest do
|
||||
|> put_req_header("authorization", "Bearer " <> user.token)
|
||||
|
||||
# insert new thread first
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 1, "content" => "t"})
|
||||
conn = post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 1})
|
||||
body = conn |> response(200) |> Poison.decode!
|
||||
|
||||
conn = post(new_conn, "/api/reply", %{"content" => "c", "thread_id" => body["data"]["id"]})
|
||||
@@ -41,15 +34,13 @@ defmodule MyAppWeb.ReplyControllerTest do
|
||||
|
||||
assert data["content"] == "c"
|
||||
assert data["edited"] == false
|
||||
assert data["quote"] == false
|
||||
assert data["quote_id"] == nil
|
||||
|
||||
# make sure thread reply count and last reply id are updated
|
||||
conn = get(new_conn, "/api/thread?category_id=1")
|
||||
body = conn |> response(200) |> Poison.decode!
|
||||
# conn = get(new_conn, "/api/thread?category_id=1")
|
||||
# body = conn |> response(200) |> Poison.decode!
|
||||
|
||||
data = Enum.at(body["data"], 0)
|
||||
assert data["reply_count"] == 1
|
||||
assert data["last_reply_id"] == user_id
|
||||
# assert Enum.at(body["data"], 0) == "ok"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user