← ClaudeAtlas

api-testinglisted

Use when writing API endpoint tests — integration tests, contract validation, response assertions, mocked external services — even when the user says 'test this route' without naming API testing.
event4u-app/agent-config · ★ 7 · Testing & QA · score 84
Install: claude install-skill event4u-app/agent-config
# api-testing ## When to use Use this skill when writing or reviewing API endpoint tests — integration tests, contract validation, response structure checks, or external service mocking. ## Procedure: Write API tests 1. **Understand the endpoint** — Read the controller, form request, and existing tests. Understand expected behavior, edge cases, and auth requirements before writing anything. 2. **Set up test data** — Use seeders (preferred) or factories. Mock external services with `Http::fake()`. 3. **Write test cases** — Cover success, validation errors, authorization failures, edge cases. 4. **Assert response** — Check status code, JSON structure, data values. Use `assertJsonStructure()`. 5. **Verify** — Run the test. Must pass. Check no flaky assertions (no time-dependent, no random ordering). ### Example ```php describe('GET /api/v1/projects', function () { it('returns paginated projects for authenticated user', function () { $user = loginAsTestUser(); $response = $this->getJson('/api/v1/projects'); $response->assertOk() ->assertJsonStructure([ 'data' => [['id', 'title', 'status']], 'meta' => ['current_page', 'per_page', 'total'], ]); }); it('returns 401 for unauthenticated request', function () { $this->getJson('/api/v1/projects') ->assertUnauthorized(); }); it('returns 403 when user lacks permission', function () { loginAsRestrictedUs