- 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>
126 lines
3.3 KiB
Elixir
126 lines
3.3 KiB
Elixir
defmodule Berrypod.SetupTest do
|
|
use Berrypod.DataCase, async: false
|
|
|
|
alias Berrypod.{Setup, Settings, Products}
|
|
|
|
import Berrypod.AccountsFixtures
|
|
|
|
describe "setup_status/0" do
|
|
test "returns all false on fresh install" do
|
|
status = Setup.setup_status()
|
|
|
|
refute status.admin_created
|
|
refute status.provider_connected
|
|
assert is_nil(status.provider_type)
|
|
refute status.products_synced
|
|
assert status.product_count == 0
|
|
refute status.stripe_connected
|
|
refute status.setup_complete
|
|
refute status.site_live
|
|
refute status.can_go_live
|
|
refute status.theme_customised
|
|
refute status.has_orders
|
|
refute status.checklist_dismissed
|
|
end
|
|
|
|
test "detects admin created" do
|
|
user_fixture()
|
|
status = Setup.setup_status()
|
|
|
|
assert status.admin_created
|
|
end
|
|
|
|
test "detects stripe connected" do
|
|
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_abc123")
|
|
status = Setup.setup_status()
|
|
|
|
assert status.stripe_connected
|
|
end
|
|
|
|
test "detects site live" do
|
|
{:ok, _} = Settings.set_site_live(true)
|
|
status = Setup.setup_status()
|
|
|
|
assert status.site_live
|
|
end
|
|
|
|
test "detects provider connected with products" do
|
|
{:ok, conn} =
|
|
Products.create_provider_connection(%{
|
|
name: "Test",
|
|
provider_type: "printify",
|
|
api_key: "test_api_key"
|
|
})
|
|
|
|
status = Setup.setup_status()
|
|
assert status.provider_connected
|
|
assert status.provider_type == "printify"
|
|
refute status.products_synced
|
|
assert status.product_count == 0
|
|
|
|
# Add a product
|
|
{:ok, _product} =
|
|
Products.create_product(%{
|
|
title: "Test product",
|
|
provider_product_id: "ext-1",
|
|
provider_connection_id: conn.id,
|
|
status: "active"
|
|
})
|
|
|
|
status = Setup.setup_status()
|
|
assert status.products_synced
|
|
assert status.product_count == 1
|
|
end
|
|
|
|
test "setup_complete requires admin, provider, and stripe" do
|
|
user_fixture()
|
|
|
|
{:ok, _conn} =
|
|
Products.create_provider_connection(%{
|
|
name: "Test",
|
|
provider_type: "printful",
|
|
api_key: "test_api_key"
|
|
})
|
|
|
|
refute Setup.setup_status().setup_complete
|
|
|
|
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_abc123")
|
|
|
|
assert Setup.setup_status().setup_complete
|
|
end
|
|
|
|
test "can_go_live requires provider, products, and stripe" do
|
|
{:ok, conn} =
|
|
Products.create_provider_connection(%{
|
|
name: "Test",
|
|
provider_type: "printify",
|
|
api_key: "test_api_key"
|
|
})
|
|
|
|
{:ok, _product} =
|
|
Products.create_product(%{
|
|
title: "Test product",
|
|
provider_product_id: "ext-1",
|
|
provider_connection_id: conn.id,
|
|
status: "active"
|
|
})
|
|
|
|
# Still missing stripe
|
|
refute Setup.setup_status().can_go_live
|
|
|
|
# Add stripe
|
|
{:ok, _} = Settings.put_secret("stripe_api_key", "sk_test_abc123")
|
|
|
|
assert Setup.setup_status().can_go_live
|
|
end
|
|
|
|
test "detects theme customised" do
|
|
refute Setup.setup_status().theme_customised
|
|
|
|
{:ok, _} = Settings.update_theme_settings(%{mood: "warm"})
|
|
|
|
assert Setup.setup_status().theme_customised
|
|
end
|
|
end
|
|
end
|