Skip to main content

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

  1. API Endpoints - REST API CRUD operations and edge cases
  2. Performance SLAs - Response times and error rates
  3. OpenAPI Schema Compliance - Responses match schema definitions
  4. 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

CategoryContextsTestsStatus
Core BusinessTenants, Merchants, Providers, LocationsCRUD + Pagination✅ 100%
SchedulingAppointments, Bookings, AvailabilitiesCRUD + Pagination✅ 100%
CustomersEndCustomers, Messages, SubscriptionsCRUD + Pagination✅ 100%
FinanceTransactions, Invoices, PaymentAccountsCRUD + Pagination✅ 100%
PlatformRoles, Users, AuditLogs, WebsitesCRUD + Pagination✅ 100%
SearchAppointmentSearches, EndCustomerSearchesSearch Operations✅ 100%

Running Integration Tests

cd integration-tests

# Install dependencies
npm install

# Run all tests
ADMIN_EMAIL=[email protected] \
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


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 GroupEndpointsTestedCoverage
Authentication33100%
Tenant55100%
Merchant55100%
Service55100%
Appointment66100%
Booking55100%
EndCustomer55100%
Transaction55100%
AuditLog22100%

Performance Thresholds

All integration tests enforce performance SLAs:

MetricThresholdEnforcement
p95 Response Time< 500msCI fails if exceeded
Error Rate< 1%CI fails if exceeded
Check Pass Rate> 95%CI fails if below

Next Steps

For API Users

  1. Visit API Reference to explore endpoints
  2. Try requests using "Try It Now" button
  3. Follow Setting Up SCP Client for step-by-step setup

For Developers

  1. Clone the repository
  2. Run docker compose up -d to start services
  3. Run integration tests: cd integration-tests && npm test