SolveEase Pay — Testing Guide
Test Setup
# Run all tests
npm test
# Watch mode
npm run test:watch
# Coverage
npm run test:coverage
# Integration tests only
npm run test:integration
# E2E tests (Playwright)
npm run test:e2e
Unit Tests
Located in tests/unit/. Test individual functions without DB or network.
What's covered:
lib/validation/schemas.ts— Zod schema validationlib/auth/api-key.ts— API key generation and hashinglib/auth/jwt.ts— JWT sign/verifylib/security/webhook.ts— Cashfree HMAC verification
Example
// tests/unit/validation.test.ts
import { describe, it, expect } from 'vitest';
import { createOrderSchema } from '@/lib/validation/schemas';
describe('createOrderSchema', () => {
it('validates a valid order', () => {
const result = createOrderSchema.safeParse({
amount: 5000,
currency: 'INR',
customer: {
name: 'Test User',
email: 'test@example.com',
phone: '9876543210',
},
});
expect(result.success).toBe(true);
});
it('rejects negative amount', () => {
const result = createOrderSchema.safeParse({ amount: -100, ... });
expect(result.success).toBe(false);
});
});
Integration Tests
Located in tests/integration/. Test API routes with a test database.
Setup
Uses a test database (set DATABASE_URL to a separate test DB in .env.test).
# Create test DB and run migrations
DATABASE_URL=postgresql://... npx prisma migrate deploy
What's covered:
POST /api/v1/orders— with valid/invalid API keys, invalid bodiesGET /api/v1/orders/:id— correct tenant vs wrong tenantPOST /api/webhooks/cashfree— valid/invalid/forged signaturesPOST /api/internal/auth— admin login
E2E Tests (Playwright)
Located in tests/e2e/. Full browser tests against a running dev server.
Setup
npx playwright install
npm run dev & # Start dev server
npm run test:e2e
Test Scenarios
- Happy path: Create order → Visit paymentUrl → Complete with test card → Verify success page
- Failed payment: Create order → Use failure test card → Verify failure page
- Admin login: Login → Create tenant → Copy API key → Test order creation
Cashfree Sandbox Test Cards
| Scenario | Card Number | Expiry | CVV |
|---|---|---|---|
| Success | 4111111111111111 | Any future | Any 3-digit |
| Insufficient Funds | 4000000000000002 | Any future | Any 3-digit |
| Success UPI | VPA: success@cashfree | — | — |
| Failure UPI | VPA: failure@cashfree | — | — |
CI Pipeline
The following runs on every PR:
# .github/workflows/ci.yml
- Unit tests: npm test
- Type check: npx tsc --noEmit
- Lint: npm run lint
- Build: npm run build
- Integration tests: npm run test:integration