berrypod/test/berrypod_web/live/setup/onboarding_test.exs
jamey 64f083d271
All checks were successful
deploy / deploy (push) Successful in 1m31s
improve setup UX: password field, setup hook, checklist banners, theme tweaks
- add password field and required shop name to setup wizard
- extract SetupHook for DRY redirect to /setup when no admin exists
- add ?from=checklist param to checklist hrefs with contextual banner on
  email settings and theme pages for easy return to dashboard
- remove email warning banner from admin layout (checklist covers it)
- make email a required checklist item (no longer optional)
- add DevReset module for wiping dev data without restart
- rename "Theme Studio" to "Theme", drop subtitle
- lower theme editor side-by-side breakpoint from 64em to 48em
- clean up login/registration pages (remove dead registration_open code)
- fix settings.put_secret to invalidate cache after write

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 17:41:08 +00:00

145 lines
4.0 KiB
Elixir

defmodule BerrypodWeb.Setup.OnboardingTest do
use BerrypodWeb.ConnCase, async: false
import Phoenix.LiveViewTest
import Berrypod.AccountsFixtures
alias Berrypod.{Products, Settings}
describe "access rules" do
test "accessible on fresh install (no admin)", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/setup")
assert html =~ "Set up your shop"
assert html =~ "Set up your account"
end
test "redirects to /admin when setup is complete", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
{:ok, _} =
Products.create_provider_connection(%{
name: "Test",
provider_type: "printify",
api_key: "test_key"
})
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_123")
{:error, redirect} = live(conn, ~p"/setup")
assert {:live_redirect, %{to: "/admin"}} = redirect
end
test "redirects to login when admin exists but not logged in", %{conn: conn} do
_user = user_fixture()
{:error, redirect} = live(conn, ~p"/setup")
assert {:live_redirect, %{to: "/users/log-in"}} = redirect
end
test "redirects to / when site is already live", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
{:ok, _} =
Products.create_provider_connection(%{
name: "Test",
provider_type: "printify",
api_key: "test_key"
})
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_123")
{:ok, _} = Settings.set_site_live(true)
{:error, redirect} = live(conn, ~p"/setup")
assert {:live_redirect, %{to: "/"}} = redirect
end
end
describe "fresh install (no admin)" do
test "shows all three cards with email form active", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/setup")
assert html =~ "Set up your account"
assert html =~ "Connect a print provider"
assert html =~ "Connect payments"
end
test "creating account auto-confirms and redirects to login", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/setup")
view
|> form(~s(form[phx-submit="create_account"]),
account: %{
shop_name: "Test Shop",
email: "admin@example.com",
password: "valid_password_123"
}
)
|> render_submit()
# The LiveView redirects to /setup/login/:token
{path, _flash} = assert_redirect(view)
assert path =~ ~r"/setup/login/.+"
end
end
describe "configure (logged in)" do
setup :register_and_log_in_user
test "shows provider and stripe steps", %{conn: conn, user: user} do
{:ok, _view, html} = live(conn, ~p"/setup")
assert html =~ user.email
assert html =~ "Connect a print provider"
assert html =~ "Connect payments"
end
test "shows provider cards", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/setup")
assert html =~ "Printify"
assert html =~ "Printful"
assert html =~ "Gelato"
assert html =~ "Coming soon"
end
test "selecting a provider shows the API key form", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/setup")
html =
view
|> form(~s(form[phx-change="select_provider"]), %{provider_select: %{type: "printify"}})
|> render_change()
assert html =~ "API token"
assert html =~ "Printify"
end
test "shows stripe form", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/setup")
assert html =~ "Secret key"
assert html =~ "Connect payments"
end
end
describe "completion" do
setup :register_and_log_in_user
test "redirects to dashboard when all three steps done", %{conn: conn} do
{:ok, _} =
Products.create_provider_connection(%{
name: "Test",
provider_type: "printify",
api_key: "test_key"
})
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_123")
{:error, redirect} = live(conn, ~p"/setup")
assert {:live_redirect, %{to: "/admin"}} = redirect
end
end
end