consolidate settings into single admin page

Merge shop status, payments, products (Printify), account (email/password),
and advanced (dashboard/error tracker links) into /admin/settings. Simplify
Auth.Settings to a redirector for /users/settings and confirm-email tokens.
Remove Providers from sidebar nav. Update all redirects and tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-12 09:04:51 +00:00
parent 26d3bd782a
commit 4514608c07
11 changed files with 526 additions and 338 deletions

View File

@@ -19,7 +19,6 @@ defmodule SimpleshopThemeWeb.Admin.LayoutTest do
assert has_element?(view, ~s(a[href="/admin/orders"]), "Orders")
assert has_element?(view, ~s(a[href="/admin/theme"]), "Theme")
assert has_element?(view, ~s(a[href="/admin/providers"]), "Providers")
assert has_element?(view, ~s(a[href="/admin/settings"]), "Settings")
end

View File

@@ -3,7 +3,9 @@ defmodule SimpleshopThemeWeb.Admin.SettingsTest do
import Phoenix.LiveViewTest
import SimpleshopTheme.AccountsFixtures
import SimpleshopTheme.ProductsFixtures
alias SimpleshopTheme.Accounts
alias SimpleshopTheme.Settings
setup do
@@ -77,7 +79,7 @@ defmodule SimpleshopThemeWeb.Admin.SettingsTest do
html =
view
|> form("form", %{stripe: %{api_key: ""}})
|> form(~s(form[phx-submit="connect_stripe"]), %{stripe: %{api_key: ""}})
|> render_submit()
assert html =~ "Please enter your Stripe secret key"
@@ -106,7 +108,9 @@ defmodule SimpleshopThemeWeb.Admin.SettingsTest do
html =
view
|> form("form", %{webhook: %{signing_secret: "whsec_test_manual_456"}})
|> form(~s(form[phx-submit="save_signing_secret"]), %{
webhook: %{signing_secret: "whsec_test_manual_456"}
})
|> render_submit()
assert html =~ "Webhook signing secret saved"
@@ -118,7 +122,7 @@ defmodule SimpleshopThemeWeb.Admin.SettingsTest do
html =
view
|> form("form", %{webhook: %{signing_secret: ""}})
|> form(~s(form[phx-submit="save_signing_secret"]), %{webhook: %{signing_secret: ""}})
|> render_submit()
assert html =~ "Please enter a signing secret"
@@ -135,4 +139,118 @@ defmodule SimpleshopThemeWeb.Admin.SettingsTest do
refute Settings.has_secret?("stripe_api_key")
end
end
describe "products section" do
setup %{conn: conn, user: user} do
conn = log_in_user(conn, user)
%{conn: conn}
end
test "shows connect button when no provider connected", %{conn: conn} do
{:ok, view, html} = live(conn, ~p"/admin/settings")
assert html =~ "Products"
assert html =~ "Not connected"
assert has_element?(view, ~s(a[href="/admin/providers/new"]), "Connect to Printify")
end
test "shows connection info when provider connected", %{conn: conn} do
conn_record = provider_connection_fixture(%{name: "Test Shop"})
product_fixture(%{provider_connection: conn_record})
{:ok, _view, html} = live(conn, ~p"/admin/settings")
assert html =~ "Connected"
assert html =~ "Test Shop"
assert html =~ "Sync products"
end
end
describe "account section" do
setup %{conn: conn, user: user} do
conn = log_in_user(conn, user)
%{conn: conn, user: user}
end
test "renders email and password forms", %{conn: conn, user: user} do
{:ok, view, html} = live(conn, ~p"/admin/settings")
assert html =~ "Account"
assert html =~ user.email
assert has_element?(view, "#email_form")
assert has_element?(view, "#password_form")
end
test "validates email change", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/settings")
result =
view
|> element("#email_form")
|> render_change(%{"user" => %{"email" => "with spaces"}})
assert result =~ "must have the @ sign and no spaces"
end
test "submits email change", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/settings")
result =
view
|> form("#email_form", %{"user" => %{"email" => unique_user_email()}})
|> render_submit()
assert result =~ "A link to confirm your email"
end
test "validates password", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/settings")
result =
view
|> element("#password_form")
|> render_change(%{
"user" => %{
"password" => "short",
"password_confirmation" => "mismatch"
}
})
assert result =~ "should be at least 12 character(s)"
end
test "submits valid password change", %{conn: conn, user: user} do
new_password = valid_user_password()
{:ok, view, _html} = live(conn, ~p"/admin/settings")
form =
form(view, "#password_form", %{
"user" => %{
"email" => user.email,
"password" => new_password,
"password_confirmation" => new_password
}
})
render_submit(form)
new_password_conn = follow_trigger_action(form, conn)
assert redirected_to(new_password_conn) == ~p"/admin/settings"
assert Accounts.get_user_by_email_and_password(user.email, new_password)
end
end
describe "advanced section" do
setup %{conn: conn, user: user} do
conn = log_in_user(conn, user)
%{conn: conn}
end
test "shows links to system tools", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/settings")
assert has_element?(view, ~s(a[href="/admin/dashboard"]), "System dashboard")
assert has_element?(view, ~s(a[href="/admin/errors"]), "Error tracker")
end
end
end