After "mix phx.gen.json Accounts User users --no-context --no-schema --no-scope email:string"
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
defmodule BeetRoundServerWeb.UserControllerTest do
|
||||
use BeetRoundServerWeb.ConnCase
|
||||
|
||||
import BeetRoundServer.AccountsFixtures
|
||||
alias BeetRoundServer.Accounts.User
|
||||
|
||||
@create_attrs %{
|
||||
email: "some email"
|
||||
}
|
||||
@update_attrs %{
|
||||
email: "some updated email"
|
||||
}
|
||||
@invalid_attrs %{email: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all users", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/users")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create user" do
|
||||
test "renders user when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/users", user: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/users/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"email" => "some email"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/users", user: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "renders user when data is valid", %{conn: conn, user: %User{id: id} = user} do
|
||||
conn = put(conn, ~p"/api/users/#{user}", user: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/users/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"email" => "some updated email"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = put(conn, ~p"/api/users/#{user}", user: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "deletes chosen user", %{conn: conn, user: user} do
|
||||
conn = delete(conn, ~p"/api/users/#{user}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/users/#{user}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_user(_) do
|
||||
user = user_fixture()
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user