Skip to main content

Source: ocean/tests/integration/README.md | ✏️ Edit on GitHub

Integration Tests

This directory contains integration tests that demonstrate and validate the critical patterns in the Ocean platform:

Test Coverage

1. Authentication Flow Tests (auth-flow.test.ts)

  • User signup with organization creation
  • Race condition handling in auth context
  • Session expiry and refresh
  • Authentication error handling
  • Organization provisioning during signup

2. GraphQL Resolver Tests (graphql-resolvers.test.ts)

  • Row-level security (RLS) enforcement
  • Role-based access control for organization data
  • Provisioning retry logic
  • Concurrent update handling with optimistic locking
  • Field-level permission validation

3. Stripe Edge Function Tests (stripe-functions.test.ts)

  • Shared authentication wrapper pattern
  • Billing operations with proper auth
  • Subscription management with error handling
  • Payment method management
  • Customer portal session creation

Key Patterns Validated

Authentication Wrapper Pattern

All Edge Functions use a consistent authentication wrapper that:

  • Validates JWT tokens
  • Loads user and organization context
  • Handles CORS preflight requests
  • Provides consistent error responses

Error Handling

  • Graceful degradation for external service failures
  • Proper error messages for user-facing operations
  • Retry logic for transient failures

Concurrent Operations

  • Optimistic locking for organization updates
  • Atomic provisioning operations
  • Race condition prevention in auth state changes

Running Tests

# Run all integration tests
pnpm test:integration

# Run specific test file
pnpm vitest run tests/integration/auth-flow.test.ts

# Run tests in watch mode
pnpm vitest watch tests/integration

Implementation Notes

These tests focus on validating patterns rather than exact implementations. They use mocked services to ensure tests run quickly and reliably without external dependencies.

The actual Edge Function and GraphQL implementations follow these same patterns but with real Supabase and Stripe integrations.