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

TierTestsDurationPurpose
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)

ServiceEndpointExpected
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)

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

FlowServicesDescription
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

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

ScenarioStepsDescription
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

CommandTierDescription
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

  1. Choose the appropriate tier directory based on the test scope
  2. Create a new .spec.ts file following the naming convention: feature-name.spec.ts
  3. Import the appropriate client from lib/ (adminClient, patientClient, etc.)
  4. Use the state manager for tests that depend on previously created data
  5. Tag the test with @tier-N for 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

VariableServiceDescription
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
Security Never commit .env files to version control. All test credentials should use sandbox/test mode keys. The .env file is listed in .gitignore.
Stripe Test Mode All payment-related tests must use Stripe test mode keys (sk_test_*). Test card numbers: 4242424242424242 (success), 4000000000000002 (decline).