# Manoon Storefront Test Suite Comprehensive test suite for the ManoonOils storefront with focus on webhooks, commerce operations, and critical paths. ## ๐ŸŽฏ Coverage Goals - **Critical Paths**: 80%+ coverage - **Webhook Handlers**: 100% coverage - **Email Services**: 90%+ coverage - **Analytics**: 80%+ coverage ## ๐Ÿงช Test Structure ``` src/__tests__/ โ”œโ”€โ”€ unit/ โ”‚ โ”œโ”€โ”€ services/ # Business logic tests โ”‚ โ”‚ โ”œโ”€โ”€ OrderNotificationService.test.ts โ”‚ โ”‚ โ””โ”€โ”€ AnalyticsService.test.ts โ”‚ โ”œโ”€โ”€ stores/ # State management tests โ”‚ โ”‚ โ””โ”€โ”€ saleorCheckoutStore.test.ts โ”‚ โ””โ”€โ”€ utils/ # Utility function tests โ”‚ โ””โ”€โ”€ formatPrice.test.ts โ”œโ”€โ”€ integration/ โ”‚ โ”œโ”€โ”€ api/ โ”‚ โ”‚ โ””โ”€โ”€ webhooks/ โ”‚ โ”‚ โ””โ”€โ”€ saleor.test.ts # Webhook handler tests โ”‚ โ””โ”€โ”€ emails/ โ”‚ โ”œโ”€โ”€ OrderConfirmation.test.tsx โ”‚ โ””โ”€โ”€ OrderShipped.test.tsx โ””โ”€โ”€ fixtures/ # Test data โ””โ”€โ”€ orders.ts ``` ## ๐Ÿš€ Running Tests ### Unit & Integration Tests (Vitest) ```bash # Run tests in watch mode npm test # Run tests once npm run test:run # Run with coverage report npm run test:coverage # Run with UI npm run test:ui ``` ### E2E Tests (Playwright) ```bash # Run all E2E tests npm run test:e2e # Run with UI mode npm run test:e2e:ui # Run specific test npx playwright test tests/critical-paths/checkout-flow.spec.ts ``` ## ๐Ÿ“Š Test Categories ### ๐Ÿ”ฅ Critical Tests (Must Pass) 1. **Webhook Handler Tests** - ORDER_CONFIRMED: Sends emails + analytics - ORDER_CREATED: No duplicate emails/analytics - ORDER_FULFILLED: Tracking info included - ORDER_CANCELLED: Cancellation reason included - ORDER_FULLY_PAID: Payment confirmation 2. **Email Service Tests** - Correct translations (SR, EN, DE, FR) - Price formatting (no /100 bug) - Admin vs Customer templates - Address formatting 3. **Analytics Tests** - Revenue tracked once per order - Correct currency (RSD not USD) - Error handling (doesn't break order flow) ### ๐Ÿ”ง Integration Tests - Full checkout flow - Cart operations - Email template rendering - API error handling ## ๐ŸŽญ Mocking Strategy - **Resend**: Mocked (no actual emails sent) - **OpenPanel**: Mocked (no actual tracking in tests) - **Saleor API**: Can use real instance for integration tests (read-only) ## ๐Ÿ“ˆ Coverage Reports Coverage reports are generated in multiple formats: - Console output (text) - `coverage/coverage-final.json` (JSON) - `coverage/index.html` (HTML report) Open `coverage/index.html` in browser for detailed view. ## ๐Ÿ” Debugging Tests ```bash # Debug specific test npm test -- --reporter=verbose src/__tests__/unit/services/AnalyticsService.test.ts # Debug with logs DEBUG=true npm test ``` ## ๐Ÿ“ Adding New Tests 1. Create test file: `src/__tests__/unit|integration/path/to/file.test.ts` 2. Import from `@/` alias (configured in vitest.config.ts) 3. Use fixtures from `src/__tests__/fixtures/` 4. Mock external services 5. Run tests to verify ## ๐Ÿšง Current Limitations - No CI/CD integration yet (informational only) - E2E tests need Playwright browser installation - Some tests use mocked data instead of real Saleor API ## โœ… Test Checklist Before deploying, ensure: - [ ] All webhook tests pass - [ ] Email service tests pass - [ ] Analytics tests pass - [ ] Coverage >= 80% for critical paths - [ ] No console errors in tests