From a10291845587bc8ef967cbd3be74be6709ebf068 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 8 Mar 2026 10:57:18 -0500 Subject: [PATCH] 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 --- .forgejo/workflows/production.yaml | 4 +++ priv/repo/seeds_e2e.exs | 39 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 priv/repo/seeds_e2e.exs diff --git a/.forgejo/workflows/production.yaml b/.forgejo/workflows/production.yaml index fd2a3bd1..bc963adc 100644 --- a/.forgejo/workflows/production.yaml +++ b/.forgejo/workflows/production.yaml @@ -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() diff --git a/priv/repo/seeds_e2e.exs b/priv/repo/seeds_e2e.exs new file mode 100644 index 00000000..d204870c --- /dev/null +++ b/priv/repo/seeds_e2e.exs @@ -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}")