test: comprehensive test suite for Manoon storefront
Add complete testing infrastructure with Vitest: Testing Stack: - Vitest for unit/integration tests - @testing-library/react for component tests - @playwright/test for E2E (installed, ready to configure) - MSW for API mocking Test Coverage: 1. Webhook Handler Tests (src/__tests__/integration/api/webhooks/saleor.test.ts) - ORDER_CONFIRMED: Emails + analytics - ORDER_CREATED: No duplicates - ORDER_FULFILLED: Tracking info - ORDER_CANCELLED: Cancellation reason - ORDER_FULLY_PAID: Payment confirmation - Error handling (400/500 responses) - Currency handling (RSD preservation) 2. OrderNotificationService Tests - Email sending in all 4 languages (SR, EN, DE, FR) - Price formatting verification - Admin vs Customer templates - Address formatting - Tracking info handling 3. AnalyticsService Tests - Revenue tracking with correct currency - Duplicate prevention verification - Error handling (doesn't break flow) - Singleton pattern 4. Utility Tests - formatPrice: RSD, EUR, USD formatting - Decimal and zero handling Fixtures: - Realistic order data in src/__tests__/fixtures/orders.ts - Multiple scenarios (with tracking, cancelled, etc.) Scripts: - npm test: Run tests in watch mode - npm run test:run: Run once - npm run test:coverage: Generate coverage report - npm run test:e2e: Run Playwright tests Coverage target: 80%+ for critical paths
This commit is contained in:
35
src/__tests__/setup.ts
Normal file
35
src/__tests__/setup.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock environment variables
|
||||
process.env.NEXT_PUBLIC_SALEOR_API_URL = "https://api.manoonoils.com/graphql/";
|
||||
process.env.NEXT_PUBLIC_SITE_URL = "https://dev.manoonoils.com";
|
||||
process.env.DASHBOARD_URL = "https://dashboard.manoonoils.com";
|
||||
process.env.RESEND_API_KEY = "test-api-key";
|
||||
process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID = "test-client-id";
|
||||
process.env.OPENPANEL_CLIENT_SECRET = "test-client-secret";
|
||||
process.env.OPENPANEL_API_URL = "https://op.nodecrew.me/api";
|
||||
|
||||
// Mock Resend
|
||||
vi.mock("resend", () => ({
|
||||
Resend: vi.fn().mockImplementation(() => ({
|
||||
emails: {
|
||||
send: vi.fn().mockResolvedValue({ id: "test-email-id" }),
|
||||
},
|
||||
})),
|
||||
}));
|
||||
|
||||
// Mock OpenPanel
|
||||
vi.mock("@openpanel/nextjs", () => ({
|
||||
OpenPanel: vi.fn().mockImplementation(() => ({
|
||||
track: vi.fn().mockResolvedValue(undefined),
|
||||
revenue: vi.fn().mockResolvedValue(undefined),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Global test utilities
|
||||
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
||||
observe: vi.fn(),
|
||||
unobserve: vi.fn(),
|
||||
disconnect: vi.fn(),
|
||||
}));
|
||||
Reference in New Issue
Block a user