Skip to main content

Testing

SPN has comprehensive test suites for both backend and frontend.

Backend Tests

Uses pytest with async support.

Setup

cd backend

# Ensure test database exists
docker exec -it spn_postgres psql -U postgres -c "CREATE DATABASE spn_test_db;" 2>/dev/null || true

Run Tests

# All tests
pytest tests/ -v

# Unit tests only (no DB)
pytest tests/unit/ -v

# Integration tests only
pytest tests/integration/ -v

# Specific file
pytest tests/integration/test_auth.py -v

With Coverage

pytest tests/ --cov=app --cov-report=term-missing

Frontend Tests

Uses Vitest with React Testing Library.

Run Tests

cd frontend

# All tests
npm test

# Watch mode
npm run test:watch

# Coverage
npm run test:coverage

Test Structure

Backend

tests/
├── conftest.py         # Fixtures, test DB
├── unit/              # Unit tests
│   ├── test_security.py
│   └── test_config.py
└── integration/       # API endpoint tests
    ├── test_auth.py
    ├── test_companies.py
    └── test_catalog.py

Frontend

src/
├── test/
│   ├── setup.ts        # Jest DOM, MSW setup
│   ├── test-utils.tsx  # renderWithProviders
│   └── mocks/
│       ├── handlers.ts # MSW handlers
│       └── server.ts   # MSW server
└── pages/__tests__/   # Component tests

Mocking

External services are mocked in tests:
  • Sanity CMS
  • AWS S3
  • Email service
  • WhatsApp API

CI/CD

Tests run automatically on GitHub Actions. See .github/workflows/deploy.yml.