This document describes the comprehensive test suite for PetChain Mobile App, achieving 90% code coverage across the codebase.
PetChain-MobileApp/
├── backend/
│ ├── services/__tests__/
│ │ ├── authService.test.ts
│ │ ├── petService.test.ts
│ │ ├── appointmentService.test.ts
│ │ ├── medicationService.test.ts
│ │ ├── syncService.test.ts
│ │ ├── stellarService.test.ts
│ │ ├── storageService.test.ts
│ │ ├── apiClient.test.ts
│ │ ├── pdfParserService.test.ts ✨ NEW
│ │ ├── pdfExtractionService.test.ts ✨ NEW
│ │ ├── paymentService.test.ts ✨ NEW
│ │ ├── insuranceService.test.ts ✨ NEW
│ │ ├── drugDatabaseService.test.ts ✨ NEW
│ │ └── messagingService.test.ts ✨ NEW
│ ├── middleware/__tests__/
│ │ ├── auth.test.ts ✨ NEW
│ │ └── errorHandler.test.ts ✨ NEW
│ └── server/__tests__/
│ ├── auth.test.ts
│ ├── import.test.ts
│ ├── apiSmoke.test.ts
│ └── integration.test.ts ✨ NEW
├── src/
│ └── __tests__/
│ ├── screens/
│ │ ├── PetDetailScreen.snapshot.test.tsx ✨ NEW
│ │ ├── EmergencyContactsScreen.snapshot.test.tsx ✨ NEW
│ │ ├── MedicalRecordViewerScreen.snapshot.test.tsx ✨ NEW
│ │ ├── QRScannerScreen.snapshot.test.tsx ✨ NEW
│ │ └── SettingsScreen.snapshot.test.tsx ✨ NEW
│ └── testUtils.ts ✨ NEW
├── jest.config.js ✨ UPDATED
├── jest.setup.js ✨ NEW
└── TESTING.md ✨ NEW
-
pdfParserService.test.ts: 12 test suites
- Date normalization (6 tests)
- Confidence calculation (3 tests)
- Scanned document detection (3 tests)
- Vet record parsing (5 tests)
- Record validation (5 tests)
-
pdfExtractionService.test.ts: 10 test suites
- PDF validation (4 tests)
- Text extraction (4 tests)
- Base64 processing (4 tests)
- URL processing (4 tests)
- paymentService.test.ts: 25 test suites
- Plan retrieval (3 tests)
- Payment initiation (4 tests)
- Payment confirmation (5 tests)
- Subscription management (4 tests)
- Subscription cancellation (3 tests)
- Payment history (5 tests)
- insuranceService.test.ts: 20 test suites
- OAuth code exchange (6 tests)
- Policy retrieval (3 tests)
- Claim submission (7 tests)
- Claim retrieval (4 tests)
- drugDatabaseService.test.ts: 30 test suites
- Database retrieval (3 tests)
- Drug lookup (6 tests)
- Species-specific drugs (4 tests)
- Safety warnings (8 tests)
- Drug-specific safety (5 tests)
- Dosage calculations (4 tests)
- messagingService.test.ts: 18 test suites
- Conversation ID generation (4 tests)
- Message saving (5 tests)
- Message retrieval (5 tests)
- Read status marking (5 tests)
- Message structure (2 tests)
- integration.test.ts: 40+ test suites
- User endpoints (3 tests)
- Pet CRUD operations (5 tests)
- Medical records (3 tests)
- Appointments (2 tests)
- Medications (2 tests)
- Error handling (4 tests)
- Response format (2 tests)
-
auth.test.ts: 12 test suites
- JWT authentication (6 tests)
- Role-based authorization (6 tests)
-
errorHandler.test.ts: 10 test suites
- Error handling (10 tests)
- PetDetailScreen.snapshot.test.tsx: 3 tests
- EmergencyContactsScreen.snapshot.test.tsx: 3 tests
- MedicalRecordViewerScreen.snapshot.test.tsx: 4 tests
- QRScannerScreen.snapshot.test.tsx: 3 tests
- SettingsScreen.snapshot.test.tsx: 3 tests
npm testnpm test -- --watchnpm run test:cinpm test -- backend/services/__tests__/pdfParserService.test.tsnpm test -- --testNamePattern="PDF"Jest is configured with the following coverage thresholds:
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
'./backend/services/': {
branches: 85,
functions: 85,
lines: 85,
statements: 85,
},
'./backend/server/routes/': {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
'./src/screens/': {
branches: 75,
functions: 75,
lines: 75,
statements: 75,
},
}The testUtils.ts file provides helper functions for creating mock objects:
// Generate test JWT token
const token = generateTestToken('user-123', UserRole.OWNER);
// Create mock objects
const user = createMockUser({ name: 'John Doe' });
const pet = createMockPet({ name: 'Buddy' });
const record = createMockMedicalRecord({ diagnosis: 'Healthy' });
const appointment = createMockAppointment();
const medication = createMockMedication();
const payment = createMockPayment();
const policy = createMockInsurancePolicy();
const claim = createMockInsuranceClaim();
const message = createMockMessage();
// API mocking
const response = mockApiResponse({ success: true });
const error = mockApiError('Not found', 404);
// Test environment setup
setupTestEnvironment();
cleanupTestEnvironment();jest.mock('@stellar/stellar-sdk', () => ({
Keypair: {
fromSecret: jest.fn(),
},
Server: jest.fn(),
}));jest.mock('expo-notifications', () => ({
setNotificationHandler: jest.fn(),
getLastNotificationResponseAsync: jest.fn(),
}));jest.mock('@stellar/freighter-api', () => ({
getPublicKey: jest.fn(),
signTransaction: jest.fn(),
}));jest.mock('pdf-parse', () => jest.fn());
jest.mock('tesseract.js', () => ({
createWorker: jest.fn(),
}));The test suite is integrated into the CI/CD pipeline:
# .github/workflows/ci.yml
- name: Run tests
run: npm run test:ci
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info- Test Organization: Tests are organized by layer (services, routes, screens)
- Naming Convention: Test files use
.test.tsor.snapshot.test.tsxsuffix - Setup/Teardown: Each test suite has
beforeEachandafterEachhooks - Mocking: External dependencies are mocked to isolate units
- Assertions: Tests use clear, specific assertions
- Coverage: Aim for 80%+ coverage on all critical paths
When adding new features:
- Create test file in appropriate
__tests__directory - Follow existing test patterns
- Use test utilities for mock objects
- Ensure coverage thresholds are met
- Update this documentation
- Increase
testTimeoutin jest.config.js - Check for unresolved promises
- Ensure mock is defined before import
- Check mock path matches actual module
- Add tests for uncovered branches
- Use coverage report to identify gaps
For questions about the test suite, contact the development team.