Compare commits

...
14 Commits
Author SHA1 Message Date
KKlochko 1cc1a83e34 Add tests for UserController, Accounts, Generators.
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build was killed
2023-08-07 20:51:54 +03:00
KKlochko 93631f195f Add the API Authentication.
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build was killed
2023-08-06 21:35:42 +03:00
KKlochko cde8970b46 Add User model.
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build was killed
2023-08-05 21:15:40 +03:00
KKlochko 33fae4ece2 Add dependencies for API Authentication.
continuous-integration/drone/tag Build was killed
2023-08-05 21:13:59 +03:00
KKlochko e89a8ea5db Update Links.create_one to use a function.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed
2023-08-04 21:10:36 +03:00
KKlochko feebbe4f8a Add a generator for Link with random shorten. 2023-08-04 21:10:08 +03:00
KKlochko ecdce9e407 Add the test config.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed
2023-08-03 14:36:07 +03:00
KKlochko e3b202825b Add the CI/CD configuration. 2023-08-03 14:35:14 +03:00
KKlochko ebac60a2b0 Add tests for the Links module. 2023-08-02 21:26:56 +03:00
KKlochko c6236c0ef1 Refactor the Links module. 2023-08-02 21:20:01 +03:00
KKlochko dd0e79c400 Add tests for the API. 2023-08-01 18:09:01 +03:00
KKlochko e6e344745b Add the API to update the Link model. 2023-08-01 18:02:14 +03:00
KKlochko 62e855e1b6 Fix the route path in LinkController.create/2. 2023-08-01 17:59:34 +03:00
KKlochko 8f6ec31366 Fix Links.update_one/2. 2023-08-01 17:58:42 +03:00
31 changed files with 928 additions and 31 deletions
+52
View File
@@ -0,0 +1,52 @@
kind: pipeline
type: docker
name: default
environment:
DATABASE_NAME: link_shortener_dev
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: postgres
DATABASE_PORT: 5432
SECRET_KEY_BASE: TestSecretKeycRZ1H45gfdAsdf8DIb45df4664mRCruzwVEF68wosddfg324ost
steps:
- name: install dependencies
image: elixir:1.14.0-slim
volumes:
- name: mix
path: /root/.mix
commands:
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix compile
- name: run migrations
image: elixir:1.14.0-slim
volumes:
- name: mix
path: /root/.mix
commands:
- mix ecto.setup
- name: run tests
image: elixir:1.14.0-slim
volumes:
- name: mix
path: /root/.mix
commands:
- mix test
volumes:
- name: mix
temp: {}
services:
- name: postgres
image: postgres:15-alpine
environment:
POSTGRES_DB: link_shortener_dev
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
+26
View File
@@ -28,4 +28,30 @@
Move Links to the Links context. Move Links to the Links context.
Refactor to split the Links to a Link model and a Links logic. Refactor to split the Links to a Link model and a Links logic.
Update the controller and the view for updated Link model. Update the controller and the view for updated Link model.
** 0.4.4 <2023-08-01 Tue>
Fix Links.update_one/2.
** 0.4.5 <2023-08-01 Tue>
Fix the route path in LinkController.create/2.
** 0.4.6 <2023-08-01 Tue>
Add the API to update the Link model.
** 0.4.7 <2023-08-01 Tue>
Add tests for the API.
** 0.4.8 <2023-08-02 Wed>
Refactor the Links module.
** 0.4.9 <2023-08-02 Wed>
Add tests for the Links module.
** 0.4.10 <2023-08-03 Thu>
Add the CI/CD configuration.
Add the test config.
** 0.5.1 <2023-08-04 Fri>
Add a generator for Link with random shorten.
Update Links.create_one to use a function.
** 0.5.2 <2023-08-05 Sat>
Add dependencies for API Authentication.
** 0.6.0 <2023-08-05 Sat>
Add User model.
** 0.7.0 <2023-08-05 Sat>
Add the API Authentication.
** 0.7.1 <2023-08-06 Sun>
Add tests for UserController, Accounts, Generators.
+4
View File
@@ -47,6 +47,10 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix # Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason config :phoenix, :json_library, Jason
config :link_shortener, LinkShortenerWeb.Auth.Guardian,
issuer: "link_shortener",
secret_key: System.get_env("SECRET_KEY_BASE")
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs" import_config "#{config_env()}.exs"
+30
View File
@@ -0,0 +1,30 @@
import Config
# Configure your database
#
# The MIX_TEST_PARTITION environment variable can be used
# to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information.
config :link_shortener, LinkShortener.Repo,
username: System.get_env("DATABASE_USERNAME"),
password: System.get_env("DATABASE_PASSWORD"),
hostname: System.get_env("DATABASE_HOST"),
database: "link_shortener_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 10
# We don't run a server during test. If one is required,
# you can enable the server option below.
config :link_shortener, LinkShortenerWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4002],
secret_key_base: System.get_env("SECRET_KEY_BASE"),
server: false
# In test we don't send emails.
config :link_shortener, LinkShortener.Mailer, adapter: Swoosh.Adapters.Test
# Print only warnings and errors during test
config :logger, level: :warn
# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime
+104
View File
@@ -0,0 +1,104 @@
defmodule LinkShortener.Accounts do
@moduledoc """
The Accounts context.
"""
import Ecto.Query, warn: false
alias LinkShortener.Repo
alias LinkShortener.Accounts.User
@doc """
Returns the list of users.
## Examples
iex> list_users()
[%User{}, ...]
"""
def list_users do
Repo.all(User)
end
@doc """
Gets a single user.
Raises `Ecto.NoResultsError` if the User does not exist.
## Examples
iex> get_user!(123)
%User{}
iex> get_user!(456)
** (Ecto.NoResultsError)
"""
def get_user!(id), do: Repo.get!(User, id)
@doc """
Creates a user.
## Examples
iex> create_user(%{field: value})
{:ok, %User{}}
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_user(attrs \\ %{}) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a user.
## Examples
iex> update_user(user, %{field: new_value})
{:ok, %User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_user(%User{} = user, attrs) do
user
|> User.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a user.
## Examples
iex> delete_user(user)
{:ok, %User{}}
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
"""
def delete_user(%User{} = user) do
Repo.delete(user)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.
## Examples
iex> change_user(user)
%Ecto.Changeset{data: %User{}}
"""
def change_user(%User{} = user, attrs \\ %{}) do
User.changeset(user, attrs)
end
end
+31
View File
@@ -0,0 +1,31 @@
defmodule LinkShortener.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :email, :string
field :encrypted_password, :string
field :password, :string, virtual: true
timestamps()
end
@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:email, :password])
|> validate_required([:email, :password])
|> unique_constraint(:email)
|> put_hashed_password()
end
defp put_hashed_password(changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{password: password}}
->
put_change(changeset, :encrypted_password, Comeonin.Bcrypt.hashpwsalt(password))
_ ->
changeset
end
end
end
@@ -0,0 +1,14 @@
defmodule LinkShortener.Generators.LinkWithRandomShorten do
@moduledoc """
This module provides a generator for Link.
"""
alias LinkShortener.Generators.SafeString
@doc """
Generate a Link with random shorten with the length.
"""
def generate_one(attrs, length \\ 10, generator \\ &SafeString.generate/1) do
Map.put(attrs, :shorten, generator.(length))
end
end
+24 -25
View File
@@ -1,16 +1,16 @@
defmodule LinkShortener.Links.Links do defmodule LinkShortener.Links do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
alias LinkShortener.Repo alias LinkShortener.Repo
alias LinkShortener.Links.Link alias LinkShortener.Links.Link
alias LinkShortener.Generators.SafeString alias LinkShortener.Generators.LinkWithRandomShorten, as: LinkGenerator
def new_one(), do: Link.changeset(%Link{}) def new_one(), do: Link.changeset(%Link{}, %{})
def create_one(attrs, length \\ 10, generator \\ SafeString) do def create_one(attrs, length \\ 10, generator \\ &LinkGenerator.generate_one/2) do
shorten = generator.generate(length) generator.(attrs, length)
insert_one(Map.put(attrs, :shorten, shorten)) |> insert_one()
end end
def insert_one(attrs) do def insert_one(attrs) do
@@ -19,25 +19,10 @@ defmodule LinkShortener.Links.Links do
|> Repo.insert() |> Repo.insert()
end end
def edit_one(id) do def get_one!(id) do
get_one(id) Repo.get!(Link, id)
|> Link.changeset()
end end
def update_one(%Link{} = link, changes) do
Link
|> Link.changeset(changes)
|> Repo.update()
end
def insert_one(attrs) do
%Link{}
|> Link.changeset(attrs)
|> Repo.insert()
end
def delete_one(%Link{} = link), do: Repo.delete(link)
def get_one_by(attrs) do def get_one_by(attrs) do
Repo.get_by(Link, attrs) Repo.get_by(Link, attrs)
end end
@@ -46,12 +31,26 @@ defmodule LinkShortener.Links.Links do
get_one_by(%{shorten: shorten}) get_one_by(%{shorten: shorten})
end end
def get_one(id) do def get_all() do
Repo.get!(Link, id) from(Link)
|> Repo.all()
end end
def get_all(opts) do def get_all(opts) do
from(Link) from(Link)
|> Repo.all() |> Repo.all()
end end
def edit_one(%Link{} = link) do
link
|> Link.changeset(%{})
end
def update_one(%Link{} = link, changes) do
link
|> Link.changeset(changes)
|> Repo.update()
end
def delete_one(%Link{} = link), do: Repo.delete(link)
end end
+16
View File
@@ -0,0 +1,16 @@
defmodule LinkShortenerWeb.Auth.Guardian do
use Guardian, otp_app: :link_shortener
alias LinkShortener.Accounts
def subject_for_token(user, _claims) do
sub = to_string(user.id)
{:ok, sub}
end
def resource_from_claims(claims) do
id = claims["sub"]
resource = Accounts.get_user!(id)
{:ok, resource}
end
end
@@ -1,13 +1,13 @@
defmodule LinkShortenerWeb.Api.V1.LinkController do defmodule LinkShortenerWeb.Api.V1.LinkController do
use LinkShortenerWeb, :controller use LinkShortenerWeb, :controller
alias LinkShortener.Links.Links alias LinkShortener.Links
alias LinkShortener.Links.Link alias LinkShortener.Links.Link
action_fallback LinkShortenerWeb.FallbackController action_fallback LinkShortenerWeb.FallbackController
def index(conn, _params) do def index(conn, _params) do
links = Links.get_all({}) links = Links.get_all()
render(conn, "index.json", links: links) render(conn, "index.json", links: links)
end end
@@ -15,19 +15,26 @@ defmodule LinkShortenerWeb.Api.V1.LinkController do
with {:ok, %Link{} = link} <- Links.insert_one(link_params) do with {:ok, %Link{} = link} <- Links.insert_one(link_params) do
conn conn
|> put_status(:created) |> put_status(:created)
|> put_resp_header("location", Routes.link_path(conn, :show, link)) |> put_resp_header("location", Routes.v1_link_path(conn, :show, link))
|> render("show.json", link: link) |> render("show.json", link: link)
end end
end end
def show(conn, %{"id" => id}) do def show(conn, %{"id" => id}) do
link = Links.get_one(id) link = Links.get_one!(id)
render(conn, "show.json", link: link) render(conn, "show.json", link: link)
end end
def update(conn, %{"id" => id, "link" => link_params}) do
link = Links.get_one!(id)
with {:ok, %Link{} = link} <- Links.update_one(link, link_params) do
render(conn, "show.json", link: link)
end
end end
def delete(conn, %{"id" => id}) do def delete(conn, %{"id" => id}) do
link = Links.get_one(id) link = Links.get_one!(id)
with {:ok, %Link{}} <- Links.delete_one(link) do with {:ok, %Link{}} <- Links.delete_one(link) do
send_resp(conn, :no_content, "") send_resp(conn, :no_content, "")
@@ -0,0 +1,26 @@
defmodule LinkShortenerWeb.Api.V1.UserController do
use LinkShortenerWeb, :controller
alias LinkShortener.Accounts
alias LinkShortener.Accounts.User
alias LinkShortenerWeb.Auth.Guardian
action_fallback LinkShortenerWeb.FallbackController
def create(conn, %{"user" => user_params}) do
with {:ok, %User{} = user} <- Accounts.create_user(user_params),
{:ok, token, _claims} <- Guardian.encode_and_sign(user) do
conn
|> put_status(:created)
|> render("user.json", %{user: user, token: token})
end
end
def signin(conn, %{"email" => email, "password" => password}) do
with {:ok, user, token} <- Guardian.authenticate(email, password) do
conn
|> put_status(:created)
|> render("user.json", %{user: user, token: token})
end
end
end
+2
View File
@@ -27,6 +27,8 @@ defmodule LinkShortenerWeb.Router do
scope "/v1", Api.V1, as: :v1 do scope "/v1", Api.V1, as: :v1 do
resources "/links", LinkController resources "/links", LinkController
post "/users/signup", UserController, :create
post "/users/signin", UserController, :signin
end end
end end
@@ -0,0 +1,12 @@
defmodule LinkShortenerWeb.Api.V1.UserView do
use LinkShortenerWeb, :view
alias LinkShortenerWeb.Api.V1.UserView
def render("user.json", %{user: user, token: token}) do
%{
email: user.email,
token: token
}
end
end
+4 -1
View File
@@ -48,7 +48,10 @@ defmodule LinkShortener.MixProject do
{:telemetry_poller, "~> 1.0"}, {:telemetry_poller, "~> 1.0"},
{:gettext, "~> 0.18"}, {:gettext, "~> 0.18"},
{:jason, "~> 1.2"}, {:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"} {:plug_cowboy, "~> 2.5"},
{:guardian, "~> 1.0"},
{:comeonin, "~> 4.0"},
{:bcrypt_elixir, "~> 1.0"}
] ]
end end
+5
View File
@@ -1,5 +1,7 @@
%{ %{
"bcrypt_elixir": {:hex, :bcrypt_elixir, "1.1.1", "6b5560e47a02196ce5f0ab3f1d8265db79a23868c137e973b27afef928ed8006", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "10f658be786bd2daaadcd45cc5b598da01d5bbc313da4d0e3efb2d6a511d896d"},
"castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"}, "castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"},
"comeonin": {:hex, :comeonin, "4.1.2", "3eb5620fd8e35508991664b4c2b04dd41e52f1620b36957be837c1d7784b7592", [:mix], [{:argon2_elixir, "~> 1.2", [hex: :argon2_elixir, repo: "hexpm", optional: true]}, {:bcrypt_elixir, "~> 0.12.1 or ~> 1.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: true]}, {:pbkdf2_elixir, "~> 0.12", [hex: :pbkdf2_elixir, repo: "hexpm", optional: true]}], "hexpm", "d8700a0ca4dbb616c22c9b3f6dd539d88deaafec3efe66869d6370c9a559b3e9"},
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
@@ -7,12 +9,15 @@
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"ecto": {:hex, :ecto, "3.10.2", "6b887160281a61aa16843e47735b8a266caa437f80588c3ab80a8a960e6abe37", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6a895778f0d7648a4b34b486af59a1c8009041fbdf2b17f1ac215eb829c60235"}, "ecto": {:hex, :ecto, "3.10.2", "6b887160281a61aa16843e47735b8a266caa437f80588c3ab80a8a960e6abe37", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6a895778f0d7648a4b34b486af59a1c8009041fbdf2b17f1ac215eb829c60235"},
"ecto_sql": {:hex, :ecto_sql, "3.10.1", "6ea6b3036a0b0ca94c2a02613fd9f742614b5cfe494c41af2e6571bb034dd94c", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6a25bdbbd695f12c8171eaff0851fa4c8e72eec1e98c7364402dda9ce11c56b"}, "ecto_sql": {:hex, :ecto_sql, "3.10.1", "6ea6b3036a0b0ca94c2a02613fd9f742614b5cfe494c41af2e6571bb034dd94c", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6a25bdbbd695f12c8171eaff0851fa4c8e72eec1e98c7364402dda9ce11c56b"},
"elixir_make": {:hex, :elixir_make, "0.7.7", "7128c60c2476019ed978210c245badf08b03dbec4f24d05790ef791da11aa17c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bc19fff950fad52bbe5f211b12db9ec82c6b34a9647da0c2224b8b8464c7e6c"},
"esbuild": {:hex, :esbuild, "0.7.1", "fa0947e8c3c3c2f86c9bf7e791a0a385007ccd42b86885e8e893bdb6631f5169", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "66661cdf70b1378ee4dc16573fcee67750b59761b2605a0207c267ab9d19f13c"}, "esbuild": {:hex, :esbuild, "0.7.1", "fa0947e8c3c3c2f86c9bf7e791a0a385007ccd42b86885e8e893bdb6631f5169", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "66661cdf70b1378ee4dc16573fcee67750b59761b2605a0207c267ab9d19f13c"},
"expo": {:hex, :expo, "0.4.1", "1c61d18a5df197dfda38861673d392e642649a9cef7694d2f97a587b2cfb319b", [:mix], [], "hexpm", "2ff7ba7a798c8c543c12550fa0e2cbc81b95d4974c65855d8d15ba7b37a1ce47"}, "expo": {:hex, :expo, "0.4.1", "1c61d18a5df197dfda38861673d392e642649a9cef7694d2f97a587b2cfb319b", [:mix], [], "hexpm", "2ff7ba7a798c8c543c12550fa0e2cbc81b95d4974c65855d8d15ba7b37a1ce47"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"}, "floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"},
"gettext": {:hex, :gettext, "0.22.3", "c8273e78db4a0bb6fba7e9f0fd881112f349a3117f7f7c598fa18c66c888e524", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "935f23447713954a6866f1bb28c3a878c4c011e802bcd68a726f5e558e4b64bd"}, "gettext": {:hex, :gettext, "0.22.3", "c8273e78db4a0bb6fba7e9f0fd881112f349a3117f7f7c598fa18c66c888e524", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "935f23447713954a6866f1bb28c3a878c4c011e802bcd68a726f5e558e4b64bd"},
"guardian": {:hex, :guardian, "1.2.1", "bdc8dd3dbf0fb7216cb6f91c11831faa1a64d39cdaed9a611e37f2413e584983", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "723fc404edfb7bd5cba4cd83329b352037f102aa97468f44e58ac7f47c136a98"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, "jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"jose": {:hex, :jose, "1.11.6", "613fda82552128aa6fb804682e3a616f4bc15565a048dabd05b1ebd5827ed965", [:mix, :rebar3], [], "hexpm", "6275cb75504f9c1e60eeacb771adfeee4905a9e182103aa59b53fed651ff9738"},
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.2", "b21bd01fdeffcfe2fab49e4942aa938b6d3e89e93a480d4aee58085560a0bc0d", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "70242edd4601d50b69273b057ecf7b684644c19ee750989fd555625ae4ce8f5d"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.2", "b21bd01fdeffcfe2fab49e4942aa938b6d3e89e93a480d4aee58085560a0bc0d", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "70242edd4601d50b69273b057ecf7b684644c19ee750989fd555625ae4ce8f5d"},
@@ -0,0 +1,14 @@
defmodule LinkShortener.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users) do
add :email, :string
add :encrypted_password, :string
timestamps()
end
create unique_index(:users, [:email])
end
end
@@ -0,0 +1,61 @@
defmodule LinkShortener.AccountsTest do
use LinkShortener.DataCase
alias LinkShortener.Accounts
describe "users" do
alias LinkShortener.Accounts.User
import LinkShortener.AccountsFixtures
@invalid_attrs %{email: nil, password: nil}
test "list_users/0 returns all users" do
user = user_fixture()
assert Accounts.list_users() == [user]
end
test "get_user!/1 returns the user with given id" do
user = user_fixture()
assert Accounts.get_user!(user.id) == user
end
test "create_user/1 with valid data creates a user" do
valid_attrs = %{email: "some email", password: "some encrypted_password"}
assert {:ok, %User{} = user} = Accounts.create_user(valid_attrs)
assert user.email == "some email"
assert user.encrypted_password != "some encrypted_password"
end
test "create_user/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_user(@invalid_attrs)
end
test "update_user/2 with valid data updates the user" do
user = user_fixture()
update_attrs = %{email: "some updated email", password: "some updated encrypted_password"}
assert {:ok, %User{} = user} = Accounts.update_user(user, update_attrs)
assert user.email == "some updated email"
assert user.encrypted_password != "some updated encrypted_password"
end
test "update_user/2 with invalid data returns error changeset" do
user = user_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_user(user, @invalid_attrs)
assert user == Accounts.get_user!(user.id)
end
test "delete_user/1 deletes the user" do
user = user_fixture()
assert {:ok, %User{}} = Accounts.delete_user(user)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_user!(user.id) end
end
test "change_user/1 returns a user changeset" do
user = user_fixture()
assert %Ecto.Changeset{} = Accounts.change_user(user)
end
end
end
@@ -0,0 +1,44 @@
defmodule LinkShortener.Generators.LinkWithRandomShortenTest do
use ExUnit.Case, async: true
alias LinkShortener.Generators.LinkWithRandomShorten
@name "Some name"
@attrs %{
name: @name
}
test "generate/1 returns random safe string with 10 as length" do
assert %{
name: @name,
shorten: shorten
} = LinkWithRandomShorten.generate_one(@attrs)
assert String.length(shorten) == 10
end
test "generate/2 returns random safe string with 5 as length" do
expected_length = 5
assert %{
name: @name,
shorten: shorten
} = LinkWithRandomShorten.generate_one(@attrs, expected_length)
assert String.length(shorten) == expected_length
end
test "generate/3 returns random safe string using a lambda function" do
random_generator = fn _ -> "random_shorten" end
expected_shorten = random_generator.(14)
expected_length = expected_shorten |> String.length()
assert %{
name: @name,
shorten: shorten
} = LinkWithRandomShorten.generate_one(@attrs, expected_length, random_generator)
assert String.length(shorten) == expected_length
assert shorten == expected_shorten
end
end
@@ -0,0 +1,17 @@
defmodule LinkShortener.Generators.SafeStringTest do
use ExUnit.Case, async: true
alias LinkShortener.Generators.SafeString
@lengths [1, 2, 5, 10]
test "generate/1 returns random safe string with same length" do
for expected_length <- @lengths do
length = expected_length
|> SafeString.generate()
|> String.length()
assert length = expected_length
end
end
end
+106
View File
@@ -0,0 +1,106 @@
defmodule LinkShortener.LinksTest do
use LinkShortener.DataCase
alias LinkShortener.Links
@create_attrs %{
name: "some link name",
url: "https://gitlab.com/KKlochko/link_shortener",
shorten: "git_repo",
}
@create_generated_attrs %{
name: "some link name",
url: "https://gitlab.com/KKlochko/link_shortener",
}
@update_attrs %{
name: "some updated link name",
url: "https://gitlab.com/KKlochko/link_shortener2",
shorten: "new_git_repo",
}
@invalid_attrs %{
name: nil,
url: nil,
shorten: nil,
}
describe "links" do
alias LinkShortener.Links.Link
import LinkShortener.LinksFixtures
test "new_one/1 returns the changeset" do
assert %Ecto.Changeset{} = Links.new_one()
end
test "create_one/1 with valid data creates a link" do
assert {:ok, %Link{} = link} = Links.create_one(@create_generated_attrs)
assert link.name == "some link name"
assert link.url == "https://gitlab.com/KKlochko/link_shortener"
assert String.length(link.shorten) == 10
end
test "create_one/2 with valid data creates a link" do
assert {:ok, %Link{} = link} = Links.create_one(@create_generated_attrs, 5)
assert link.name == "some link name"
assert link.url == "https://gitlab.com/KKlochko/link_shortener"
assert String.length(link.shorten) == 5
end
test "insert_one/1 with valid data creates a link" do
assert {:ok, %Link{} = link} = Links.insert_one(@create_attrs)
assert link.name == "some link name"
assert link.url == "https://gitlab.com/KKlochko/link_shortener"
assert link.shorten == "git_repo"
end
test "insert_one/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Links.insert_one(@invalid_attrs)
end
test "get_one!/1 returns the link with given id" do
link = link_fixture()
assert Links.get_one!(link.id) == link
end
test "get_one_by!/1 returns the link with given shorten" do
link = link_fixture()
assert Links.get_one_by(%{shorten: link.shorten}) == link
end
test "get_one_by_shorten!/1 returns the link with given shorten" do
link = link_fixture()
assert Links.get_one_by_shorten(link.shorten) == link
end
test "get_all/0 returns all links" do
link = link_fixture()
assert Links.get_all() == [link]
end
test "edit_one/1 with valid data returns the changeset" do
link = link_fixture()
assert %Ecto.Changeset{} = Links.edit_one(link)
end
test "update_one/2 with valid data updates the link" do
link = link_fixture()
assert {:ok, %Link{} = link} = Links.update_one(link, @update_attrs)
assert link.name == "some updated link name"
assert link.url == "https://gitlab.com/KKlochko/link_shortener2"
assert link.shorten == "new_git_repo"
end
test "update_link/2 with invalid data returns error changeset" do
link = link_fixture()
assert {:error, %Ecto.Changeset{}} = Links.update_one(link, @invalid_attrs)
assert link == Links.get_one!(link.id)
end
test "delete_one/1 deletes the link" do
link = link_fixture()
assert {:ok, %Link{}} = Links.delete_one(link)
assert_raise Ecto.NoResultsError, fn -> Links.get_one!(link.id) end
end
end
end
@@ -0,0 +1,97 @@
defmodule LinkShortenerWeb.Api.V1.LinkControllerTest do
use LinkShortenerWeb.ConnCase
import LinkShortener.LinksFixtures
alias LinkShortener.Links.Link
alias LinkShortener.Links
@create_attrs %{
name: "some link name",
url: "https://gitlab.com/KKlochko/link_shortener",
shorten: "git_repo",
}
@update_attrs %{
name: "some updated link name",
url: "https://gitlab.com/KKlochko/link_shortener2",
shorten: "new_git_repo",
}
@invalid_attrs %{
name: nil,
url: nil,
shorten: nil,
}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
describe "index" do
test "lists all links", %{conn: conn} do
conn = get(conn, Routes.v1_link_path(conn, :index))
assert json_response(conn, 200)["data"] == []
end
end
describe "create link" do
test "renders link when data is valid", %{conn: conn} do
conn = post(conn, Routes.v1_link_path(conn, :create), link: @create_attrs)
assert %{"id" => id} = json_response(conn, 201)["data"]
conn = get(conn, Routes.v1_link_path(conn, :show, id))
assert %{
"id" => ^id,
"name" => "some link name",
"url" => "https://gitlab.com/KKlochko/link_shortener",
"shorten" => "git_repo",
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.v1_link_path(conn, :create), link: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "update link" do
setup [:create_link]
test "renders link when data is valid", %{conn: conn, link: %Link{id: id} = link} do
conn = put(conn, Routes.v1_link_path(conn, :update, link), link: @update_attrs)
assert %{"id" => ^id} = json_response(conn, 200)["data"]
conn = get(conn, Routes.v1_link_path(conn, :show, id))
assert %{
"id" => ^id,
"name" => "some updated link name",
"url" => "https://gitlab.com/KKlochko/link_shortener2",
"shorten" => "new_git_repo",
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn, link: link} do
conn = put(conn, Routes.v1_link_path(conn, :update, link), link: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "delete link" do
setup [:create_link]
test "deletes chosen link", %{conn: conn, link: link} do
conn = delete(conn, Routes.v1_link_path(conn, :delete, link))
assert response(conn, 204)
assert_error_sent 404, fn ->
get(conn, Routes.v1_link_path(conn, :show, link))
end
end
end
defp create_link(_) do
link = link_fixture()
%{link: link}
end
end
@@ -0,0 +1,46 @@
defmodule LinkShortenerWeb.Api.V1.UserControllerTest do
use LinkShortenerWeb.ConnCase
import LinkShortener.AccountsFixtures
alias LinkShortener.Accounts.User
@create_attrs %{
email: "some_email@mail.com",
password: "some password"
}
@update_attrs %{
email: "some updated email",
password: "some updated password"
}
@invalid_attrs %{
email: nil,
encrypted_password: nil
}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
describe "create user" do
test "renders user when data is valid", %{conn: conn} do
conn = post(conn, Routes.v1_user_path(conn, :create), user: @create_attrs)
assert %{
"email" => "some_email@mail.com",
"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, :create), user: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
defp create_user(_) do
user = user_fixture()
%{user: user}
end
end
@@ -0,0 +1,8 @@
defmodule LinkShortenerWeb.PageControllerTest do
use LinkShortenerWeb.ConnCase
test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200) =~ "Usage"
end
end
@@ -0,0 +1,14 @@
defmodule LinkShortenerWeb.ErrorViewTest do
use LinkShortenerWeb.ConnCase, async: true
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
test "renders 404.html" do
assert render_to_string(LinkShortenerWeb.ErrorView, "404.html", []) == "Not Found"
end
test "renders 500.html" do
assert render_to_string(LinkShortenerWeb.ErrorView, "500.html", []) == "Internal Server Error"
end
end
@@ -0,0 +1,8 @@
defmodule LinkShortenerWeb.LayoutViewTest do
use LinkShortenerWeb.ConnCase, async: true
# When testing helpers, you may want to import Phoenix.HTML and
# use functions such as safe_to_string() to convert the helper
# result into an HTML string.
# import Phoenix.HTML
end
@@ -0,0 +1,3 @@
defmodule LinkShortenerWeb.PageViewTest do
use LinkShortenerWeb.ConnCase, async: true
end
+38
View File
@@ -0,0 +1,38 @@
defmodule LinkShortenerWeb.ConnCase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a connection.
Such tests rely on `Phoenix.ConnTest` and also
import other functionality to make it easier
to build common data structures and query the data layer.
Finally, if the test case interacts with the database,
we enable the SQL sandbox, so changes done to the database
are reverted at the end of every test. If you are using
PostgreSQL, you can even run database tests asynchronously
by setting `use LinkShortenerWeb.ConnCase, async: true`, although
this option is not recommended for other databases.
"""
use ExUnit.CaseTemplate
using do
quote do
# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
import LinkShortenerWeb.ConnCase
alias LinkShortenerWeb.Router.Helpers, as: Routes
# The default endpoint for testing
@endpoint LinkShortenerWeb.Endpoint
end
end
setup tags do
LinkShortener.DataCase.setup_sandbox(tags)
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end
+58
View File
@@ -0,0 +1,58 @@
defmodule LinkShortener.DataCase do
@moduledoc """
This module defines the setup for tests requiring
access to the application's data layer.
You may define functions here to be used as helpers in
your tests.
Finally, if the test case interacts with the database,
we enable the SQL sandbox, so changes done to the database
are reverted at the end of every test. If you are using
PostgreSQL, you can even run database tests asynchronously
by setting `use LinkShortener.DataCase, async: true`, although
this option is not recommended for other databases.
"""
use ExUnit.CaseTemplate
using do
quote do
alias LinkShortener.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query
import LinkShortener.DataCase
end
end
setup tags do
LinkShortener.DataCase.setup_sandbox(tags)
:ok
end
@doc """
Sets up the sandbox based on the test tags.
"""
def setup_sandbox(tags) do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(LinkShortener.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
end
@doc """
A helper that transforms changeset errors into a map of messages.
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
assert %{password: ["password is too short"]} = errors_on(changeset)
"""
def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
end)
end)
end
end
@@ -0,0 +1,26 @@
defmodule LinkShortener.AccountsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `LinkShortener.Accounts` context.
"""
@doc """
Generate a unique user email.
"""
def unique_user_email, do: "some email#{System.unique_integer([:positive])}"
@doc """
Generate a new user.
"""
def user_fixture(attrs \\ %{}) do
{:ok, user} =
attrs
|> Enum.into(%{
email: unique_user_email(),
password: "some encrypted_password"
})
|> LinkShortener.Accounts.create_user()
LinkShortener.Accounts.get_user!(user.id)
end
end
+24
View File
@@ -0,0 +1,24 @@
defmodule LinkShortener.LinksFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `LinkShortener.Links` context.
"""
alias LinkShortener.Links
@doc """
Generate a link.
"""
def link_fixture(attrs \\ %{}) do
{:ok, link} =
attrs
|> Enum.into(%{
name: "some name",
url: "https://gitlab.com/KKlochko/link_shortener",
shorten: "api-article",
})
|> Links.create_one()
link
end
end
+2
View File
@@ -0,0 +1,2 @@
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(LinkShortener.Repo, :manual)