E2E Testing Framework
Comprehensive end-to-end test suite for the YourEra platform.
Overview
The E2E test suite is a Playwright-based framework organized into a 5-tier architecture. It validates the entire YourEra platform from health checks through full patient journeys, with 120+ tests across all tiers.
Architecture
┌──────────────────────────────────────────────┐
│ Tier 5: Full Scenarios │
│ Complete patient journeys end-to-end │
├──────────────────────────────────────────────┤
│ Tier 4: UI Tests │
│ Browser-based form and portal testing │
├──────────────────────────────────────────────┤
│ Tier 3: Business Flows │
│ Cross-service integration flows │
├──────────────────────────────────────────────┤
│ Tier 2: API Contracts │
│ Endpoint input/output validation │
├──────────────────────────────────────────────┤
│ Tier 1: Smoke Tests │
│ Service health checks (~5s) │
└──────────────────────────────────────────────┘
Test Count Summary
| Tier | Tests | Duration | Purpose |
|---|---|---|---|
| 1 — Smoke | 9 | ~5s | All services responding |
| 2 — API Contracts | 56+ | ~30s | Every endpoint validates I/O |
| 3 — Business Flows | 20+ | ~2min | Cross-service flows |
| 4 — UI | 15+ | ~3min | Browser-based testing |
| 5 — Scenarios | 10+ | ~5min | Full patient journeys |
Tier 1: Smoke Tests
Smoke tests are the fastest tier, completing in approximately 5 seconds. They verify that every service in the platform is reachable and responding to health check endpoints.
Checks (9 Tests)
| Service | Endpoint | Expected |
|---|---|---|
| Integration Service | api.hisera.com/health |
200 OK |
| Intake Gateway | intake-api.hisera.com/health |
200 OK |
| iOS API | api-app.hisera.com/health |
200 OK |
| Patient Portal | patient.hisera.com/health |
200 OK |
| Admin Portal | admin.yourera.com |
200 OK |
| GLP-1 Intake | intake.hisera.com/start-online-visit/glp-1/ |
200 OK |
| NAD+ Intake | intake.hisera.com/start-online-visit/nad/ |
200 OK |
| Microdose Intake | intake.hisera.com/start-online-visit/micro/ |
200 OK |
| Canvas FHIR | yourera.canvasmedical.com/metadata |
200 OK + CapabilityStatement |
Tier 2: API Contracts
API contract tests validate every public and internal API endpoint. Each test sends a well-formed request and validates the response status code, shape, and required fields. Invalid inputs are also tested to verify proper error handling.
Coverage (56+ Tests)
- Admin API — All
/api/admin/*endpoints (stats, patients, orders, sync-logs, refund, charge) - RxQueue API —
/api/tasks,/api/task-action,/api/rx-queue/hp-data,/api/practitioners - Patient API — All
/api/patient/*endpoints (profile, prescriptions, shipments, messages, notifications) - Intake Gateway —
/submit-intake,/validate-coupon,/verify-email - Pharmacy Router —
/rx/prescriptions/submit,/rx/prescriptions/:id, webhooks - Auth Endpoints — OTP send/verify, Canvas HMAC validation, session management
Test Pattern
import { test, expect } from '@playwright/test';
import { adminClient } from '../lib/api-client';
test('GET /api/admin/stats returns dashboard metrics', async () => {
const res = await adminClient.get('/api/admin/stats');
expect(res.status).toBe(200);
expect(res.data).toHaveProperty('revenue');
expect(res.data).toHaveProperty('pendingRxCount');
expect(res.data).toHaveProperty('shipmentPipeline');
});
Tier 3: Business Flows
Business flow tests validate cross-service integrations by executing multi-step sequences that span multiple services. These tests use real API calls but may use test-mode flags to avoid side effects.
Flows Tested
| Flow | Services | Description |
|---|---|---|
| Intake to Canvas | Intake Gateway, Canvas FHIR | Submit intake, verify Canvas patient created with correct demographics |
| Approve to Payment | RxQueue, Orchestrator, Stripe | Approve Rx, verify payment charged on saved method |
| Shipment Lifecycle | Shipping Service, FedEx, Integration DB | Create label, update status through packed/shipped/delivered |
| Messaging Roundtrip | Patient Portal, Canvas FHIR | Patient sends message, verify it appears in Canvas Communications |
| Pharmacy Routing | Pharmacy Router, PioneerRx, Boothwyn | Submit Rx for different states, verify correct pharmacy selected |
| Refill Cycle | Refill Cron, Orchestrator, Shipping | Trigger refill, verify new shipment created for GMP orders |
Tier 4: UI Tests
UI tests use Playwright's browser automation to test the frontend applications. They verify form validation, navigation, error handling, and user interactions in actual browser contexts.
Test Areas
- Intake Forms — Step navigation, field validation, auto-formatting (DOB, phone), address autocomplete, error states
- Edge Cases — Browser back button, page refresh with draft persistence, expired sessions, network errors
- Admin Portal — Login flow, RxQueue interaction, patient search, order filters
- Patient Portal — Login flow, dashboard rendering, message sending, appointment booking
Browser Configuration
// playwright.config.ts
{
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'mobile', use: { ...devices['iPhone 14'] } },
],
webServer: {
command: 'npm run dev',
port: 5173,
}
}
Tier 5: Full Scenarios
Scenario tests are the highest-level tests, executing complete patient journeys from intake through prescription delivery. Each scenario combines API calls and browser automation to verify the full workflow.
Scenarios
| Scenario | Steps | Description |
|---|---|---|
| GLP-1 Patient Journey | 12 | Complete intake, Rx review, approval, payment, GMP shipment, tracking, refill |
| NAD+ Patient Journey | 12 | NAD+ intake with G6PD screening, approval, Boothwyn fulfillment, webhook tracking |
| Microdose Patient Journey | 10 | Microdose intake, medication preference, approval, pharmacy routing |
| Admin Verification | 8 | Admin login, dashboard check, patient lookup, order review, sync log inspection |
| RxQueue Browser Approve | 6 | Canvas HMAC login, task selection, H&P completion, dosage selection, approve action |
Running Tests
Commands
| Command | Tier | Description |
|---|---|---|
npm run smoke |
1 | Run all smoke/health check tests |
npm run api |
2 | Run all API contract tests |
npm run flows |
3 | Run business flow integration tests |
npm run ui |
4 | Run browser-based UI tests |
npm run journey |
5 | Run full scenario tests |
npm test |
All | Run all tiers sequentially |
npm run test:parallel |
1-3 | Run tiers 1-3 in parallel (no browser needed) |
Environment Setup
# Install dependencies
npm install
# Install Playwright browsers
npx playwright install
# Copy env template
cp .env.example .env
# Run smoke tests to verify setup
npm run smoke
Adding Tests
File Structure
e2e-tests/
tests/
tier-1-smoke/ # Health check tests
tier-2-api/ # API contract tests
tier-3-flows/ # Business flow tests
tier-4-ui/ # Browser UI tests
tier-5-scenarios/ # Full journey tests
lib/
api-client.ts # HTTP client with auth
canvas-client.ts # Canvas FHIR helpers
stripe-helpers.ts # Stripe test mode helpers
state-manager.ts # Cross-test state sharing
test-data.ts # Test data generators
Creating a New Test
- Choose the appropriate tier directory based on the test scope
- Create a new
.spec.tsfile following the naming convention:feature-name.spec.ts - Import the appropriate client from
lib/(adminClient, patientClient, etc.) - Use the state manager for tests that depend on previously created data
- Tag the test with
@tier-Nfor filtering
State Management
import { stateManager } from '../lib/state-manager';
// Store data from one test
stateManager.set('testPatientId', patientId);
// Retrieve in a later test
const patientId = stateManager.get('testPatientId');
Test Credentials
All test credentials are stored in the .env file. The .env.example
template lists all required variables.
Required Environment Variables
| Variable | Service | Description |
|---|---|---|
CANVAS_CLIENT_ID |
Canvas | OAuth2 client credentials (dev sandbox) |
CANVAS_CLIENT_SECRET |
Canvas | OAuth2 client secret |
STRIPE_SECRET_KEY |
Stripe | Stripe test mode secret key (sk_test_*) |
ADMIN_SECRET |
Integration Service | Server-to-server admin authentication |
CANVAS_AUTH_SECRET |
Canvas Plugin | HMAC signing secret (same as ADMIN_JWT_SECRET) |
PHARMACY_ROUTER_API_KEY |
Pharmacy Router | HMAC API key for pharmacy submission |
PHARMACY_ROUTER_API_SECRET |
Pharmacy Router | HMAC signing secret |
.env files to version control. All test credentials should
use sandbox/test mode keys. The .env file is listed in .gitignore.
sk_test_*).
Test card numbers: 4242424242424242 (success), 4000000000000002 (decline).