Quality Checks & Integration Testing
The Service Commerce Platform uses automated validation to ensure API documentation stays in sync with the actual implementation.
Overview
What Gets Validated
- API Endpoints - REST API CRUD operations and edge cases
- Performance SLAs - Response times and error rates
- OpenAPI Schema Compliance - Responses match schema definitions
- Documentation Accuracy - Code examples match actual API behavior
Validation Pipeline
Integration Testing with Vitest
Test Structure
integration-tests/
├── tests/
│ ├── tenants.test.ts
│ ├── merchants.test.ts
│ ├── appointments.test.ts
│ ├── bookings.test.ts
│ ├── end_customers.test.ts
│ ├── providers.test.ts
│ ├── services.test.ts
│ ├── locations.test.ts
│ ├── availabilities.test.ts
│ ├── transactions.test.ts
│ ├── invoices.test.ts
│ ├── audit_logs.test.ts
│ └── ... (28 test files total)
├── helpers/
│ └── sandbox.ts
├── vitest.config.ts
└── vitest.setup.ts
Current Coverage
| Category | Contexts | Tests | Status |
|---|---|---|---|
| Core Business | Tenants, Merchants, Providers, Locations | CRUD + Pagination | ✅ 100% |
| Scheduling | Appointments, Bookings, Availabilities | CRUD + Pagination | ✅ 100% |
| Customers | EndCustomers, Messages, Subscriptions | CRUD + Pagination | ✅ 100% |
| Finance | Transactions, Invoices, PaymentAccounts | CRUD + Pagination | ✅ 100% |
| Platform | Roles, Users, AuditLogs, Websites | CRUD + Pagination | ✅ 100% |
| Search | AppointmentSearches, EndCustomerSearches | Search Operations | ✅ 100% |
Running Integration Tests
cd integration-tests
# Install dependencies
npm install
# Run all tests
ADMIN_EMAIL=admin@alvera-scp-dev.local \
ADMIN_PASSWORD='DevPassword123!' \
TENANT_NAME=alvera-scp-dev \
npm test
# Run specific test file
npm test -- tests/tenants.test.ts
# Run with coverage
npm run test:coverage
Test Pattern
Each test file follows this pattern:
import { describe, it, expect, beforeAll } from 'vitest';
import { OpenAPI, AuthenticationService } from '@scp/sdk';
import { createTenant } from '@scp/client-samples/tenants/create';
import { listTenants } from '@scp/client-samples/tenants/list';
describe('Tenant API Integration Tests', () => {
beforeAll(async () => {
// Authenticate and get Bearer token
const auth = await AuthenticationService.sessionCreate({
requestBody: {
email: process.env.ADMIN_EMAIL!,
password: process.env.ADMIN_PASSWORD!,
tenant_name: process.env.TENANT_NAME!,
},
});
OpenAPI.TOKEN = auth.token;
});
it('should create a tenant (201)', async () => {
const tenant = await createTenant();
expect(tenant.id).toBeDefined();
expect(tenant.name).toContain('Test Tenant');
});
it('should list tenants with pagination (200)', async () => {
const { data, meta } = await listTenants();
expect(data).toBeInstanceOf(Array);
expect(meta.page_size).toBe(20);
});
});
TypeScript Client Samples
Client samples serve as both documentation examples and test helpers:
Structure
client_samples/typescript/
├── tenants/
│ ├── create.ts # createTenant()
│ ├── list.ts # listTenants()
│ ├── show.ts # getTenant()
│ ├── update.ts # updateTenant()
│ └── delete.ts # deleteTenant()
├── merchants/
├── appointments/
├── bookings/
└── ... (27 context directories)
Usage
// Import from client samples
import { createTenant } from '@scp/client-samples/tenants/create';
import { createMerchant } from '@scp/client-samples/merchants/create';
import { createAppointment } from '@scp/client-samples/appointments/create';
// Use in tests or applications
const tenant = await createTenant();
const merchant = await createMerchant(tenant.id, merchantOrgId);
const appointment = await createAppointment(tenant.id, merchantId, ...);
Download
- TypeScript Client Samples - Reusable API examples
- Integration Tests - Complete Vitest test suite
API Coverage Report
After running tests, the API coverage report shows which endpoints are tested:
# Generate coverage report
npm run test:coverage
# View HTML report
open coverage/index.html
Coverage by Tag Group
| Tag Group | Endpoints | Tested | Coverage |
|---|---|---|---|
| Authentication | 3 | 3 | 100% |
| Tenant | 5 | 5 | 100% |
| Merchant | 5 | 5 | 100% |
| Service | 5 | 5 | 100% |
| Appointment | 6 | 6 | 100% |
| Booking | 5 | 5 | 100% |
| EndCustomer | 5 | 5 | 100% |
| Transaction | 5 | 5 | 100% |
| AuditLog | 2 | 2 | 100% |
Performance Thresholds
All integration tests enforce performance SLAs:
| Metric | Threshold | Enforcement |
|---|---|---|
| p95 Response Time | < 500ms | CI fails if exceeded |
| Error Rate | < 1% | CI fails if exceeded |
| Check Pass Rate | > 95% | CI fails if below |
Next Steps
For API Users
- Visit API Reference to explore endpoints
- Try requests using "Try It Now" button
- Follow Setting Up SCP Client for step-by-step setup
For Developers
- Clone the repository
- Run
docker compose up -dto start services - Run integration tests:
cd integration-tests && npm test
Related Documentation
- API Reference - Interactive API docs
- Setting Up SCP Client - SDK setup guide
- Cookbook - Interactive guides