From 90fb424f3464fc40b8e3cf58df929eea84c781d8 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 8 Mar 2026 13:14:56 -0500 Subject: [PATCH] feat: create test organization in e2e seed script After login, users without an organization are redirected to /orgs instead of /dashboard. The e2e tests expect /dashboard, so create a test organization for the user during seeding. Also made the seed script idempotent by deleting existing test user before creating a new one. Tested locally and confirmed working. --- priv/repo/seeds_e2e.exs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/priv/repo/seeds_e2e.exs b/priv/repo/seeds_e2e.exs index 2682636b..e6d16ab5 100644 --- a/priv/repo/seeds_e2e.exs +++ b/priv/repo/seeds_e2e.exs @@ -3,6 +3,7 @@ # Run with: mix run priv/repo/seeds_e2e.exs alias Towerops.Accounts +alias Towerops.Organizations alias Towerops.Repo # Test user credentials (must match what's used in e2e/tests/auth.setup.ts) @@ -11,6 +12,12 @@ test_password = "TestPassword123!" # Fixed TOTP secret for reproducible tests (base32 encoded) test_totp_secret = "JBSWY3DPEHPK3PXP" +# Delete existing test user if present (for idempotency) +case Repo.get_by(Towerops.Accounts.User, email: test_email) do + nil -> :ok + existing_user -> Repo.delete!(existing_user) +end + # Create test user {:ok, user} = Accounts.register_user(%{ @@ -31,7 +38,12 @@ test_totp_secret = "JBSWY3DPEHPK3PXP" {:ok, _device, _secret} = Accounts.create_totp_device(user.id, "E2E Test Authenticator", test_totp_secret) +# Create a test organization so user doesn't get redirected to /orgs +{:ok, organization} = + Organizations.create_organization(%{name: "Test Organization"}, user.id) + IO.puts("✅ Created test user: #{test_email}") +IO.puts(" Organization: #{organization.name}") IO.puts(" Password: #{test_password}") IO.puts(" TOTP Secret: #{test_totp_secret}") IO.puts("")