Update the RedirectionController.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
59de90601a
commit
61af12a52a
@ -0,0 +1,10 @@
|
|||||||
|
defmodule LinkShortenerWeb.RedirectionController do
|
||||||
|
use LinkShortenerWeb, :controller
|
||||||
|
|
||||||
|
alias LinkShortener.Links
|
||||||
|
|
||||||
|
def show(conn, %{"shorten" => shorten}) do
|
||||||
|
%{url: url} = Links.get_one_by_shorten!(shorten)
|
||||||
|
redirect(conn, external: url)
|
||||||
|
end
|
||||||
|
end
|
@ -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
|
Loading…
Reference in new issue