1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 17:42:48 +00:00

little bit of everything - it's been a long day

This commit is contained in:
2018-01-14 23:46:15 -06:00
parent d9d7f2d202
commit efbee265d3
25 changed files with 298 additions and 125 deletions

View File

@@ -13,18 +13,19 @@ defmodule MyApp.Data.ThreadTest do
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"}]}
{error, _} = catch_error(insert(%{}))
assert error == :badmatch
end
test "insert: insert as invalid user" do
assert insert(new_thread(9238748)) == {:error, [%{user_id: "does not exist"}]}
{:badmatch, {:error, data}} = catch_error(insert(new_thread(9238748)))
assert data.errors == [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"}]}
{error, _} = catch_error(insert(new_thread(user.id, 2342342343)))
assert error == :badmatch
end
test "new thread should be inserted" do
@@ -33,7 +34,6 @@ defmodule MyApp.Data.ThreadTest do
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

View File

@@ -41,6 +41,11 @@ defmodule MyApp.Data.UserTest do
battletag: "mgerb",
id: user.id,
permissions: "user",
character_avatar: nil,
character_class: nil,
character_guild: nil,
character_name: nil,
character_realm: nil,
}
end

View File

@@ -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

View File

@@ -7,29 +7,22 @@ defmodule MyAppWeb.ThreadControllerTest do
new_conn = build_conn()
|> put_req_header("authorization", "Bearer " <> user.token)
conn = post(new_conn, "/api/thread")
body = conn |> response(400) |> Poison.decode!
{:badmatch, {:error, data}} = catch_error(post(new_conn, "/api/thread"))
assert body["error"]["message"] == [
%{"title" => "can't be blank"},
%{"category_id" => "can't be blank"},
%{"content" => "can't be blank"},
assert data.errors == [
title: {"can't be blank", [validation: :required]},
category_id: {"can't be blank", [validation: :required]},
]
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"},
{:badmatch, {:error, data}} = catch_error(post(new_conn, "/api/thread", %{"title" => "t"}))
assert data.errors == [
category_id: {"can't be blank", [validation: :required]},
]
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"}]
{:badmatch, {:error, data}} = catch_error(post(new_conn, "/api/thread", %{"title" => "t", "category_id" => 100000}))
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"}]
assert data.errors == [category_id: {"does not exist", []}]
end
test "insert new thread should succeed" do
@@ -40,10 +33,10 @@ defmodule MyAppWeb.ThreadControllerTest do
body = conn |> response(200) |> Poison.decode!
data = body["data"]
# assert body == "test"
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