Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01efdc201d | ||
|
|
8a423b721d | ||
|
|
06dfee5b57 |
+3
-3
@@ -12,7 +12,7 @@ environment:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
image: elixir:1.14.0-slim
|
image: elixir:1.14.0
|
||||||
volumes:
|
volumes:
|
||||||
- name: mix
|
- name: mix
|
||||||
path: /root/.mix
|
path: /root/.mix
|
||||||
@@ -23,7 +23,7 @@ steps:
|
|||||||
- mix compile
|
- mix compile
|
||||||
|
|
||||||
- name: run migrations
|
- name: run migrations
|
||||||
image: elixir:1.14.0-slim
|
image: elixir:1.14.0
|
||||||
volumes:
|
volumes:
|
||||||
- name: mix
|
- name: mix
|
||||||
path: /root/.mix
|
path: /root/.mix
|
||||||
@@ -31,7 +31,7 @@ steps:
|
|||||||
- mix ecto.setup
|
- mix ecto.setup
|
||||||
|
|
||||||
- name: run tests
|
- name: run tests
|
||||||
image: elixir:1.14.0-slim
|
image: elixir:1.14.0
|
||||||
volumes:
|
volumes:
|
||||||
- name: mix
|
- name: mix
|
||||||
path: /root/.mix
|
path: /root/.mix
|
||||||
|
|||||||
+6
-1
@@ -43,7 +43,6 @@
|
|||||||
** 0.4.10 <2023-08-03 Thu>
|
** 0.4.10 <2023-08-03 Thu>
|
||||||
Add the CI/CD configuration.
|
Add the CI/CD configuration.
|
||||||
Add the test config.
|
Add the test config.
|
||||||
|
|
||||||
** 0.5.1 <2023-08-04 Fri>
|
** 0.5.1 <2023-08-04 Fri>
|
||||||
Add a generator for Link with random shorten.
|
Add a generator for Link with random shorten.
|
||||||
Update Links.create_one to use a function.
|
Update Links.create_one to use a function.
|
||||||
@@ -61,3 +60,9 @@
|
|||||||
Add the authentication for API sing in.
|
Add the authentication for API sing in.
|
||||||
** 0.8.2 <2023-08-10 Thu>
|
** 0.8.2 <2023-08-10 Thu>
|
||||||
Add the auth pipeline for the Link API path.
|
Add the auth pipeline for the Link API path.
|
||||||
|
** 0.8.3 <2023-08-11 Fri>
|
||||||
|
Add tests for user login.
|
||||||
|
** 0.8.4 <2023-08-12 Sat>
|
||||||
|
Add ErrorHandler for API Auth.
|
||||||
|
** 0.8.5 <2024-08-05 Mon>
|
||||||
|
Update the docker image for the CI/CD pipeline.
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
defmodule LinkShortenerWeb.Auth.ErrorHandler do
|
||||||
|
import Plug.Conn
|
||||||
|
|
||||||
|
def auth_error(conn, {type, _reason}, _opts) do
|
||||||
|
body = Poison.encode!(%{error: to_string(type)})
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/json")
|
||||||
|
|> send_resp(401, body)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,7 +6,7 @@ defmodule LinkShortenerWeb.Api.V1.UserControllerTest do
|
|||||||
alias LinkShortener.Accounts.User
|
alias LinkShortener.Accounts.User
|
||||||
|
|
||||||
@create_attrs %{
|
@create_attrs %{
|
||||||
email: "some_email@mail.com",
|
email: "user@mail.com",
|
||||||
password: "some password"
|
password: "some password"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,6 +15,11 @@ defmodule LinkShortenerWeb.Api.V1.UserControllerTest do
|
|||||||
password: "some updated password"
|
password: "some updated password"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@invalid_password_attrs %{
|
||||||
|
email: "user@mail.com",
|
||||||
|
password: ""
|
||||||
|
}
|
||||||
|
|
||||||
@invalid_attrs %{
|
@invalid_attrs %{
|
||||||
email: nil,
|
email: nil,
|
||||||
encrypted_password: nil
|
encrypted_password: nil
|
||||||
@@ -24,11 +29,11 @@ defmodule LinkShortenerWeb.Api.V1.UserControllerTest do
|
|||||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "create user" 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, Routes.v1_user_path(conn, :create), user: @create_attrs)
|
conn = post(conn, Routes.v1_user_path(conn, :create), user: @create_attrs)
|
||||||
assert %{
|
assert %{
|
||||||
"email" => "some_email@mail.com",
|
"email" => "user@mail.com",
|
||||||
"token" => token
|
"token" => token
|
||||||
} = json_response(conn, 201)
|
} = json_response(conn, 201)
|
||||||
end
|
end
|
||||||
@@ -39,8 +44,26 @@ defmodule LinkShortenerWeb.Api.V1.UserControllerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "user sign in" do
|
||||||
|
setup [:create_user]
|
||||||
|
|
||||||
|
test "renders user when data is valid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.v1_user_path(conn, :signin), @create_attrs)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"email" => email,
|
||||||
|
"token" => token,
|
||||||
|
} = json_response(conn, 201)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders errors when data is invalid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.v1_user_path(conn, :signin), @invalid_password_attrs)
|
||||||
|
assert "Unauthorized" == json_response(conn, 401)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp create_user(_) do
|
defp create_user(_) do
|
||||||
user = user_fixture()
|
user = user_fixture(@create_attrs)
|
||||||
%{user: user}
|
%{user: user}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ defmodule LinkShortener.AccountsFixtures do
|
|||||||
def user_token_fixture(attrs \\ %{}) do
|
def user_token_fixture(attrs \\ %{}) do
|
||||||
user_params = %{
|
user_params = %{
|
||||||
email: "user@mail.com",
|
email: "user@mail.com",
|
||||||
password: "hello world 12345"
|
password: "some password"
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, %User{} = user} = Accounts.register_user(user_params)
|
{:ok, %User{} = user} = Accounts.register_user(user_params)
|
||||||
|
|||||||
Reference in New Issue
Block a user