@democratize-quality/mcp-server 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +891 -420
- package/package.json +3 -1
- package/src/chatmodes//360/237/214/220 api-generator.chatmode.md" +337 -318
- package/src/chatmodes//360/237/214/220 api-planner.chatmode.md" +760 -237
- package/src/tools/api/api-generator.js +841 -112
- package/src/tools/api/api-planner.js +690 -25
- package/src/tools/api/api-project-setup.js +313 -0
- package/src/tools/api/prompts/README.md +293 -0
- package/src/tools/api/prompts/generation-prompts.js +599 -0
- package/src/tools/api/prompts/healing-prompts.js +143 -0
- package/src/tools/api/prompts/index.js +25 -0
- package/src/tools/api/prompts/orchestrator.js +333 -0
- package/src/tools/api/prompts/validation-rules.js +251 -0
- package/src/utils/agentInstaller.js +0 -1
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Generation Prompts for API Test Generator
|
|
3
|
+
*
|
|
4
|
+
* This module contains all prompts used for AI-based test code generation.
|
|
5
|
+
* Separated for easy iteration, versioning, and prompt engineering.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
/**
|
|
10
|
+
* Playwright test generation prompts
|
|
11
|
+
*/
|
|
12
|
+
playwright: {
|
|
13
|
+
system: `You are an expert Playwright test engineer. Generate clean, idiomatic, production-ready Playwright API tests.
|
|
14
|
+
|
|
15
|
+
CRITICAL - File Generation Rules:
|
|
16
|
+
- Generate ONLY the ONE requested test file
|
|
17
|
+
- DO NOT create any additional files (README, SUMMARY, GUIDE, NOTES, etc.)
|
|
18
|
+
- DO NOT create documentation files unless explicitly requested
|
|
19
|
+
- DO NOT create helper files unless explicitly requested
|
|
20
|
+
- Output ONLY the test code for the specified file
|
|
21
|
+
|
|
22
|
+
Requirements:
|
|
23
|
+
- Use Playwright's request fixture directly (no wrappers)
|
|
24
|
+
- Use proper TypeScript types when language=typescript
|
|
25
|
+
- Include proper async/await patterns
|
|
26
|
+
- Use template literals for URL construction with \${baseUrl}
|
|
27
|
+
- Generate proper assertions with expect()
|
|
28
|
+
- Handle both single and chained requests
|
|
29
|
+
- Include proper error handling
|
|
30
|
+
- Add descriptive comments for complex logic
|
|
31
|
+
|
|
32
|
+
Code Style:
|
|
33
|
+
- 2-space indentation
|
|
34
|
+
- Single quotes for strings (except template literals)
|
|
35
|
+
- Semicolons at end of statements
|
|
36
|
+
- Clear variable naming
|
|
37
|
+
- Proper spacing and formatting`,
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generate a section test file with multiple scenarios
|
|
41
|
+
*/
|
|
42
|
+
generateTest: (context) => {
|
|
43
|
+
const { testPlanTitle, baseUrl, sectionTitle, scenarios, language, isTypeScript, sessionId } = context;
|
|
44
|
+
|
|
45
|
+
let prompt = `Generate a complete Playwright test file for this section:
|
|
46
|
+
|
|
47
|
+
**Test Plan:** ${testPlanTitle}
|
|
48
|
+
**Section:** ${sectionTitle}
|
|
49
|
+
**Base URL:** ${baseUrl}
|
|
50
|
+
**Language:** ${language}
|
|
51
|
+
**Session ID:** ${sessionId}
|
|
52
|
+
|
|
53
|
+
**Scenarios to test:**
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
scenarios.forEach((scenario, idx) => {
|
|
57
|
+
prompt += `
|
|
58
|
+
${idx + 1}. **${scenario.title}**
|
|
59
|
+
- Method: ${scenario.method}
|
|
60
|
+
- Endpoint: ${scenario.endpoint}
|
|
61
|
+
- Expected Status: ${scenario.expectedStatus || 200}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
if (scenario.requestBody) {
|
|
65
|
+
prompt += ` - Request Body: ${JSON.stringify(scenario.requestBody, null, 2).substring(0, 200)}...
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (scenario.expectedBody) {
|
|
70
|
+
prompt += ` - Expected Body Fields: ${Object.keys(scenario.expectedBody).join(', ')}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (scenario.steps && scenario.steps.length > 0) {
|
|
75
|
+
prompt += ` - Multi-step test with ${scenario.steps.length} sequential requests
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
prompt += `
|
|
81
|
+
**Instructions:**
|
|
82
|
+
1. Generate a COMPLETE test file including imports and test structure
|
|
83
|
+
2. ${isTypeScript ? 'Use TypeScript with proper types' : 'Use JavaScript'}
|
|
84
|
+
3. Import from '@playwright/test' for Playwright
|
|
85
|
+
4. Create test.describe() for the section: "${sectionTitle}"
|
|
86
|
+
5. Create one test() for each scenario above
|
|
87
|
+
6. Use \`const baseUrl = '${baseUrl}';\` at the top of describe block
|
|
88
|
+
7. Use Playwright's \`request\` fixture directly (no helper classes)
|
|
89
|
+
8. Construct URLs as template literals: \`\${baseUrl}/endpoint\`
|
|
90
|
+
9. Include proper assertions for status codes and response body structure
|
|
91
|
+
10. For multi-step tests, chain requests and pass data between steps
|
|
92
|
+
11. Add error handling where appropriate
|
|
93
|
+
12. Include comments for complex logic
|
|
94
|
+
|
|
95
|
+
**CRITICAL - Output Restrictions:**
|
|
96
|
+
- Generate ONLY this ONE test file: ${sectionTitle}
|
|
97
|
+
- DO NOT generate README, SUMMARY, GUIDE, or any other files
|
|
98
|
+
- DO NOT suggest creating additional files
|
|
99
|
+
- DO NOT include file creation instructions
|
|
100
|
+
- Return ONLY the test file code as plain text
|
|
101
|
+
|
|
102
|
+
**File structure:**
|
|
103
|
+
\`\`\`
|
|
104
|
+
// Header comment
|
|
105
|
+
import/require statements
|
|
106
|
+
test.describe('${sectionTitle}', () => {
|
|
107
|
+
const baseUrl = '${baseUrl}';
|
|
108
|
+
|
|
109
|
+
test('scenario 1', async ({ request }) => {
|
|
110
|
+
// test code
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('scenario 2', async ({ request }) => {
|
|
114
|
+
// test code
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
\`\`\`
|
|
118
|
+
|
|
119
|
+
Return the COMPLETE file content for THIS FILE ONLY.`;
|
|
120
|
+
|
|
121
|
+
return prompt;
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Generate main test file that runs all sections
|
|
126
|
+
*/
|
|
127
|
+
generateMainTest: (context) => {
|
|
128
|
+
const { testPlanTitle, baseUrl, sections, language, isTypeScript, sessionId } = context;
|
|
129
|
+
|
|
130
|
+
let prompt = `Generate a main Playwright test file that orchestrates all test sections:
|
|
131
|
+
|
|
132
|
+
**Test Plan:** ${testPlanTitle}
|
|
133
|
+
**Base URL:** ${baseUrl}
|
|
134
|
+
**Language:** ${language}
|
|
135
|
+
**Session ID:** ${sessionId}
|
|
136
|
+
|
|
137
|
+
**Sections:**
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
sections.forEach((section, idx) => {
|
|
141
|
+
prompt += `${idx + 1}. ${section.title} (${section.scenarioCount} scenarios)
|
|
142
|
+
`;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
prompt += `
|
|
146
|
+
**Instructions:**
|
|
147
|
+
1. Generate a COMPLETE main test file
|
|
148
|
+
2. ${isTypeScript ? 'Use TypeScript' : 'Use JavaScript'}
|
|
149
|
+
3. Import from '@playwright/test'
|
|
150
|
+
4. Create one main test.describe() for "${testPlanTitle}"
|
|
151
|
+
5. Set \`const baseUrl = '${baseUrl}';\`
|
|
152
|
+
6. Import or reference individual section test files
|
|
153
|
+
7. Keep it simple - this is just an orchestration file
|
|
154
|
+
8. Add a comment noting individual sections are in separate files
|
|
155
|
+
|
|
156
|
+
**CRITICAL - Output Restrictions:**
|
|
157
|
+
- Generate ONLY this ONE main test file
|
|
158
|
+
- DO NOT generate README, SUMMARY, GUIDE, or any other files
|
|
159
|
+
- DO NOT create section files (they're generated separately)
|
|
160
|
+
- Return ONLY the main test file code
|
|
161
|
+
|
|
162
|
+
Return the COMPLETE main file content for THIS FILE ONLY.`;
|
|
163
|
+
|
|
164
|
+
return prompt;
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Jest test generation prompts
|
|
170
|
+
*/
|
|
171
|
+
jest: {
|
|
172
|
+
system: `You are an expert Jest test engineer. Generate clean, idiomatic, production-ready Jest API tests using axios.
|
|
173
|
+
|
|
174
|
+
CRITICAL - File Generation Rules:
|
|
175
|
+
- Generate ONLY the ONE requested test file
|
|
176
|
+
- DO NOT create any additional files (README, SUMMARY, GUIDE, NOTES, etc.)
|
|
177
|
+
- DO NOT create documentation files unless explicitly requested
|
|
178
|
+
- Output ONLY the test code for the specified file
|
|
179
|
+
|
|
180
|
+
Requirements:
|
|
181
|
+
- Use axios for API calls
|
|
182
|
+
- Use proper TypeScript types when language=typescript
|
|
183
|
+
- Include proper async/await patterns
|
|
184
|
+
- Generate proper assertions with expect()
|
|
185
|
+
- Handle both single and chained requests
|
|
186
|
+
- Include proper error handling
|
|
187
|
+
|
|
188
|
+
Code Style:
|
|
189
|
+
- 2-space indentation
|
|
190
|
+
- Single quotes for strings (except template literals)
|
|
191
|
+
- Semicolons at end of statements
|
|
192
|
+
- Clear variable naming`,
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Generate a section test file with multiple scenarios
|
|
196
|
+
*/
|
|
197
|
+
generateTest: (context) => {
|
|
198
|
+
const { testPlanTitle, baseUrl, sectionTitle, scenarios, language, isTypeScript, sessionId } = context;
|
|
199
|
+
|
|
200
|
+
let prompt = `Generate a complete Jest test file for this section:
|
|
201
|
+
|
|
202
|
+
**Test Plan:** ${testPlanTitle}
|
|
203
|
+
**Section:** ${sectionTitle}
|
|
204
|
+
**Base URL:** ${baseUrl}
|
|
205
|
+
**Language:** ${language}
|
|
206
|
+
**Session ID:** ${sessionId}
|
|
207
|
+
|
|
208
|
+
**Scenarios to test:**
|
|
209
|
+
`;
|
|
210
|
+
|
|
211
|
+
scenarios.forEach((scenario, idx) => {
|
|
212
|
+
prompt += `
|
|
213
|
+
${idx + 1}. **${scenario.title}**
|
|
214
|
+
- Method: ${scenario.method}
|
|
215
|
+
- Endpoint: ${scenario.endpoint}
|
|
216
|
+
- Expected Status: ${scenario.expectedStatus || 200}
|
|
217
|
+
`;
|
|
218
|
+
|
|
219
|
+
if (scenario.requestBody) {
|
|
220
|
+
prompt += ` - Request Body: ${JSON.stringify(scenario.requestBody, null, 2).substring(0, 200)}...
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (scenario.expectedBody) {
|
|
225
|
+
prompt += ` - Expected Body Fields: ${Object.keys(scenario.expectedBody).join(', ')}
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (scenario.steps && scenario.steps.length > 0) {
|
|
230
|
+
prompt += ` - Multi-step test with ${scenario.steps.length} sequential requests
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
prompt += `
|
|
236
|
+
**Instructions:**
|
|
237
|
+
1. Generate a COMPLETE test file including imports and test structure
|
|
238
|
+
2. ${isTypeScript ? 'Use TypeScript with proper types' : 'Use JavaScript'}
|
|
239
|
+
3. Import axios for HTTP requests
|
|
240
|
+
4. Create describe() for the section: "${sectionTitle}"
|
|
241
|
+
5. Create one test() for each scenario above
|
|
242
|
+
6. Use \`const baseUrl = '${baseUrl}';\` at the top
|
|
243
|
+
7. Use axios methods (axios.get, axios.post, etc.)
|
|
244
|
+
8. Construct URLs as template literals: \`\${baseUrl}/endpoint\`
|
|
245
|
+
9. Include proper assertions with Jest's expect()
|
|
246
|
+
10. For multi-step tests, chain requests and pass data between steps
|
|
247
|
+
11. Add error handling where appropriate
|
|
248
|
+
|
|
249
|
+
**CRITICAL - Output Restrictions:**
|
|
250
|
+
- Generate ONLY this ONE test file
|
|
251
|
+
- DO NOT generate README, SUMMARY, GUIDE, or any other files
|
|
252
|
+
- DO NOT suggest creating additional files
|
|
253
|
+
- Return ONLY the test file code as plain text
|
|
254
|
+
|
|
255
|
+
**File structure:**
|
|
256
|
+
\`\`\`
|
|
257
|
+
// Header comment
|
|
258
|
+
import/require statements
|
|
259
|
+
describe('${sectionTitle}', () => {
|
|
260
|
+
const baseUrl = '${baseUrl}';
|
|
261
|
+
|
|
262
|
+
test('scenario 1', async () => {
|
|
263
|
+
// test code
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('scenario 2', async () => {
|
|
267
|
+
// test code
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
\`\`\`
|
|
271
|
+
|
|
272
|
+
Return the COMPLETE file content for THIS FILE ONLY.`;
|
|
273
|
+
|
|
274
|
+
return prompt;
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Generate main test file
|
|
279
|
+
*/
|
|
280
|
+
generateMainTest: (context) => {
|
|
281
|
+
const { testPlanTitle, baseUrl, sections, language, isTypeScript, sessionId } = context;
|
|
282
|
+
|
|
283
|
+
let prompt = `Generate a main Jest test file that orchestrates all test sections:
|
|
284
|
+
|
|
285
|
+
**Test Plan:** ${testPlanTitle}
|
|
286
|
+
**Base URL:** ${baseUrl}
|
|
287
|
+
**Language:** ${language}
|
|
288
|
+
**Session ID:** ${sessionId}
|
|
289
|
+
|
|
290
|
+
**Sections:**
|
|
291
|
+
`;
|
|
292
|
+
|
|
293
|
+
sections.forEach((section, idx) => {
|
|
294
|
+
prompt += `${idx + 1}. ${section.title} (${section.scenarioCount} scenarios)
|
|
295
|
+
`;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
prompt += `
|
|
299
|
+
**Instructions:**
|
|
300
|
+
1. Generate a COMPLETE main test file
|
|
301
|
+
2. ${isTypeScript ? 'Use TypeScript' : 'Use JavaScript'}
|
|
302
|
+
3. Import axios
|
|
303
|
+
4. Create one main describe() for "${testPlanTitle}"
|
|
304
|
+
5. Set \`const baseUrl = '${baseUrl}';\`
|
|
305
|
+
6. Add a comment noting individual sections are in separate files
|
|
306
|
+
|
|
307
|
+
**CRITICAL - Output Restrictions:**
|
|
308
|
+
- Generate ONLY this ONE main test file
|
|
309
|
+
- DO NOT generate README, SUMMARY, GUIDE, or any other files
|
|
310
|
+
- Return ONLY the main test file code
|
|
311
|
+
|
|
312
|
+
Return the COMPLETE main file content for THIS FILE ONLY.`;
|
|
313
|
+
|
|
314
|
+
return prompt;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Legacy scenario-level prompts (kept for backward compatibility)
|
|
320
|
+
*/
|
|
321
|
+
playwrightScenario: {
|
|
322
|
+
system: `You are an expert Playwright test engineer. Generate clean, idiomatic, production-ready Playwright API tests.
|
|
323
|
+
|
|
324
|
+
Requirements:
|
|
325
|
+
- Use Playwright's request fixture directly (no wrappers)
|
|
326
|
+
- Use proper TypeScript types when language=typescript
|
|
327
|
+
- Include proper async/await patterns
|
|
328
|
+
- Use template literals for URL construction with \${baseUrl}
|
|
329
|
+
- Generate proper assertions with expect()
|
|
330
|
+
- Handle both single and chained requests
|
|
331
|
+
- Include proper error handling
|
|
332
|
+
- Add descriptive comments for complex logic
|
|
333
|
+
|
|
334
|
+
Code Style:
|
|
335
|
+
- 2-space indentation
|
|
336
|
+
- Single quotes for strings (except template literals)
|
|
337
|
+
- Semicolons at end of statements
|
|
338
|
+
- Clear variable naming
|
|
339
|
+
- Proper spacing and formatting`,
|
|
340
|
+
|
|
341
|
+
user: (context) => {
|
|
342
|
+
const { scenario, baseUrl, language, options } = context;
|
|
343
|
+
|
|
344
|
+
let prompt = `Generate a Playwright test for this scenario:
|
|
345
|
+
|
|
346
|
+
**Test Details:**
|
|
347
|
+
- Title: "${scenario.title}"
|
|
348
|
+
- Method: ${scenario.method}
|
|
349
|
+
- Endpoint: ${scenario.endpoint}
|
|
350
|
+
- Base URL: ${baseUrl}
|
|
351
|
+
- Language: ${language}
|
|
352
|
+
|
|
353
|
+
`;
|
|
354
|
+
|
|
355
|
+
// Add request details
|
|
356
|
+
if (scenario.data && Object.keys(scenario.data).length > 0) {
|
|
357
|
+
prompt += `**Request Body:**
|
|
358
|
+
\`\`\`json
|
|
359
|
+
${JSON.stringify(scenario.data, null, 2)}
|
|
360
|
+
\`\`\`
|
|
361
|
+
|
|
362
|
+
`;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (scenario.headers && Object.keys(scenario.headers).length > 0) {
|
|
366
|
+
prompt += `**Headers:**
|
|
367
|
+
\`\`\`json
|
|
368
|
+
${JSON.stringify(scenario.headers, null, 2)}
|
|
369
|
+
\`\`\`
|
|
370
|
+
|
|
371
|
+
`;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (scenario.query && Object.keys(scenario.query).length > 0) {
|
|
375
|
+
prompt += `**Query Parameters:**
|
|
376
|
+
\`\`\`json
|
|
377
|
+
${JSON.stringify(scenario.query, null, 2)}
|
|
378
|
+
\`\`\`
|
|
379
|
+
|
|
380
|
+
`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (scenario.pathParams && Object.keys(scenario.pathParams).length > 0) {
|
|
384
|
+
prompt += `**Path Parameters:**
|
|
385
|
+
\`\`\`json
|
|
386
|
+
${JSON.stringify(scenario.pathParams, null, 2)}
|
|
387
|
+
\`\`\`
|
|
388
|
+
|
|
389
|
+
`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Add expectations
|
|
393
|
+
if (scenario.expect) {
|
|
394
|
+
prompt += `**Expected Response:**
|
|
395
|
+
- Status Code: ${scenario.expect.status || 200}
|
|
396
|
+
`;
|
|
397
|
+
if (scenario.expect.body) {
|
|
398
|
+
prompt += `- Response Body Structure:
|
|
399
|
+
\`\`\`json
|
|
400
|
+
${JSON.stringify(scenario.expect.body, null, 2)}
|
|
401
|
+
\`\`\`
|
|
402
|
+
`;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Add chained requests if present
|
|
407
|
+
if (scenario.chain && scenario.chain.length > 0) {
|
|
408
|
+
prompt += `\n**Chained Requests:**
|
|
409
|
+
This is a multi-step test with ${scenario.chain.length} sequential API calls.
|
|
410
|
+
`;
|
|
411
|
+
scenario.chain.forEach((step, index) => {
|
|
412
|
+
prompt += `
|
|
413
|
+
Step ${index + 1}: ${step.name}
|
|
414
|
+
- Method: ${step.method}
|
|
415
|
+
- Endpoint: ${step.endpoint}
|
|
416
|
+
`;
|
|
417
|
+
if (step.extract) {
|
|
418
|
+
prompt += `- Extract: ${JSON.stringify(step.extract)}
|
|
419
|
+
`;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
prompt += `
|
|
425
|
+
**Instructions:**
|
|
426
|
+
1. Generate ONLY the test body code (the code inside the test() function)
|
|
427
|
+
2. Start at the correct indentation level (6 spaces for test body)
|
|
428
|
+
3. Use \`await request.${scenario.method.toLowerCase()}()\` for the API call
|
|
429
|
+
4. Construct URL as: \`\${baseUrl}${scenario.endpoint}\`
|
|
430
|
+
5. Include all request options (headers, params, data)
|
|
431
|
+
6. Add proper assertions for status code and response body
|
|
432
|
+
7. For TypeScript, use proper types
|
|
433
|
+
8. For chained requests, store results and use them in subsequent calls
|
|
434
|
+
|
|
435
|
+
DO NOT include:
|
|
436
|
+
- test.describe() wrapper
|
|
437
|
+
- test() function declaration
|
|
438
|
+
- import statements
|
|
439
|
+
- Extra blank lines at start/end
|
|
440
|
+
|
|
441
|
+
Return ONLY the test body code, properly indented.`;
|
|
442
|
+
|
|
443
|
+
return prompt;
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Generate a complete Jest test for a single scenario
|
|
449
|
+
*/
|
|
450
|
+
jestScenario: {
|
|
451
|
+
system: `You are an expert Jest test engineer. Generate clean, idiomatic, production-ready Jest API tests using axios.
|
|
452
|
+
|
|
453
|
+
Requirements:
|
|
454
|
+
- Use axios for API calls
|
|
455
|
+
- Use proper TypeScript types when language=typescript
|
|
456
|
+
- Include proper async/await patterns
|
|
457
|
+
- Generate proper assertions with expect()
|
|
458
|
+
- Handle both single and chained requests
|
|
459
|
+
- Include proper error handling
|
|
460
|
+
- Add descriptive comments for complex logic
|
|
461
|
+
|
|
462
|
+
Code Style:
|
|
463
|
+
- 2-space indentation
|
|
464
|
+
- Single quotes for strings
|
|
465
|
+
- Semicolons at end of statements
|
|
466
|
+
- Clear variable naming
|
|
467
|
+
- Proper spacing and formatting`,
|
|
468
|
+
|
|
469
|
+
user: (context) => {
|
|
470
|
+
const { scenario, baseUrl, language, options } = context;
|
|
471
|
+
|
|
472
|
+
let prompt = `Generate a Jest/axios test for this scenario:
|
|
473
|
+
|
|
474
|
+
**Test Details:**
|
|
475
|
+
- Title: "${scenario.title}"
|
|
476
|
+
- Method: ${scenario.method}
|
|
477
|
+
- Endpoint: ${scenario.endpoint}
|
|
478
|
+
- Base URL: ${baseUrl}
|
|
479
|
+
- Language: ${language}
|
|
480
|
+
|
|
481
|
+
`;
|
|
482
|
+
|
|
483
|
+
// Add request details (similar to Playwright)
|
|
484
|
+
if (scenario.data && Object.keys(scenario.data).length > 0) {
|
|
485
|
+
prompt += `**Request Body:**
|
|
486
|
+
\`\`\`json
|
|
487
|
+
${JSON.stringify(scenario.data, null, 2)}
|
|
488
|
+
\`\`\`
|
|
489
|
+
|
|
490
|
+
`;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (scenario.headers && Object.keys(scenario.headers).length > 0) {
|
|
494
|
+
prompt += `**Headers:**
|
|
495
|
+
\`\`\`json
|
|
496
|
+
${JSON.stringify(scenario.headers, null, 2)}
|
|
497
|
+
\`\`\`
|
|
498
|
+
|
|
499
|
+
`;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (scenario.query && Object.keys(scenario.query).length > 0) {
|
|
503
|
+
prompt += `**Query Parameters:**
|
|
504
|
+
\`\`\`json
|
|
505
|
+
${JSON.stringify(scenario.query, null, 2)}
|
|
506
|
+
\`\`\`
|
|
507
|
+
|
|
508
|
+
`;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Add expectations
|
|
512
|
+
if (scenario.expect) {
|
|
513
|
+
prompt += `**Expected Response:**
|
|
514
|
+
- Status Code: ${scenario.expect.status || 200}
|
|
515
|
+
`;
|
|
516
|
+
if (scenario.expect.body) {
|
|
517
|
+
prompt += `- Response Body Structure:
|
|
518
|
+
\`\`\`json
|
|
519
|
+
${JSON.stringify(scenario.expect.body, null, 2)}
|
|
520
|
+
\`\`\`
|
|
521
|
+
`;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
prompt += `
|
|
526
|
+
**Instructions:**
|
|
527
|
+
1. Generate ONLY the test body code (the code inside the test() function)
|
|
528
|
+
2. Start at the correct indentation level (6 spaces for test body)
|
|
529
|
+
3. Use \`await apiUtils.makeRequest()\` helper for API calls
|
|
530
|
+
4. Include all request options (method, url, headers, params, data)
|
|
531
|
+
5. Add proper assertions for status code and response body
|
|
532
|
+
6. For TypeScript, use proper types
|
|
533
|
+
7. Handle errors appropriately
|
|
534
|
+
|
|
535
|
+
DO NOT include:
|
|
536
|
+
- describe() wrapper
|
|
537
|
+
- test() function declaration
|
|
538
|
+
- import statements
|
|
539
|
+
- Extra blank lines at start/end
|
|
540
|
+
|
|
541
|
+
Return ONLY the test body code, properly indented.`;
|
|
542
|
+
|
|
543
|
+
return prompt;
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Generate Postman test scripts
|
|
549
|
+
*/
|
|
550
|
+
postmanTestScript: {
|
|
551
|
+
system: `You are a Postman automation expert. Generate clear, effective Postman test scripts.
|
|
552
|
+
|
|
553
|
+
Requirements:
|
|
554
|
+
- Use pm.test() for assertions
|
|
555
|
+
- Use pm.response for response validation
|
|
556
|
+
- Use pm.expect() for assertions
|
|
557
|
+
- Include proper error messages
|
|
558
|
+
- Add descriptive test names`,
|
|
559
|
+
|
|
560
|
+
user: (context) => {
|
|
561
|
+
const { expect, extract } = context;
|
|
562
|
+
|
|
563
|
+
let prompt = `Generate Postman test script for this validation:
|
|
564
|
+
|
|
565
|
+
`;
|
|
566
|
+
|
|
567
|
+
if (expect && expect.status) {
|
|
568
|
+
prompt += `**Expected Status:** ${expect.status}
|
|
569
|
+
`;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (expect && expect.body) {
|
|
573
|
+
prompt += `**Expected Response Body:**
|
|
574
|
+
\`\`\`json
|
|
575
|
+
${JSON.stringify(expect.body, null, 2)}
|
|
576
|
+
\`\`\`
|
|
577
|
+
`;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (extract) {
|
|
581
|
+
prompt += `**Extract Variables:**
|
|
582
|
+
${Object.entries(extract).map(([key, field]) => `- ${key} from ${field}`).join('\n')}
|
|
583
|
+
`;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
prompt += `
|
|
587
|
+
**Instructions:**
|
|
588
|
+
1. Generate test script as array of strings
|
|
589
|
+
2. Each line should be a separate array element
|
|
590
|
+
3. Include status code validation
|
|
591
|
+
4. Include response body validation
|
|
592
|
+
5. Extract and store variables if specified
|
|
593
|
+
|
|
594
|
+
Return JavaScript array of test script lines.`;
|
|
595
|
+
|
|
596
|
+
return prompt;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|