Skip to content

Commit e081232

Browse files
Feat: Add Zod schema for test case creation validation
1 parent 0f17ed3 commit e081232

File tree

2 files changed

+72
-68
lines changed

2 files changed

+72
-68
lines changed

src/tools/testmanagement-utils/create-testcase.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios, { AxiosError } from "axios";
22
import config from "../../config";
3+
import { z } from "zod";
34

45
interface TestCaseStep {
56
step: string;
@@ -54,6 +55,75 @@ export interface TestCaseResponse {
5455
};
5556
}
5657

58+
export const CreateTestCaseSchema = z.object({
59+
project_identifier: z
60+
.string()
61+
.describe(
62+
"The ID of the BrowserStack project in which to create the test case. Ask User if he want to create a new project if no project ID is provided using createProjectOrFolder tool.",
63+
),
64+
folder_id: z
65+
.string()
66+
.describe(
67+
"The ID of the folder under the project to create the test case in. If omitted, Ask user if he wants to create a new folder createProjectOrFolder tool.",
68+
),
69+
name: z.string().describe("Name of the test case."),
70+
description: z
71+
.string()
72+
.optional()
73+
.nullish()
74+
.describe("Brief description of the test case."),
75+
owner: z
76+
.string()
77+
.email()
78+
.describe("Email of the test case owner.")
79+
.optional()
80+
.nullish(),
81+
preconditions: z
82+
.string()
83+
.optional()
84+
.nullish()
85+
.describe("Any preconditions (HTML allowed)."),
86+
test_case_steps: z
87+
.array(
88+
z.object({
89+
step: z.string().describe("Action to perform in this step."),
90+
result: z.string().describe("Expected result of this step."),
91+
}),
92+
)
93+
.describe("List of steps and expected results."),
94+
issues: z
95+
.array(z.string())
96+
.optional()
97+
.describe(
98+
"List of the linked Jira, Asana or Azure issues ID's. This should be strictly in array format not the string of json.",
99+
),
100+
issue_tracker: z
101+
.object({
102+
name: z
103+
.string()
104+
.nullish()
105+
.describe(
106+
"Issue tracker name, For example, use jira for Jira, azure for Azure DevOps, or asana for Asana ​",
107+
),
108+
host: z
109+
.string()
110+
.url()
111+
.describe("Base URL of the issue tracker.")
112+
.nullish(),
113+
})
114+
.optional(),
115+
tags: z
116+
.array(z.string())
117+
.optional()
118+
.describe(
119+
"Tags to attach to the test case. This should be strictly in array format not the string of json",
120+
),
121+
custom_fields: z
122+
.record(z.string(), z.string())
123+
.optional()
124+
.describe("Map of custom field names to values."),
125+
});
126+
57127
export function sanitizeArgs(args: any) {
58128
const cleaned = { ...args };
59129

src/tools/testmanagement.ts

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
createTestCase as createTestCaseAPI,
1010
TestCaseCreateRequest,
1111
sanitizeArgs,
12+
CreateTestCaseSchema,
1213
} from "./testmanagement-utils/create-testcase";
1314

1415
/**
@@ -88,74 +89,7 @@ export default function addTestManagementTools(server: McpServer) {
8889
server.tool(
8990
"createTestCase",
9091
"Use this tool to create a test case in BrowserStack Test Management.",
91-
{
92-
project_identifier: z
93-
.string()
94-
.describe(
95-
"The ID of the BrowserStack project in which to create the test case. Ask User if he want to create a new project if no project ID is provided using createProjectOrFolder tool.",
96-
),
97-
folder_id: z
98-
.string()
99-
.describe(
100-
"The ID of the folder under the project to create the test case in. If omitted, Ask user if he wants to create a new folder createProjectOrFolder tool.",
101-
),
102-
name: z.string().describe("Name of the test case."),
103-
description: z
104-
.string()
105-
.optional()
106-
.nullish()
107-
.describe("Brief description of the test case."),
108-
owner: z
109-
.string()
110-
.email()
111-
.describe("Email of the test case owner.")
112-
.optional()
113-
.nullish(),
114-
preconditions: z
115-
.string()
116-
.optional()
117-
.nullish()
118-
.describe("Any preconditions (HTML allowed)."),
119-
test_case_steps: z
120-
.array(
121-
z.object({
122-
step: z.string().describe("Action to perform in this step."),
123-
result: z.string().describe("Expected result of this step."),
124-
}),
125-
)
126-
.describe("List of steps and expected results."),
127-
issues: z
128-
.array(z.string())
129-
.optional()
130-
.describe(
131-
"List of the linked Jira, Asana or Azure issues ID's. This should be strictly in array format not the string of json.",
132-
),
133-
issue_tracker: z
134-
.object({
135-
name: z
136-
.string()
137-
.nullish()
138-
.describe(
139-
"Issue tracker name, For example, use jira for Jira, azure for Azure DevOps, or asana for Asana ​",
140-
),
141-
host: z
142-
.string()
143-
.url()
144-
.describe("Base URL of the issue tracker.")
145-
.nullish(),
146-
})
147-
.optional(),
148-
tags: z
149-
.array(z.string())
150-
.optional()
151-
.describe(
152-
"Tags to attach to the test case. This should be strictly in array format not the string of json",
153-
),
154-
custom_fields: z
155-
.record(z.string(), z.string())
156-
.optional()
157-
.describe("Map of custom field names to values."),
158-
},
92+
CreateTestCaseSchema.shape,
15993
async (args) => {
16094
return createTestCaseTool(args as TestCaseCreateRequest);
16195
},

0 commit comments

Comments
 (0)