1
0
Fork 0
mirror of https://github.com/edgurgel/httparrot synced 2025-04-05 00:02:41 -04:00
httparrot/test/redirect_handler_test.exs
2019-06-30 14:44:33 +12:00

51 lines
1.3 KiB
Elixir

defmodule HTTParrot.RedirectHandlerTest do
use ExUnit.Case
import :meck
import HTTParrot.RedirectHandler
setup do
new(:cowboy_req)
on_exit(fn -> unload() end)
:ok
end
test "malformed_request returns true if it's not an integer" do
expect(:cowboy_req, :binding, [{[:n, :req1], "a2B="}])
assert malformed_request(:req1, :state) == {true, :req1, :state}
assert validate(:cowboy_req)
end
test "malformed_request returns false if it's an integer" do
expect(:cowboy_req, :binding, [{[:n, :req1], "2"}])
assert malformed_request(:req1, :state) == {false, :req1, 2}
assert validate(:cowboy_req)
end
test "malformed_request returns 1 if 'n' is less than 1" do
expect(:cowboy_req, :binding, [{[:n, :req1], "0"}])
assert malformed_request(:req1, :state) == {false, :req1, 1}
assert validate(:cowboy_req)
end
test "moved_permanently returns 'redirect/n-1' if n > 1" do
expect(:cowboy_req, :uri, 2, "host")
assert moved_permanently(:req1, 4) == {{true, "host/redirect/3"}, :req1, nil}
assert validate(:cowboy_req)
end
test "moved_permanently returns '/get' if n = 1" do
expect(:cowboy_req, :uri, 2, "host")
assert moved_permanently(:req1, 1) == {{true, "host/get"}, :req1, nil}
assert validate(:cowboy_req)
end
end