mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 17:42:48 +00:00
end point tests figured out
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# secret dev configurations - api keys go here
|
# secret dev configurations - api keys go here
|
||||||
|
use Mix.Config
|
||||||
|
|
||||||
config :myapp,
|
config :myapp,
|
||||||
bnet_client_id: "",
|
bnet_client_id: "",
|
||||||
|
|||||||
@@ -16,4 +16,9 @@ config :myapp, MyApp.Repo,
|
|||||||
password: "postgres",
|
password: "postgres",
|
||||||
database: "myapp_test",
|
database: "myapp_test",
|
||||||
hostname: "localhost",
|
hostname: "localhost",
|
||||||
|
template: "template0",
|
||||||
pool: Ecto.Adapters.SQL.Sandbox
|
pool: Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
||||||
|
config :myapp, MyApp.Guardian,
|
||||||
|
issuer: "myapp",
|
||||||
|
secret_key: "secret"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule MyApp.Guardian.Auth.Pipeline.User do
|
defmodule MyApp.Guardian.Auth.Pipeline.User do
|
||||||
use Guardian.Plug.Pipeline, otp_app: :MyApp,
|
use Guardian.Plug.Pipeline, otp_app: :myapp,
|
||||||
module: MyApp.Guardian,
|
module: MyApp.Guardian,
|
||||||
error_handler: MyApp.Auth.ErrorHandler
|
error_handler: MyApp.Auth.ErrorHandler
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ defmodule MyApp.Guardian.Auth.Pipeline.User do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule MyApp.Guardian.Auth.Pipeline.Mod do
|
defmodule MyApp.Guardian.Auth.Pipeline.Mod do
|
||||||
use Guardian.Plug.Pipeline, otp_app: :MyApp,
|
use Guardian.Plug.Pipeline, otp_app: :myapp,
|
||||||
module: MyApp.Guardian,
|
module: MyApp.Guardian,
|
||||||
error_handler: MyApp.Auth.ErrorHandler
|
error_handler: MyApp.Auth.ErrorHandler
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ defmodule MyApp.Guardian.Auth.Pipeline.Mod do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule MyApp.Guardian.Auth.Pipeline.Admin do
|
defmodule MyApp.Guardian.Auth.Pipeline.Admin do
|
||||||
use Guardian.Plug.Pipeline, otp_app: :MyApp,
|
use Guardian.Plug.Pipeline, otp_app: :myapp,
|
||||||
module: MyApp.Guardian,
|
module: MyApp.Guardian,
|
||||||
error_handler: MyApp.Auth.ErrorHandler
|
error_handler: MyApp.Auth.ErrorHandler
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ defmodule MyAppWeb.CategoryController do
|
|||||||
|
|
||||||
@spec get_collection(map, map) :: any
|
@spec get_collection(map, map) :: any
|
||||||
def get_collection(conn, _params) do
|
def get_collection(conn, _params) do
|
||||||
|
|
||||||
output = Data.Category.get_categories()
|
output = Data.Category.get_categories()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_status(200)
|
|> put_status(200)
|
||||||
|> Response.json(output)
|
|> Response.json(output)
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ defmodule MyApp.Data.UserTest do
|
|||||||
|
|
||||||
test "user is inserted into database" do
|
test "user is inserted into database" do
|
||||||
{:ok, user} = new_user()
|
{:ok, user} = new_user()
|
||||||
assert user == %{
|
assert user.access_token == "test_token"
|
||||||
access_token: "test_token",
|
assert user.battle_net_id == 1
|
||||||
battle_net_id: 1,
|
assert user.battletag == "mgerb42"
|
||||||
battletag: "mgerb42",
|
assert user.id == user.id
|
||||||
id: user.id,
|
assert user.permissions == "user"
|
||||||
permissions: "user",
|
assert user.token =~ ~r/(?).(?).(?)/
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "user's battletag is updated" do
|
test "user's battletag is updated" do
|
||||||
|
|||||||
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
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
defmodule MyApp.Data.TestHelpers do
|
defmodule MyApp.Data.TestHelpers do
|
||||||
import MyApp.Data.User
|
import MyApp.Data.User
|
||||||
|
alias MyApp.Guardian.Auth
|
||||||
|
|
||||||
@spec new_user() :: {:ok, map}
|
@spec new_user() :: {:ok, map}
|
||||||
def new_user() do
|
def new_user() do
|
||||||
upsert_user(%{"battle_net_id" => 1, "battletag" => "mgerb42", "access_token" => "test_token"})
|
upsert_user(%{"battle_net_id" => 1, "battletag" => "mgerb42", "access_token" => "test_token"})
|
||||||
|
|> Auth.Token.add_token_and_map_claims
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec atom_key_to_string(map) :: map
|
@spec atom_key_to_string(map) :: map
|
||||||
|
|||||||
Reference in New Issue
Block a user