π§ͺ Mock Services
Shipnative features a powerful mock services architecture that allows you to develop your entire frontend without needing to set up any backend services or API keys. This enables rapid prototyping, offline development, and a truly frontend-first workflow.How it Works
Mock services automatically activate when the corresponding API keys are missing from yourapps/app/.env file during development (__DEV__ environment). This means you can write code as if the real backend services are connected, and Shipnative will seamlessly swap in the mock implementations.
Automatic Detection Example
.env and restart your app, the mock services will automatically deactivate, and your app will connect to the live services β no code changes required!
Benefits of Mock Mode
- Frontend-First Development: Start building your UI and user experience immediately, without waiting for backend setup or API key configuration.
- Rapid Prototyping: Quickly iterate on features and designs without external dependencies.
- Offline Development: Work on your app even without an internet connection.
- Simplified Testing: Easily test various scenarios (e.g., different subscription states, empty data sets) by manipulating mock data.
- Reduced Costs: Avoid incurring costs from third-party services during early development.
Available Mock Services
Shipnative provides comprehensive mock implementations for all its core services:| Service | Mock Location | Real Service | Purpose |
|---|---|---|---|
| Supabase | services/mocks/supabase.ts | @supabase/supabase-js | Authentication, Database, Storage, Realtime, RPC |
| PostHog | services/mocks/posthog.ts | posthog-react-native | Analytics, Feature Flags |
| Sentry | services/mocks/sentry.ts | @sentry/react-native | Error Tracking |
| RevenueCat | services/mocks/revenueCat.ts | react-native-purchases | Payments (iOS, Android, Web) |
Mock Service Capabilities
1. Supabase Mock
The Supabase mock (services/mocks/supabase.ts) provides a near-complete simulation of the real Supabase client.
- Authentication:
- β Sign up, sign in, sign out with email/password.
- β Session management (persists in SecureStore).
- β Password reset (simulated).
- β User updates and auth state listeners.
- β OAuth (Google, Apple, GitHub, Twitter) flow simulation.
- Database:
- β Full CRUD operations (Create, Read, Update, Delete).
- β
All standard query filters (
eq,neq,gt,gte,lt,lte,like,ilike,in). - β
Ordering, limiting, and pagination (
order,limit,range). - β
Single row queries (
single(),maybeSingle()). - β Upsert operations.
- β In-memory storage with optional SecureStore persistence.
- Storage:
- β
File upload (
upload()), download (download()), and removal (remove()). - β
List files (
list()). - β
Public URLs (
getPublicUrl()) and signed URLs (createSignedUrl()). - β Bucket management.
- β
File upload (
- Realtime:
- β Channel subscriptions.
- β Postgres changes (INSERT, UPDATE, DELETE) simulation.
- β Programmatic event triggering for testing.
- RPC (Remote Procedure Call):
- β Register custom RPC handlers to simulate stored procedures.
2. PostHog Mock
The PostHog mock (services/mocks/posthog.ts) simulates analytics and feature flag functionality.
- Analytics: Event tracking, screen tracking, user identification, user properties, groups.
- Feature Flags: Simulated feature flag checks (
isFeatureEnabled,getFeatureFlag). - Opt-in/Opt-out: Simulated behavior.
3. Sentry Mock
The Sentry mock (services/mocks/sentry.ts) captures and logs errors and performance data to the console.
- Error Tracking: Exception capturing, message logging, breadcrumbs, user context, tags, and extra data.
- Performance Monitoring: Simulated performance transaction logging.
4. RevenueCat Mock
The RevenueCat mock (services/mocks/revenueCat.ts) simulates in-app purchase flows.
- Subscriptions: Purchase flow (always succeeds), restore purchases, get offerings/packages, customer info, entitlements, subscription states.
Testing Utilities
Each mock service provides helper utilities for testing specific scenarios, such as seeding data, triggering events, or simulating errors.Supabase Mock Testing Utilities
RevenueCat Mock Testing Utilities
Mock Service Behavior Details
Data Persistence
- During App Session: Mock data persists in memory throughout the appβs current session. Authentication sessions are maintained, and database queries work across components.
- On App Restart: All mock data is cleared, and the user is logged out. Database tables will be empty.
- Solution for Testing: Use
mockSupabaseHelpers.seedTable()in your appβs initialization logic or test setup to re-populate data.
- Solution for Testing: Use
Network Delays
Mock services simulate realistic network delays to help you test loading states and user experience.Console Logging
All mock operations log detailed information to the console, which is invaluable for debugging and understanding data flow.Transitioning to Production
When youβre ready to use real services, simply add your API keys to yourapps/app/.env file and restart your app. The mock services will automatically deactivate, and your application will connect to the live backend services. No code changes are needed!
Limitations
While mock services are powerful, some advanced features of real services cannot be fully replicated:- Row Level Security (RLS): Mock Supabase does not enforce RLS policies.
- Advanced Database Features: Complex database functions, triggers, or highly specific filters might not be fully supported.
- Performance Testing: Mocks do not accurately reflect the performance characteristics of real backend services.