- Settings.site_live?/0 and set_site_live/1 for shop visibility control - Accounts.has_admin?/0 to detect single-tenant admin existence - Registration lockdown: /users/register redirects when admin exists - Setup.setup_status/0 aggregates provider, product, and stripe checks - Coming soon page at /coming-soon with themed styling - ThemeHook :require_site_live gate on all public shop routes - Site live → everyone through - Authenticated → admin preview through - No admin → fresh install demo through - Otherwise → redirect to coming soon - Go live / take offline toggle on /admin/settings - 648 tests, 0 failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
95 lines
2.4 KiB
Elixir
95 lines
2.4 KiB
Elixir
defmodule SimpleshopTheme.SetupTest do
|
|
use SimpleshopTheme.DataCase, async: false
|
|
|
|
alias SimpleshopTheme.{Setup, Settings, Products}
|
|
|
|
import SimpleshopTheme.AccountsFixtures
|
|
|
|
describe "setup_status/0" do
|
|
test "returns all false on fresh install" do
|
|
status = Setup.setup_status()
|
|
|
|
refute status.admin_created
|
|
refute status.printify_connected
|
|
refute status.products_synced
|
|
assert status.product_count == 0
|
|
refute status.stripe_connected
|
|
refute status.site_live
|
|
refute status.can_go_live
|
|
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 printify 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.printify_connected
|
|
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 "can_go_live requires printify, 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
|
|
end
|
|
end
|