A production-grade API integration testing framework built with Node.js, Axios, Mocha, Chai, AJV (JSON Schema validation), and PostgreSQL.
The framework validates end-to-end API behavior, contracts, authentication flows, user CRUD lifecycle (create, read, update, delete), contract validation, retry logic, and database persistence using real HTTP calls and real backend state — without mocking.
It demonstrates how to build a maintainable, extensible, and CI-ready API testing framework suitable for real-world backend services.
- Centralized Axios client
- Automatic auth token injection
- Retry logic for transient network / 5xx failures
- Structured request / response error logging
- Login helpers for test setup
- In-memory session token management
- Automatic
Authorizationheader handling
- Create, read, update, and delete user flows validated end-to-end
- Authorization and role-based access enforced per operation
- Database state verification for write operations
- Positive and negative path coverage
- JSON Schema validation using AJV
- Schemas applied inline within functional tests
- Early detection of breaking API contract changes
- PostgreSQL integration for end-to-end validation
- DB assertions used only for write operations
- Explicit safety guards to prevent accidental production access
- Single environment configuration via
.env - Secrets isolated using
.env.example - Feature flags (e.g.
ALLOW_DB_TESTS) for destructive checks
- Deterministic test data generation
- Clean separation of API, helpers, schemas, and DB logic
- Safe execution in local and CI environments
framework/
├── api/
│ ├── apiClient.js
│ ├── authApi.js
│ ├── authProfileApi.js
│ ├── createUserApi.js
│ ├── deleteUserApi.js
│ ├── updateUserApi.js
│ └── userApi.js
│
├── helpers/
│ ├── authHelper.js
│ └── schemaHelper.js
│
├── db/
│ ├── dbClient.js
│ └── dbQueries.js
│
├── fixture/
│ └── users.json
│
├── schema/
│ ├── loginResponse.schema.json
│ ├── userProfile.schema.json
│ ├── entityNotFound.schema.json
│ └── errorResponse.schema.json
│
├── utils/
│ ├── env.js
│ ├── session.js
│ ├── retry.js
│ ├── dataFactory.js
│ └── schemaValidator.js
│
tests/
├── auth/
│ └── auth.spec.js
└── users/
└── user.spec.js
npm installnpm testDatabase checks are disabled by default.
ALLOW_DB_TESTS=true npm testCreate a .env file based on .env.example:
BASE_URL=https://api.example.com
ADMIN_USERNAME=admin_user
ADMIN_PASSWORD=********
SERVICE_TOKEN=********
DB_HOST=localhost
DB_PORT=5432
DB_NAME=users_service
DB_USER=test_user
DB_PASSWORD=********
DB_SSL=false
ALLOW_DB_TESTS=falseMIT