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:
42
src/__tests__/unit/utils/formatPrice.test.ts
Normal file
42
src/__tests__/unit/utils/formatPrice.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { formatPrice } from "@/app/api/webhooks/saleor/utils";
|
||||
|
||||
describe("formatPrice", () => {
|
||||
it("should format RSD currency correctly", () => {
|
||||
const result = formatPrice(5479, "RSD");
|
||||
// Note: sr-RS locale uses non-breaking space between number and currency
|
||||
expect(result).toMatch(/5\.479,00\sRSD/);
|
||||
});
|
||||
|
||||
it("should format small amounts correctly", () => {
|
||||
const result = formatPrice(50, "RSD");
|
||||
expect(result).toMatch(/50,00\sRSD/);
|
||||
});
|
||||
|
||||
it("should format large amounts correctly", () => {
|
||||
const result = formatPrice(100000, "RSD");
|
||||
expect(result).toMatch(/100\.000,00\sRSD/);
|
||||
});
|
||||
|
||||
it("should format EUR currency correctly", () => {
|
||||
const result = formatPrice(100, "EUR");
|
||||
expect(result).toContain("100,00");
|
||||
expect(result).toContain("EUR");
|
||||
});
|
||||
|
||||
it("should format USD currency correctly", () => {
|
||||
const result = formatPrice(150, "USD");
|
||||
expect(result).toContain("150,00");
|
||||
expect(result).toContain("USD");
|
||||
});
|
||||
|
||||
it("should handle decimal amounts", () => {
|
||||
const result = formatPrice(1000.5, "RSD");
|
||||
expect(result).toMatch(/1\.000,50\sRSD/);
|
||||
});
|
||||
|
||||
it("should handle zero", () => {
|
||||
const result = formatPrice(0, "RSD");
|
||||
expect(result).toMatch(/0,00\sRSD/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user