|
|
@ -31,7 +31,7 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
|
|
|
|
|
|
|
|
describe "create user with sign up" do
|
|
|
|
describe "create user with sign up" do
|
|
|
|
test "renders user when data is valid", %{conn: conn} do
|
|
|
|
test "renders user when data is valid", %{conn: conn} do
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_up", user: @create_attrs)
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-up", user: @create_attrs)
|
|
|
|
assert %{
|
|
|
|
assert %{
|
|
|
|
"email" => "user@mail.com",
|
|
|
|
"email" => "user@mail.com",
|
|
|
|
"token" => token
|
|
|
|
"token" => token
|
|
|
@ -39,7 +39,7 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_up", user: @invalid_attrs)
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-up", user: @invalid_attrs)
|
|
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -48,7 +48,7 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
setup [:create_user]
|
|
|
|
setup [:create_user]
|
|
|
|
|
|
|
|
|
|
|
|
test "renders user when data is valid", %{conn: conn} do
|
|
|
|
test "renders user when data is valid", %{conn: conn} do
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_in", @create_attrs)
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-in", @create_attrs)
|
|
|
|
|
|
|
|
|
|
|
|
assert %{
|
|
|
|
assert %{
|
|
|
|
"email" => email,
|
|
|
|
"email" => email,
|
|
|
@ -57,7 +57,7 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_in", @invalid_password_attrs)
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-in", @invalid_password_attrs)
|
|
|
|
assert %{
|
|
|
|
assert %{
|
|
|
|
"errors" => %{"detail" => "Unauthorized"}
|
|
|
|
"errors" => %{"detail" => "Unauthorized"}
|
|
|
|
} = json_response(conn, 401)
|
|
|
|
} = json_response(conn, 401)
|
|
|
@ -78,7 +78,7 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "renders the message and the token if successfully sign out", %{conn: conn, token: token} do
|
|
|
|
test "renders the message and the token if successfully sign out", %{conn: conn, token: token} do
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_out", %{})
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-out", %{})
|
|
|
|
|
|
|
|
|
|
|
|
assert %{
|
|
|
|
assert %{
|
|
|
|
"message" => "Successfully sign out",
|
|
|
|
"message" => "Successfully sign out",
|
|
|
@ -88,9 +88,9 @@ defmodule LinkShortenerWeb.Api.V1.AccountsControllerTest do
|
|
|
|
|
|
|
|
|
|
|
|
test "renders errors if the token is invalid after revoke", %{conn: conn, token: token} do
|
|
|
|
test "renders errors if the token is invalid after revoke", %{conn: conn, token: token} do
|
|
|
|
# revoking
|
|
|
|
# revoking
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_out", %{})
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-out", %{})
|
|
|
|
# second revoking
|
|
|
|
# second revoking
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign_out", %{})
|
|
|
|
conn = post(conn, ~p"/api/v1/users/sign-out", %{})
|
|
|
|
|
|
|
|
|
|
|
|
assert %{
|
|
|
|
assert %{
|
|
|
|
"error" => "invalid_token"
|
|
|
|
"error" => "invalid_token"
|
|
|
|