Skip to content

Commit

Permalink
Add a test case for 301 redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
fredwu committed Oct 10, 2023
1 parent 0df2c55 commit bd3c190
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/lib/crawler/fetcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ defmodule Crawler.FetcherTest do
assert page.body == "<html>200</html>"
end

test "success: 301", %{bypass: bypass, url: url} do
Bypass.expect_once(bypass, "GET", "/fetcher/301", fn conn ->
conn
|> Plug.Conn.merge_resp_headers([{"location", "#{url}/fetcher/301_200"}])
|> Plug.Conn.resp(301, "")
end)

Bypass.expect_once(bypass, "GET", "/fetcher/301_200", fn conn ->
Plug.Conn.resp(conn, 200, "<html>301_200</html>")
end)

url = "#{url}/fetcher/301"

@defaults
|> Map.merge(%{url: url})
|> Fetcher.fetch()

page = Store.find({url, nil})

assert page.url == url
assert page.body == "<html>301_200</html>"
end

test "failure: 500", %{bypass: bypass, url: url} do
url = "#{url}/fetcher/500"

Expand Down

0 comments on commit bd3c190

Please sign in to comment.