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 validation
  • lib/auth/api-key.ts — API key generation and hashing
  • lib/auth/jwt.ts — JWT sign/verify
  • lib/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 bodies
  • GET /api/v1/orders/:id — correct tenant vs wrong tenant
  • POST /api/webhooks/cashfree — valid/invalid/forged signatures
  • POST /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

  1. Happy path: Create order → Visit paymentUrl → Complete with test card → Verify success page
  2. Failed payment: Create order → Use failure test card → Verify failure page
  3. Admin login: Login → Create tenant → Copy API key → Test order creation

Cashfree Sandbox Test Cards

ScenarioCard NumberExpiryCVV
Success4111111111111111Any futureAny 3-digit
Insufficient Funds4000000000000002Any futureAny 3-digit
Success UPIVPA: success@cashfree
Failure UPIVPA: 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