mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
little bit of everything - it's been a long day
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user