GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - deefex/api-automation-demo: An API automation demo using TypeScript, Vitest, Axios, Zod and Nock

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
tests
tests
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
vitest.config.ts
vitest.config.ts
 
 
vitest.live.config.ts
vitest.live.config.ts
 
 

Repository files navigation

API Automation Demo (TypeScript + Swagger Petstore)

CI

A demo of API automation

What this demonstrates

  • API methods: GET, POST, and DELETE (cleanup)
  • Request complexity: path params and nested JSON request bodies
  • Response complexity: nested objects + arrays
  • Advanced verification:
    • Typed schema validation using zod (deserialization-style checks)
    • Full-response snapshot verification (approval testing style)
  • Builder pattern for reusable and maintainable test data setup
  • Negative-path checks for invalid payloads and missing resources
  • Mocking strategy using nock for deterministic API tests

Tech stack

  • TypeScript
  • Vitest
  • Axios
  • Zod
  • Nock

The architecture jigsaw

This is a conceptual view of how everything hangs together

flowchart LR
    A["Vitest (test runner)"] --> B["Test Files<br/>mock + live"]
    B --> C["PetstoreClient"]
    C --> D["Axios (HTTP client)"]
    C --> E["Zod (request/response validation)"]

    subgraph Mocked Path
      B --> M["Nock intercepts HTTP"]
      M --> D
      D --> N["No real network call"]
    end

    subgraph Live Path
      D --> P["Swagger Petstore API"]
    end

    E --> Q["Typed, validated data<br/>for assertions"]
    A --> R["Assertions + snapshots + reports"]
    Q --> R
Loading
  • Vitest runs the suite and performs assertions/snapshot checks.
  • PetstoreClient is the thin abstraction your tests call.
  • Axios performs HTTP requests.
  • Zod validates request and response payloads at runtime while keeping TypeScript types aligned.
  • Nock is used only for mock tests to intercept HTTP and avoid external dependencies.

Project structure

src/
  client/
    petstoreClient.ts
  config/
    env.ts
  models/
    pet.ts
tests/
  builders/
    petBuilder.ts
  live/
    petstore.live.test.ts
    setup.ts
  mock/
    petstore.mock.test.ts
    setup.ts
.github/workflows/
  ci.yml

Quick start

  1. Install dependencies
npm install
  1. Run deterministic mocked tests (recommended default)
npm run test:mock
  1. Run live Petstore tests
npm run test:live

Environment

Copy .env.example to .env if you want to override the default API base URL.

PETSTORE_BASE_URL=https://petstore.swagger.io/v2

Notes

  • npm run test:mock runs only mock tests to keep CI stable and fast.
  • Live tests are intentionally separate because public API data/state can be unstable.

About

An API automation demo using TypeScript, Vitest, Axios, Zod and Nock

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.