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}")