69 lines
2.1 KiB
Elixir
69 lines
2.1 KiB
Elixir
|
|
defmodule BerrypodWeb.SeoControllerTest do
|
||
|
|
use BerrypodWeb.ConnCase, async: false
|
||
|
|
|
||
|
|
import Berrypod.AccountsFixtures
|
||
|
|
import Berrypod.ProductsFixtures
|
||
|
|
|
||
|
|
setup do
|
||
|
|
user_fixture()
|
||
|
|
{:ok, _} = Berrypod.Settings.set_site_live(true)
|
||
|
|
:ok
|
||
|
|
end
|
||
|
|
|
||
|
|
describe "GET /robots.txt" do
|
||
|
|
test "returns 200 with text/plain content type", %{conn: conn} do
|
||
|
|
conn = get(conn, "/robots.txt")
|
||
|
|
assert response_content_type(conn, :text) =~ "text/plain"
|
||
|
|
assert response(conn, 200)
|
||
|
|
end
|
||
|
|
|
||
|
|
test "allows crawling of shop pages", %{conn: conn} do
|
||
|
|
body = get(conn, "/robots.txt") |> response(200)
|
||
|
|
assert body =~ "User-agent: *"
|
||
|
|
assert body =~ "Allow: /"
|
||
|
|
end
|
||
|
|
|
||
|
|
test "disallows admin and sensitive paths", %{conn: conn} do
|
||
|
|
body = get(conn, "/robots.txt") |> response(200)
|
||
|
|
assert body =~ "Disallow: /admin/"
|
||
|
|
assert body =~ "Disallow: /api/"
|
||
|
|
end
|
||
|
|
|
||
|
|
test "includes sitemap URL", %{conn: conn} do
|
||
|
|
body = get(conn, "/robots.txt") |> response(200)
|
||
|
|
assert body =~ "Sitemap:"
|
||
|
|
assert body =~ "/sitemap.xml"
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe "GET /sitemap.xml" do
|
||
|
|
test "returns 200 with application/xml content type", %{conn: conn} do
|
||
|
|
conn = get(conn, "/sitemap.xml")
|
||
|
|
assert response_content_type(conn, :xml) =~ "application/xml"
|
||
|
|
assert response(conn, 200)
|
||
|
|
end
|
||
|
|
|
||
|
|
test "includes static shop pages", %{conn: conn} do
|
||
|
|
body = get(conn, "/sitemap.xml") |> response(200)
|
||
|
|
assert body =~ "<loc>"
|
||
|
|
assert body =~ "/collections/all"
|
||
|
|
assert body =~ "/about"
|
||
|
|
assert body =~ "/contact"
|
||
|
|
end
|
||
|
|
|
||
|
|
test "includes visible product URLs", %{conn: conn} do
|
||
|
|
product = product_fixture(%{slug: "test-sitemap-tee", visible: true, status: "active"})
|
||
|
|
|
||
|
|
body = get(conn, "/sitemap.xml") |> response(200)
|
||
|
|
assert body =~ "/products/#{product.slug}"
|
||
|
|
end
|
||
|
|
|
||
|
|
test "is valid XML with urlset root element", %{conn: conn} do
|
||
|
|
body = get(conn, "/sitemap.xml") |> response(200)
|
||
|
|
assert body =~ ~s(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
|
||
|
|
assert body =~ "<urlset"
|
||
|
|
assert body =~ "</urlset>"
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|