1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-12 10:02:49 +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

@@ -5,13 +5,12 @@ defmodule MyApp.Data.UserTest do
test "user is inserted into database" do
{:ok, user} = new_user()
assert user == %{
access_token: "test_token",
battle_net_id: 1,
battletag: "mgerb42",
id: user.id,
permissions: "user",
}
assert user.access_token == "test_token"
assert user.battle_net_id == 1
assert user.battletag == "mgerb42"
assert user.id == user.id
assert user.permissions == "user"
assert user.token =~ ~r/(?).(?).(?)/
end
test "user's battletag is updated" do

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

View File

@@ -1,9 +1,11 @@
defmodule MyApp.Data.TestHelpers do
import MyApp.Data.User
alias MyApp.Guardian.Auth
@spec new_user() :: {:ok, map}
def new_user() do
upsert_user(%{"battle_net_id" => 1, "battletag" => "mgerb42", "access_token" => "test_token"})
|> Auth.Token.add_token_and_map_claims
end
@spec atom_key_to_string(map) :: map