|
| 1 | +# E2E Tests for AuthProvider |
| 2 | + |
| 3 | +Playwright-based E2E tests that verify the AuthProvider OAuth authentication flow against a real Tailor Platform workspace. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +### 1. Deploy backend to Tailor Platform |
| 8 | + |
| 9 | +```bash |
| 10 | +cd e2e/backend |
| 11 | +TAILOR_PLATFORM_WORKSPACE_ID=<your-workspace-id> pnpm deploy |
| 12 | +``` |
| 13 | + |
| 14 | +After deploy, retrieve the app URL and client ID using `tailor-sdk`: |
| 15 | + |
| 16 | +```bash |
| 17 | +# Get the app URL |
| 18 | +npx tailor-sdk show --workspace-id <your-workspace-id> --json |
| 19 | +# → {"url": "https://<slug>.erp.dev", ...} |
| 20 | + |
| 21 | +# Get the OAuth2 client ID |
| 22 | +npx tailor-sdk oauth2client list --workspace-id <your-workspace-id> --json |
| 23 | +# → [{"clientId": "tpoc_...", ...}] |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Create a test user |
| 27 | + |
| 28 | +Open the GraphQL Playground for the workspace at [console.tailor.tech](https://console.tailor.tech) and run: |
| 29 | + |
| 30 | +```graphql |
| 31 | +# 1. Create the IDP user (authentication credentials) |
| 32 | +mutation CreateIdpUser { |
| 33 | + _createUser(input: { password: "TestPassword123!", name: "e2e-test@example.com" }) { |
| 34 | + id |
| 35 | + name |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +# 2. Create the TailorDB user profile (required for user lookup after auth) |
| 40 | +mutation CreateUserProfile { |
| 41 | + createUser(input: { email: "e2e-test@example.com", name: "E2E Test User", roles: [] }) { |
| 42 | + id |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### 3. Configure environment |
| 48 | + |
| 49 | +```bash |
| 50 | +cp e2e/.env.example e2e/.env |
| 51 | +``` |
| 52 | + |
| 53 | +Fill in `VITE_TAILOR_APP_URL` and `VITE_TAILOR_CLIENT_ID` (retrieved above). The test user credentials are pre-filled. |
| 54 | + |
| 55 | +### 4. Install dependencies & browsers |
| 56 | + |
| 57 | +```bash |
| 58 | +pnpm install |
| 59 | +cd e2e && npx playwright install chromium |
| 60 | +``` |
| 61 | + |
| 62 | +## Running Tests |
| 63 | + |
| 64 | +```bash |
| 65 | +# From monorepo root |
| 66 | +cd e2e && pnpm test |
| 67 | + |
| 68 | +# With Playwright UI |
| 69 | +cd e2e && pnpm test:ui |
| 70 | + |
| 71 | +# Dev server only (for debugging) |
| 72 | +cd e2e && pnpm dev |
| 73 | +``` |
| 74 | + |
| 75 | +## Test Scenarios |
| 76 | + |
| 77 | +| Test | Description | |
| 78 | +| ------------------- | ---------------------------------------------------------------- | |
| 79 | +| Auth guard display | Verifies unauthenticated users see the login UI | |
| 80 | +| Login flow | Full OAuth redirect → IDP login → callback → authenticated state | |
| 81 | +| Logout | Verifies logout returns to auth guard | |
| 82 | +| Session persistence | Confirms page reload maintains authentication | |
| 83 | + |
| 84 | +## Architecture |
| 85 | + |
| 86 | +``` |
| 87 | +e2e/ |
| 88 | +├── app/ # Minimal Vite app with AuthProvider |
| 89 | +│ ├── src/App.tsx # Test app using AuthProvider + guardComponent |
| 90 | +│ └── vite.config.ts |
| 91 | +├── backend/ # Tailor Platform config for E2E workspace |
| 92 | +│ ├── tailor.config.ts |
| 93 | +│ └── src/tailordb/user.ts |
| 94 | +├── tests/ |
| 95 | +│ └── auth.spec.ts # Playwright test specs |
| 96 | +└── playwright.config.ts |
| 97 | +``` |
0 commit comments