Integration Tests for an API Route

Cover the success path, validation, auth failures, 404s, and side effects of one endpoint.

Intermediate1 min read

Customize

Fill these in and the prompt below updates as you type. Anything you leave blank stays as a placeholder.

Your prompt

3 placeholders left
Write integration tests for this {{framework}} route using {{test_stack}}.

Test:
- Successful response (correct status code and response shape)
- Validation errors (missing or invalid fields)
- Authentication/authorization failures
- Resource not found
- Any side effects (e.g. email sent, DB record created)

Mock the database and any external services. Use beforeEach/afterEach for setup and teardown.

Route handler:
{{code}}

Similar prompts

Design a REST API

Endpoint-by-endpoint design including the error responses most API specs forget.

Fix a Bug Without Breaking Things

Find every affected code path and the same bug elsewhere before landing the minimal fix.

Function From Requirements

A typed, documented function built to spec — with three unit tests covering the edge and error cases.

Generate Test Fixtures

Happy path, boundary values, and a deliberate failure case — each with a note on what it covers.