defprod-create-api-tests

Generates Vitest or Jest HTTP integration tests for API-surface user stories with one test per acceptance criterion.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/defprod1/defprod-skills --skill defprod-create-api-tests-defprod1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defprod-create-api-tests
Source: https://github.com/defprod1/defprod-skills/tree/main/skills/defprod-create-api-tests
Command: npx skills add https://github.com/defprod1/defprod-skills --skill defprod-create-api-tests-defprod1

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing integration tests that stay aligned with product definitions is tedious: acceptance criteria drift from test coverage, stories get bundled into monolithic tests that hide failures, and mixed-surface areas make it unclear which stories need HTTP tests. This Skill reads user stories and acceptance criteria from the DefProd MCP server and generates one spec file per API story with exactly one test per acceptance criterion. ## Core Features & Use Cases - Surface-aware story filtering: Selects stories whose surface is api, either set explicitly or inferred from the API-… story-key prefix, and skips UI, MCP, and CLI stories with a logged reason. - AC-per-test contract: Generates one test('ACn: ...') per testable acceptance criterion under a single describe block per story, documents untestable criteria in the file header, and retrofits existing bundled-AC specs. - Harness verification and reporting: Checks for Vitest/Jest config, an ApiClient helper, and a running backend before generating, then runs the suite, classifies failures as test faults or product faults, and produces a coverage summary table. - Use Case: After defining an API area in DefProd with stories like "create an API key", run the skill against your backend app to produce RPC integration tests asserting on the response envelope, then iterate until the suite is green. ## Quick Start Ask your agent to run /defprod-create-api-tests with your product name and area key to generate HTTP integration tests for all API stories in that area.

Frequently Asked Questions about defprod-create-api-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate API integration tests from user stories?

Invoke /defprod-create-api-tests with a product name and area key. The skill fetches stories and acceptance criteria from the DefProd MCP server, filters to api-surface stories, and writes one spec file per story with one test per acceptance criterion.

How do I write one test per acceptance criterion in Vitest?

Structure each spec with a single describe block named after the story and one test('ACn: ...') per testable criterion. Each test is self-contained, provisions its own fixtures via a fresh-user helper, and asserts only on that criterion's behavior.

Does this work with Jest as well as Vitest?

Yes, the skill supports both Vitest (preferred) and Jest. It checks the backend app's package.json devDependencies and config file, then generates specs importing from vitest or @jest/globals accordingly.

What happens to stories that are not API surface?

Stories with surface ui, mcp, or cli are skipped with a one-line log entry. The skill directs you to the matching sibling skill or the /defprod-create-area-tests dispatcher for those surfaces.

Why are some acceptance criteria not turned into tests?

Criteria that are not verifiable through RPC calls, such as documentation completeness or OpenAPI artifact presence, are classified as untestable. They are documented in the spec file header with a reason rather than silently skipped.

What prerequisites must exist before generating API tests?

The backend app must declare Vitest or Jest with a config file, an ApiClient helper with rpc methods and a fresh-user fixture must exist, and the dev backend must be running. The skill halts with instructions if any prerequisite is missing.