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:
112
src/__tests__/fixtures/orders.ts
Normal file
112
src/__tests__/fixtures/orders.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
// Test fixtures for orders
|
||||
export const mockOrderPayload = {
|
||||
id: "T3JkZXI6MTIzNDU2Nzg=",
|
||||
number: 1524,
|
||||
user_email: "test@hytham.me",
|
||||
first_name: "Test",
|
||||
last_name: "Customer",
|
||||
billing_address: {
|
||||
first_name: "Test",
|
||||
last_name: "Customer",
|
||||
street_address_1: "123 Test Street",
|
||||
street_address_2: "",
|
||||
city: "Belgrade",
|
||||
postal_code: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456",
|
||||
},
|
||||
shipping_address: {
|
||||
first_name: "Test",
|
||||
last_name: "Customer",
|
||||
street_address_1: "123 Test Street",
|
||||
street_address_2: "",
|
||||
city: "Belgrade",
|
||||
postal_code: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456",
|
||||
},
|
||||
lines: [
|
||||
{
|
||||
id: "T3JkZXJMaW5lOjE=",
|
||||
product_name: "Manoon Anti-age Serum",
|
||||
variant_name: "50ml",
|
||||
quantity: 2,
|
||||
total_price_gross_amount: "10000",
|
||||
currency: "RSD",
|
||||
},
|
||||
],
|
||||
total_gross_amount: "10000",
|
||||
shipping_price_gross_amount: "480",
|
||||
channel: {
|
||||
currency_code: "RSD",
|
||||
},
|
||||
language_code: "EN",
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
export const mockOrderConverted = {
|
||||
id: "T3JkZXI6MTIzNDU2Nzg=",
|
||||
number: "1524",
|
||||
userEmail: "test@hytham.me",
|
||||
user: {
|
||||
firstName: "Test",
|
||||
lastName: "Customer",
|
||||
},
|
||||
billingAddress: {
|
||||
firstName: "Test",
|
||||
lastName: "Customer",
|
||||
streetAddress1: "123 Test Street",
|
||||
streetAddress2: "",
|
||||
city: "Belgrade",
|
||||
postalCode: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456",
|
||||
},
|
||||
shippingAddress: {
|
||||
firstName: "Test",
|
||||
lastName: "Customer",
|
||||
streetAddress1: "123 Test Street",
|
||||
streetAddress2: "",
|
||||
city: "Belgrade",
|
||||
postalCode: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456",
|
||||
},
|
||||
lines: [
|
||||
{
|
||||
id: "T3JkZXJMaW5lOjE=",
|
||||
productName: "Manoon Anti-age Serum",
|
||||
variantName: "50ml",
|
||||
quantity: 2,
|
||||
totalPrice: {
|
||||
gross: {
|
||||
amount: 10000,
|
||||
currency: "RSD",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
total: {
|
||||
gross: {
|
||||
amount: 10000,
|
||||
currency: "RSD",
|
||||
},
|
||||
},
|
||||
languageCode: "EN",
|
||||
metadata: [],
|
||||
};
|
||||
|
||||
export const mockOrderWithTracking = {
|
||||
...mockOrderConverted,
|
||||
metadata: [
|
||||
{ key: "trackingNumber", value: "TRK123456789" },
|
||||
{ key: "trackingUrl", value: "https://tracking.example.com/TRK123456789" },
|
||||
],
|
||||
};
|
||||
|
||||
export const mockOrderCancelled = {
|
||||
...mockOrderConverted,
|
||||
metadata: [
|
||||
{ key: "cancellationReason", value: "Customer requested cancellation" },
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user