- new /setup page with three-section onboarding (account, provider, payments) - dashboard launch checklist with progress bar, go-live, dismiss - provider registry on Provider module (single source of truth for metadata) - payments registry for Stripe - setup context made provider-agnostic (provider_connected, theme_customised, etc.) - admin provider pages now fully registry-driven (no hardcoded provider names) - auth flow: fresh installs redirect to /setup, signed_in_path respects setup state - removed old /admin/setup wizard - 840 tests, 0 failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.2 KiB
Elixir
117 lines
3.2 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 =~ "Create admin 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 "sections" do
|
|
test "shows all three sections on fresh install", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/setup")
|
|
|
|
assert html =~ "Create admin account"
|
|
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
|
|
|> element(~s(button[phx-value-type="printify"]))
|
|
|> render_click()
|
|
|
|
assert html =~ "API token"
|
|
assert html =~ "Printify"
|
|
end
|
|
end
|
|
|
|
describe "stripe section" do
|
|
test "shows stripe form", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/setup")
|
|
|
|
assert html =~ "Secret key"
|
|
assert html =~ "Connect Stripe"
|
|
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
|