P
💻DeveloppementIntermediateChatGPT

Write Integration Tests for an API

Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Help me write integration tests for my REST API. Work from the framework, endpoints and test environment I specify below.

API framework: [e.g., Express, Fastify, NestJS or FastAPI]
Database: [e.g., PostgreSQL with Prisma or MongoDB with Mongoose]
Authentication: [e.g., a JWT bearer token, sessions or an API key]
Endpoints: [list the endpoints, e.g., POST /auth/login, GET /users/:id, POST /orders]

Test framework: [e.g., Jest with Supertest, Vitest or Mocha]
Test database: [e.g., a dedicated PostgreSQL database, in-memory SQLite or a mock]
CI service: [e.g., GitHub Actions or GitLab CI]

  1. Show the setup and teardown code. Configure the test database, seed fixtures and clean up between tests.
  2. Cover the authentication flow from login to token refresh, including invalid and expired tokens.
  3. Test create, read, update and delete operations across the endpoints. Assert successful responses, validation failures and HTTP error responses.
  4. Check that protected endpoints reject unauthenticated requests and that users can only perform the actions their permissions allow.
  5. Write one end-to-end user journey, such as signing up, logging in, creating a resource, editing it and deleting it.
  6. Add contract tests that compare the shape of each JSON response with the API documentation.
  7. Provide a GitHub Actions job that runs the suite with PostgreSQL as a service container.

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt addresses integration tests in their most difficult dimension: managing database state between tests. The setup/teardown and seeding strategy is the key to a deterministic test suite that doesn't produce false positives due to residual data from a previous test. Authorization tests are often overlooked in integration test suites, yet they constitute the most critical security layer: verifying that protected endpoints are inaccessible without a valid token, and that permissions are correctly applied (a user cannot modify another's data). Requesting contract tests (JSON structure validation) is an advanced practice that prevents silent breaking changes in APIs: if a field is renamed or removed, the test fails immediately, alerting the team before the change reaches API consumers.

Use Cases

REST API integration testingEndpoint security validationAutomated test pipeline

Expected Output

A complete integration test suite with setup/teardown, authentication tests, CRUD, authorization, and CI configuration.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

Task brief for Claude Code: frame a feature end to end

Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.

1678
💻DeveloppementIntermediateClaude

Write a project's CLAUDE.md: the brief Claude Code reads at every session

Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.

639
💻DeveloppementAdvancedAll AIs

Design a Secure Webhook API

Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.

411
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

473