All checks were successful
deploy / deploy (push) Successful in 3m30s
phase 1 (no admin): show only the email form phase 2 (admin created, not logged in): "check your inbox" gate with "wrong email? start over" link that deletes the unconfirmed user phase 3 (logged in via magic link): show provider + stripe steps removes the confusing redirect to /users/log-in after account creation. users now stay on /setup throughout the entire setup process. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
155 lines
4.3 KiB
Elixir
155 lines
4.3 KiB
Elixir
defmodule BerrypodWeb.Setup.OnboardingTest do
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Berrypod.AccountsFixtures
|
|
|
|
alias Berrypod.{Accounts, 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 "shows check inbox when admin exists but not logged in", %{conn: conn} do
|
|
_user = unconfirmed_user_fixture()
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/setup")
|
|
assert html =~ "Check your inbox"
|
|
refute html =~ "Connect a print provider"
|
|
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 "phase: email form" do
|
|
test "shows only email form on fresh install", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/setup")
|
|
|
|
assert html =~ "Create admin account"
|
|
refute html =~ "Connect a print provider"
|
|
refute html =~ "Connect payments"
|
|
end
|
|
end
|
|
|
|
describe "phase: check inbox" do
|
|
test "shows check inbox after creating account", %{conn: conn} do
|
|
{:ok, view, _html} = live(conn, ~p"/setup")
|
|
|
|
html =
|
|
view
|
|
|> form("form", account: %{email: "admin@example.com"})
|
|
|> render_submit()
|
|
|
|
assert html =~ "Check your inbox"
|
|
assert html =~ "admin@example.com"
|
|
refute html =~ "Connect a print provider"
|
|
end
|
|
|
|
test "start over resets to email form", %{conn: conn} do
|
|
_user = unconfirmed_user_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/setup")
|
|
|
|
html = render_click(view, "start_over")
|
|
|
|
assert html =~ "Create admin account"
|
|
refute html =~ "Check your inbox"
|
|
refute Accounts.has_admin?()
|
|
end
|
|
end
|
|
|
|
describe "phase: 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
|
|
|> element(~s(button[phx-value-type="printify"]))
|
|
|> render_click()
|
|
|
|
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 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
|