Skip to content

VidhyaSangeetha/enterprise-api-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

A battle-tested API testing architecture built from experience managing 37+ enterprise-grade test suites.

Mocha Supertest Chai k6 Allure TestRail


🧠 Why I Built This

This template distills enterprise-grade API testing patterns into a clean, reusable framework. It demonstrates advanced concepts like:

  • Real JWT Authentication Flow: Using DummyJSON's /auth/login to show token caching and injection.
  • Enterprise Pagination: Handling limit, skip, and total metadata.
  • Data-Driven Testing: Dynamically generating tests from JSON fixtures.
  • Performance SLAs: k6 benchmarks with automated pass/fail thresholds.

πŸ›  Prerequisites

To run performance tests, you need k6 installed on your system:

  • Windows: winget install GrafanaLabs.k6
  • macOS: brew install k6
  • Linux: See k6 docs

πŸš€ Quick Start

# 1. Install dependencies
npm install

# 2. Run all tests
npm test

# 3. Run specific suites
npm run test:smoke        # Critical path only
npm run test:regression   # Full CRUD coverage
npm run test:integration  # End-to-end flows
npm run test:ddt          # Data-driven tests

Zero external setup required β€” tests run against DummyJSON, a production-ready mock API.


πŸ“ Project Architecture

enterprise-api-template/
β”œβ”€β”€ config/              # Centralized env config (never read process.env directly)
β”œβ”€β”€ helpers/             # ⭐ Reusable infrastructure layer
β”‚   β”œβ”€β”€ auth.js          #    Token caching & login flows
β”‚   β”œβ”€β”€ request.js       #    Generic HTTP wrapper (GET/POST/PUT/PATCH/DELETE)
β”‚   β”œβ”€β”€ assertions.js    #    Status-code assertion helpers
β”‚   β”œβ”€β”€ data-factory.js  #    Faker.js dynamic data generation
β”‚   └── cleanup.js       #    Test teardown utilities
β”œβ”€β”€ fixtures/            # Test data (JSON + YAML flows)
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ smoke/           # Gatekeeper tests β€” run first in CI
β”‚   β”œβ”€β”€ regression/      # Full feature coverage per module
β”‚   β”œβ”€β”€ integration/     # Cross-module end-to-end flows
β”‚   β”œβ”€β”€ data-driven/     # Fixture-driven parameterized tests
β”‚   └── performance/     # k6 scripts (smoke/load/stress)
β”œβ”€β”€ scripts/             # TestRail sync, Allure report generation
└── .github/workflows/   # CI/CD pipeline

Helper Layer β€” The Key Differentiator

graph LR
    A[Test Suite] --> B[helpers/request.js]
    A --> C[helpers/assertions.js]
    A --> D[helpers/data-factory.js]
    B --> E[supertest + config]
    C --> E
    D --> F[Faker.js]
    A --> G[helpers/auth.js]
    G --> E
Loading

Instead of writing raw supertest calls in every test file, the helper layer provides a consistent, documented API that scales to dozens of modules.


πŸ§ͺ Test Coverage Matrix

Suite File Tests What It Covers
🚬 Smoke health-check.test.js 5 API reachability, response shape
🚬 Smoke auth.test.js 6 Login/register critical paths
πŸ§ͺ Regression users.test.js 16 Full CRUD lifecycle, edge cases
πŸ§ͺ Regression users-search.test.js 9 Pagination, filtering, delayed response
πŸ§ͺ Regression register.test.js 8 Registration validation scenarios
πŸ”— Integration user-lifecycle-flow.test.js 6 End-to-end multi-step flow
πŸ“Š DDT users-ddt.test.js 14 JSON/YAML fixture-driven tests
Total ~64

⚑ Performance Testing (k6)

Three profiles with automated SLA thresholds:

Profile VUs Duration p95 SLA Error Rate Use Case
Smoke 1 30s < 500ms 0% Sanity check
Load 10 60s < 1000ms < 5% Baseline capacity
Stress 1β†’50 3.5min < 2000ms < 10% Breaking point
npm run perf:smoke    # Quick sanity check
npm run perf:load     # Baseline measurement
npm run perf:stress   # Find the limits

Requires k6 installed locally.


πŸ“Š Reporting & Integrations

Allure Reports

npm test                     # Run tests (generates allure-results/)
npm run report:allure        # Generate + open HTML report

TestRail Sync

npm run push:testrail:dry    # Preview what would be synced
npm run push:testrail        # Push test cases to TestRail

πŸ€– AI-Powered Test Generation (Claude Code)

This framework includes custom Claude Code Skills to accelerate test development using AI. These skills allow you to generate production-ready test files from OpenAPI specs or declarative flow definitions.

Available Skills (Slash Commands)

Skill Command Purpose
Generate Tests /generate-tests Creates tests/generated/*.js from an OpenAPI spec or flows.yaml.
Enhance Tests /enhance-tests Adds business-rule coverage and negative scenarios to existing test files.
Generate Flows /generate-flows (Optional) Scaffolds flow definitions from project requirements or tickets.

Typical AI Workflow

  1. Define the Flow: Describe a multi-step user journey in api/flows.yaml.
  2. Generate Code: Run /generate-tests --flows api/flows.yaml.
  3. Refine: Run /enhance-tests tests/generated/new-feature.js to add edge cases.
  4. Verify: Run the generated Mocha tests normally.

[!TIP] These skills are optimized for this framework's helper patterns (helpers/request.js, helpers/assertions.js), ensuring that AI-generated code is indistinguishable from human-written code.


πŸ”„ CI/CD Pipeline

The GitHub Actions workflow implements a smoke-gated pipeline:

graph TD
    A[Push / PR] --> B[🚬 Smoke Tests]
    B -->|Pass| C[πŸ§ͺ Regression]
    B -->|Pass| D[πŸ”— Integration]
    B -->|Pass| E[πŸ“Š Data-Driven]
    C & D & E --> F[πŸ“Š Allure Report Upload]
    B -->|Fail| G[❌ Pipeline Stops]
Loading

If smoke tests fail, the entire pipeline stops β€” no wasted CI minutes on tests that can't possibly pass.


πŸ† Enterprise Patterns Demonstrated

Pattern Where Why It Matters
Token Caching helpers/auth.js Avoid 37+ redundant login calls per run
Centralized HTTP Wrapper helpers/request.js One change = all suites updated
Assertion Library helpers/assertions.js Consistent error validation across modules
Dynamic Data Factory helpers/data-factory.js Zero hardcoded data, true test isolation
Data-Driven Testing fixtures/*.json + tests/data-driven/ Scale to 100s of scenarios via config
YAML Flow Definitions api/*.yaml Declarative multi-step test workflows
Smoke-Gated CI .github/workflows/ Fast feedback, no wasted resources
Performance SLAs tests/performance/lib/thresholds.js Automated pass/fail for latency budgets
TestRail Integration scripts/push-to-testrail.js Automated test management sync

πŸ‘©β€πŸ’» Author

Vidhya Sasidharan β€” Senior QA Engineer | AI Quality Specialist

  • 🌍 Dubai, UAE
  • πŸ’Ό 10+ years in Quality Engineering
  • πŸ§ͺ 37+ enterprise API test suites managed
  • πŸ€– Pioneering AI-assisted QA workflows

LinkedIn


πŸ“„ License

MIT β€” Use this template as a foundation for your own API testing projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors