add setup foundations: site gate, registration lockdown, coming soon page
- 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>
This commit is contained in:
@@ -6,6 +6,22 @@ defmodule SimpleshopTheme.AccountsTest do
|
||||
import SimpleshopTheme.AccountsFixtures
|
||||
alias SimpleshopTheme.Accounts.{User, UserToken}
|
||||
|
||||
describe "has_admin?/0" do
|
||||
test "returns false when no users exist" do
|
||||
refute Accounts.has_admin?()
|
||||
end
|
||||
|
||||
test "returns true when a user exists" do
|
||||
user_fixture()
|
||||
assert Accounts.has_admin?()
|
||||
end
|
||||
|
||||
test "returns true with an unconfirmed user" do
|
||||
unconfirmed_user_fixture()
|
||||
assert Accounts.has_admin?()
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_user_by_email/1" do
|
||||
test "does not return the user if the email does not exist" do
|
||||
refute Accounts.get_user_by_email("unknown@example.com")
|
||||
|
||||
@@ -192,6 +192,25 @@ defmodule SimpleshopTheme.SettingsTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "site_live?/0 and set_site_live/1" do
|
||||
test "defaults to false when no setting exists" do
|
||||
refute Settings.site_live?()
|
||||
end
|
||||
|
||||
test "returns true after setting site live" do
|
||||
assert {:ok, _} = Settings.set_site_live(true)
|
||||
assert Settings.site_live?()
|
||||
end
|
||||
|
||||
test "returns false after setting site offline" do
|
||||
assert {:ok, _} = Settings.set_site_live(true)
|
||||
assert Settings.site_live?()
|
||||
|
||||
assert {:ok, _} = Settings.set_site_live(false)
|
||||
refute Settings.site_live?()
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete_setting/1" do
|
||||
test "deletes an existing setting" do
|
||||
{:ok, _} = Settings.put_setting("to_delete", "value")
|
||||
|
||||
94
test/simpleshop_theme/setup_test.exs
Normal file
94
test/simpleshop_theme/setup_test.exs
Normal file
@@ -0,0 +1,94 @@
|
||||
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
|
||||
Reference in New Issue
Block a user