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.
This commit is contained in:
Graham McIntire 2026-03-08 13:14:56 -05:00
parent 97ba2b045b
commit 90fb424f34
No known key found for this signature in database

View file

@ -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("")