2026-02-26 14:14:14 +00:00
|
|
|
defmodule BerrypodWeb.Plugs.BrokenUrlTrackerTest do
|
|
|
|
|
use BerrypodWeb.ConnCase, async: true
|
|
|
|
|
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
import Berrypod.AccountsFixtures
|
|
|
|
|
|
|
|
|
|
alias Berrypod.{Redirects, Settings}
|
2026-02-26 14:14:14 +00:00
|
|
|
|
|
|
|
|
setup do
|
|
|
|
|
Redirects.create_table()
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
# Create admin user so SetupHook allows access
|
|
|
|
|
user_fixture()
|
|
|
|
|
# Mark site as live so requests aren't redirected to /coming-soon
|
|
|
|
|
{:ok, _} = Settings.set_site_live(true)
|
2026-02-26 14:14:14 +00:00
|
|
|
:ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "records broken URL on 404", %{conn: conn} do
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
# Multi-segment path goes through the catch-all route and raises NotFoundError.
|
|
|
|
|
# The BrokenUrlTracker plug catches this and records it before re-raising.
|
|
|
|
|
assert_error_sent :not_found, fn ->
|
|
|
|
|
get(conn, "/zz/nonexistent-path")
|
|
|
|
|
end
|
2026-02-26 14:14:14 +00:00
|
|
|
|
|
|
|
|
[broken_url] = Redirects.list_broken_urls()
|
2026-02-28 02:21:11 +00:00
|
|
|
assert broken_url.path == "/zz/nonexistent-path"
|
2026-02-26 14:14:14 +00:00
|
|
|
assert broken_url.recent_404_count == 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "skips static asset paths", %{conn: conn} do
|
integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution
Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling
Test updates for cache isolation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00
|
|
|
# Static asset paths should not be recorded as broken URLs.
|
|
|
|
|
# These raise NotFoundError but the tracker ignores them.
|
|
|
|
|
assert_error_sent :not_found, fn ->
|
|
|
|
|
get(conn, "/assets/missing-file.js")
|
|
|
|
|
end
|
2026-02-26 14:14:14 +00:00
|
|
|
|
|
|
|
|
assert Redirects.list_broken_urls() == []
|
|
|
|
|
end
|
|
|
|
|
end
|