This commit is contained in:
@@ -32,8 +32,8 @@ defmodule LinkShortenerWeb.Router do
|
|||||||
pipe_through :api
|
pipe_through :api
|
||||||
|
|
||||||
scope "/v1", Api.V1, as: :v1 do
|
scope "/v1", Api.V1, as: :v1 do
|
||||||
post "/users/sign_up", AccountsController, :sign_up
|
post "/users/sign-up", AccountsController, :sign_up
|
||||||
post "/users/sign_in", AccountsController, :sign_in
|
post "/users/sign-in", AccountsController, :sign_in
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ defmodule LinkShortenerWeb.Router do
|
|||||||
pipe_through [:api, :auth]
|
pipe_through [:api, :auth]
|
||||||
|
|
||||||
scope "/v1", Api.V1, as: :v1 do
|
scope "/v1", Api.V1, as: :v1 do
|
||||||
post "/users/sign_out", AccountsController, :sign_out
|
post "/users/sign-out", AccountsController, :sign_out
|
||||||
|
|
||||||
resources "/links", LinkController
|
resources "/links", LinkController
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user