feat: add e2e test user seeding for CI

Created seeds_e2e.exs to automatically create a test user with TOTP enabled
for Playwright e2e tests. This ensures tests can authenticate in CI without
requiring manual user setup.

Test credentials (for CI only):
- Email: test@example.com
- Password: TestPassword123!
- TOTP Secret: JBSWY3DPEHPK3PXP (fixed for reproducibility)

The workflow now:
1. Loads database structure
2. Seeds test user with TOTP
3. Passes credentials to e2e tests via environment variables
This commit is contained in:
Graham McIntire 2026-03-08 10:57:18 -05:00
parent d7a5c78e5d
commit a102918455
No known key found for this signature in database
2 changed files with 43 additions and 0 deletions

View file

@ -159,6 +159,7 @@ jobs:
run: |
mix ecto.create
mix ecto.load --skip-if-loaded
mix run priv/repo/seeds_e2e.exs
- name: Start Phoenix server in background
run: |
@ -197,6 +198,9 @@ jobs:
run: npm test
env:
CI: true
TEST_USER_EMAIL: test@example.com
TEST_USER_PASSWORD: TestPassword123!
TEST_USER_TOTP_SECRET: JBSWY3DPEHPK3PXP
- name: Upload test results
if: failure()

39
priv/repo/seeds_e2e.exs Normal file
View file

@ -0,0 +1,39 @@
# Seeds for E2E testing
# Creates a test user with TOTP enabled for Playwright tests
# Run with: mix run priv/repo/seeds_e2e.exs
alias Towerops.Accounts
alias Towerops.Repo
# Test user credentials (must match what's used in e2e/tests/auth.setup.ts)
test_email = "test@example.com"
test_password = "TestPassword123!"
# Fixed TOTP secret for reproducible tests (base32 encoded)
test_totp_secret = "JBSWY3DPEHPK3PXP"
# Create test user
{:ok, user} =
Accounts.register_user(%{
email: test_email,
password: test_password,
password_confirmation: test_password
})
# Confirm the user's email
{:ok, _user} = Accounts.confirm_user_email(user.email)
# Enable TOTP for the user
{:ok, _credential} =
Accounts.create_totp_credential(user, %{
name: "E2E Test Authenticator",
secret: test_totp_secret
})
IO.puts("✅ Created test user: #{test_email}")
IO.puts(" Password: #{test_password}")
IO.puts(" TOTP Secret: #{test_totp_secret}")
IO.puts("")
IO.puts("Set these in your CI environment or .env file:")
IO.puts(" TEST_USER_EMAIL=#{test_email}")
IO.puts(" TEST_USER_PASSWORD=#{test_password}")
IO.puts(" TEST_USER_TOTP_SECRET=#{test_totp_secret}")