CLSkills
Testingintermediate

API Test Suite

Share

Generate API test suites for REST endpoints

API Test Suite

Generate API test suites for REST endpoints

Generate comprehensive API test suites for REST endpoints.

Instructions

  1. For each endpoint, test:

    • 200: happy path with valid data
    • 400: invalid request body / missing required fields
    • 401: missing or expired auth token
    • 403: valid auth but insufficient permissions
    • 404: resource not found
    • 409: conflict (duplicate resource)
    • 422: valid JSON but business rule violation
  2. Test template:

import request from 'supertest';
import { app } from '../app';

describe('POST /api/users', () => {
  it('201 - creates user with valid data', async () => {
    const res = await request(app)
      .post('/api/users')
      .set('Authorization', 'Bearer valid-token')
      .send({ name: 'Alice', email: 'alice@test.com' });

    expect(res.status).toBe(201);
    expect(res.body).toMatchObject({
      id: expect.any(Number),
      name: 'Alice',
      email: 'alice@test.com',
    });
  });

  it('400 - rejects missing email', async () => {
    const res = await request(app)
      .post('/api/users')
      .set('Authorization', 'Bearer valid-token')
      .send({ name: 'Alice' });

    expect(res.status).toBe(400);
    expect(res.body.error.message).toContain('email');
  });

  it('401 - rejects unauthenticated request', async () => {
    const res = await request(app)
      .post('/api/users')
      .send({ name: 'Alice', email: 'alice@test.com' });

    expect(res.status).toBe(401);
  });
});

Rules

  • Test response body shape, not just status codes
  • Test pagination headers/metadata for list endpoints
  • Use a test database that's reset between suites

Quick Info

CategoryTesting
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
testingapirest

Install command:

curl -o ~/.claude/skills/api-test-suite.md https://claude-skills-hub.vercel.app/skills/testing/api-test-suite.md