Skip to content

Commit 9336d40

Browse files
muratkeremozcanforcetrainer
authored andcommitted
docs: expand TEA documentation with cheat sheets, MCP enhancements, a… (bmad-code-org#1289)
* docs: expand TEA documentation with cheat sheets, MCP enhancements, and API testing patterns * docs: update TEA fragment counts and fix playwright-utils code examples * docs: addressed PR review concerns * docs: update TEA MCP configuration link to point to documentation site
1 parent 46c54c0 commit 9336d40

File tree

14 files changed

+2821
-354
lines changed

14 files changed

+2821
-354
lines changed

docs/explanation/features/tea-overview.md

Lines changed: 285 additions & 10 deletions
Large diffs are not rendered by default.

src/modules/bmm/agents/tea.agent.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ agent:
1212

1313
persona:
1414
role: Master Test Architect
15-
identity: Test architect specializing in CI/CD, automated frameworks, and scalable quality gates.
15+
identity: Test architect specializing in API testing, backend services, UI automation, CI/CD pipelines, and scalable quality gates. Equally proficient in pure API/service-layer testing as in browser-based E2E testing.
1616
communication_style: "Blends data with gut instinct. 'Strong opinions, weakly held' is their mantra. Speaks in risk calculations and impact assessments."
1717
principles: |
1818
- Risk-based testing - depth scales with impact
1919
- Quality gates backed by data
20-
- Tests mirror usage patterns
20+
- Tests mirror usage patterns (API, UI, or both)
2121
- Flakiness is critical technical debt
2222
- Tests first AI implements suite validates
2323
- Calculate risk vs value for every testing decision
24+
- Prefer lower test levels (unit > integration > E2E) when possible
25+
- API tests are first-class citizens, not just UI support
2426
2527
critical_actions:
2628
- "Consult {project-root}/_bmad/bmm/testarch/tea-index.csv to select knowledge fragments under knowledge/ and load only the files needed for the current task"
@@ -39,7 +41,7 @@ agent:
3941

4042
- trigger: AT or fuzzy match on atdd
4143
workflow: "{project-root}/_bmad/bmm/workflows/testarch/atdd/workflow.yaml"
42-
description: "[AT] Generate E2E tests first, before starting implementation"
44+
description: "[AT] Generate API and/or E2E tests first, before starting implementation"
4345

4446
- trigger: TA or fuzzy match on test-automate
4547
workflow: "{project-root}/_bmad/bmm/workflows/testarch/automate/workflow.yaml"

src/modules/bmm/module.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ project_knowledge: # Artifacts from research, document-project output, other lon
4545
result: "{project-root}/{value}"
4646

4747
tea_use_mcp_enhancements:
48-
prompt: "Test Architect Playwright MCP capabilities (healing, exploratory, verification) are optionally available.\nYou will have to setup your MCPs yourself; refer to test-architecture.md for hints.\nWould you like to enable MCP enhancements in Test Architect?"
48+
prompt: "Test Architect Playwright MCP capabilities (healing, exploratory, verification) are optionally available.\nYou will have to setup your MCPs yourself; refer to https://docs.bmad-method.org/explanation/features/tea-overview for configuration examples.\nWould you like to enable MCP enhancements in Test Architect?"
4949
default: false
5050
result: "{value}"
5151

src/modules/bmm/testarch/knowledge/api-request.md

Lines changed: 155 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Principle
44

5-
Use typed HTTP client with built-in schema validation and automatic retry for server errors. The utility handles URL resolution, header management, response parsing, and single-line response validation with proper TypeScript support.
5+
Use typed HTTP client with built-in schema validation and automatic retry for server errors. The utility handles URL resolution, header management, response parsing, and single-line response validation with proper TypeScript support. **Works without a browser** - ideal for pure API/service testing.
66

77
## Rationale
88

@@ -21,6 +21,7 @@ The `apiRequest` utility provides:
2121
- **Schema validation**: Single-line validation (JSON Schema, Zod, OpenAPI)
2222
- **URL resolution**: Four-tier strategy (explicit > config > Playwright > direct)
2323
- **TypeScript generics**: Type-safe response bodies
24+
- **No browser required**: Pure API testing without browser overhead
2425

2526
## Pattern Examples
2627

@@ -60,10 +61,11 @@ test('should fetch user data', async ({ apiRequest }) => {
6061

6162
```typescript
6263
import { test } from '@seontechnologies/playwright-utils/api-request/fixtures';
64+
import { z } from 'zod';
6365

64-
test('should validate response schema', async ({ apiRequest }) => {
65-
// JSON Schema validation
66-
const response = await apiRequest({
66+
// JSON Schema validation
67+
test('should validate response schema (JSON Schema)', async ({ apiRequest }) => {
68+
const { status, body } = await apiRequest({
6769
method: 'GET',
6870
path: '/api/users/123',
6971
validateSchema: {
@@ -77,22 +79,25 @@ test('should validate response schema', async ({ apiRequest }) => {
7779
},
7880
});
7981
// Throws if schema validation fails
82+
expect(status).toBe(200);
83+
});
8084

81-
// Zod schema validation
82-
import { z } from 'zod';
83-
84-
const UserSchema = z.object({
85-
id: z.string(),
86-
name: z.string(),
87-
email: z.string().email(),
88-
});
85+
// Zod schema validation
86+
const UserSchema = z.object({
87+
id: z.string(),
88+
name: z.string(),
89+
email: z.string().email(),
90+
});
8991

90-
const response = await apiRequest({
92+
test('should validate response schema (Zod)', async ({ apiRequest }) => {
93+
const { status, body } = await apiRequest({
9194
method: 'GET',
9295
path: '/api/users/123',
9396
validateSchema: UserSchema,
9497
});
9598
// Response body is type-safe AND validated
99+
expect(status).toBe(200);
100+
expect(body.email).toContain('@');
96101
});
97102
```
98103

@@ -236,6 +241,136 @@ test('should poll until job completes', async ({ apiRequest, recurse }) => {
236241
- `recurse` polls until predicate returns true
237242
- Composable utilities work together seamlessly
238243

244+
### Example 6: Microservice Testing (Multiple Services)
245+
246+
**Context**: Test interactions between microservices without a browser.
247+
248+
**Implementation**:
249+
250+
```typescript
251+
import { test, expect } from '@seontechnologies/playwright-utils/fixtures';
252+
253+
const USER_SERVICE = process.env.USER_SERVICE_URL || 'http://localhost:3001';
254+
const ORDER_SERVICE = process.env.ORDER_SERVICE_URL || 'http://localhost:3002';
255+
256+
test.describe('Microservice Integration', () => {
257+
test('should validate cross-service user lookup', async ({ apiRequest }) => {
258+
// Create user in user-service
259+
const { body: user } = await apiRequest({
260+
method: 'POST',
261+
path: '/api/users',
262+
baseUrl: USER_SERVICE,
263+
body: { name: 'Test User', email: '[email protected]' },
264+
});
265+
266+
// Create order in order-service (validates user via user-service)
267+
const { status, body: order } = await apiRequest({
268+
method: 'POST',
269+
path: '/api/orders',
270+
baseUrl: ORDER_SERVICE,
271+
body: {
272+
userId: user.id,
273+
items: [{ productId: 'prod-1', quantity: 2 }],
274+
},
275+
});
276+
277+
expect(status).toBe(201);
278+
expect(order.userId).toBe(user.id);
279+
});
280+
281+
test('should reject order for invalid user', async ({ apiRequest }) => {
282+
const { status, body } = await apiRequest({
283+
method: 'POST',
284+
path: '/api/orders',
285+
baseUrl: ORDER_SERVICE,
286+
body: {
287+
userId: 'non-existent-user',
288+
items: [{ productId: 'prod-1', quantity: 1 }],
289+
},
290+
});
291+
292+
expect(status).toBe(400);
293+
expect(body.code).toBe('INVALID_USER');
294+
});
295+
});
296+
```
297+
298+
**Key Points**:
299+
300+
- Test multiple services without browser
301+
- Use `baseUrl` to target different services
302+
- Validate cross-service communication
303+
- Pure API testing - fast and reliable
304+
305+
### Example 7: GraphQL API Testing
306+
307+
**Context**: Test GraphQL endpoints with queries and mutations.
308+
309+
**Implementation**:
310+
311+
```typescript
312+
test.describe('GraphQL API', () => {
313+
const GRAPHQL_ENDPOINT = '/graphql';
314+
315+
test('should query users via GraphQL', async ({ apiRequest }) => {
316+
const query = `
317+
query GetUsers($limit: Int) {
318+
users(limit: $limit) {
319+
id
320+
name
321+
email
322+
}
323+
}
324+
`;
325+
326+
const { status, body } = await apiRequest({
327+
method: 'POST',
328+
path: GRAPHQL_ENDPOINT,
329+
body: {
330+
query,
331+
variables: { limit: 10 },
332+
},
333+
});
334+
335+
expect(status).toBe(200);
336+
expect(body.errors).toBeUndefined();
337+
expect(body.data.users).toHaveLength(10);
338+
});
339+
340+
test('should create user via mutation', async ({ apiRequest }) => {
341+
const mutation = `
342+
mutation CreateUser($input: CreateUserInput!) {
343+
createUser(input: $input) {
344+
id
345+
name
346+
}
347+
}
348+
`;
349+
350+
const { status, body } = await apiRequest({
351+
method: 'POST',
352+
path: GRAPHQL_ENDPOINT,
353+
body: {
354+
query: mutation,
355+
variables: {
356+
input: { name: 'GraphQL User', email: '[email protected]' },
357+
},
358+
},
359+
});
360+
361+
expect(status).toBe(200);
362+
expect(body.data.createUser.id).toBeDefined();
363+
});
364+
});
365+
```
366+
367+
**Key Points**:
368+
369+
- GraphQL via POST request
370+
- Variables in request body
371+
- Check `body.errors` for GraphQL errors (not status code)
372+
- Works for queries and mutations
373+
239374
## Comparison with Vanilla Playwright
240375

241376
| Vanilla Playwright | playwright-utils apiRequest |
@@ -251,11 +386,13 @@ test('should poll until job completes', async ({ apiRequest, recurse }) => {
251386

252387
**Use apiRequest for:**
253388

254-
- ✅ API endpoint testing
255-
- ✅ Background API calls in UI tests
389+
- ✅ Pure API/service testing (no browser needed)
390+
- ✅ Microservice integration testing
391+
- ✅ GraphQL API testing
256392
- ✅ Schema validation needs
257393
- ✅ Tests requiring retry logic
258-
- ✅ Typed API responses
394+
- ✅ Background API calls in UI tests
395+
- ✅ Contract testing support
259396

260397
**Stick with vanilla Playwright for:**
261398

@@ -265,11 +402,13 @@ test('should poll until job completes', async ({ apiRequest, recurse }) => {
265402

266403
## Related Fragments
267404

405+
- `api-testing-patterns.md` - Comprehensive pure API testing patterns
268406
- `overview.md` - Installation and design principles
269407
- `auth-session.md` - Authentication token management
270408
- `recurse.md` - Polling for async operations
271409
- `fixtures-composition.md` - Combining utilities with mergeTests
272410
- `log.md` - Logging API requests
411+
- `contract-testing.md` - Pact contract testing
273412

274413
## Anti-Patterns
275414

0 commit comments

Comments
 (0)