This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
defmodule LinkShortenerWeb.RedirectionControllerTest do
|
||||
use LinkShortenerWeb.ConnCase
|
||||
|
||||
import LinkShortener.LinksFixtures
|
||||
|
||||
alias LinkShortener.Links.Link
|
||||
alias LinkShortener.Links
|
||||
|
||||
@invalid_shorten "invalid_shorten"
|
||||
|
||||
describe "redirection via a link" do
|
||||
setup [:create_link]
|
||||
|
||||
test "redirected via the shorten", %{conn: conn, link: %Link{shorten: shorten} = link} do
|
||||
conn = get(conn, ~p"/u/#{shorten}")
|
||||
assert response(conn, 302)
|
||||
end
|
||||
|
||||
test "no redirection if a shorten is not found", %{conn: conn, link: link} do
|
||||
assert_error_sent 404, fn ->
|
||||
conn = get(conn, ~p"/u/#{@invalid_shorten}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_link(_) do
|
||||
link = link_fixture()
|
||||
%{link: link}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user