@@ -6,32 +6,13 @@ import { projectIdentifierToId } from "./TCG-utils/api.js";
66import { BrowserStackConfig } from "../../lib/types.js" ;
77import { getTMBaseURL } from "../../lib/tm-base-url.js" ;
88import { getBrowserStackAuth } from "../../lib/get-auth.js" ;
9-
10- interface TestCaseStep {
11- step : string ;
12- result : string ;
13- }
14-
15- interface IssueTracker {
16- name : string ;
17- host : string ;
18- }
9+ import logger from "../../logger.js" ;
1910
2011export interface TestCaseUpdateRequest {
2112 project_identifier : string ;
22- test_case_id : string ;
13+ test_case_identifier : string ;
2314 name ?: string ;
2415 description ?: string ;
25- owner ?: string ;
26- preconditions ?: string ;
27- test_case_steps ?: TestCaseStep [ ] ;
28- issues ?: string [ ] ;
29- issue_tracker ?: IssueTracker ;
30- tags ?: string [ ] ;
31- custom_fields ?: Record < string , string > ;
32- automation_status ?: string ;
33- priority ?: string ;
34- case_type ?: string ;
3516}
3617
3718export interface TestCaseUpdateResponse {
@@ -54,7 +35,10 @@ export interface TestCaseUpdateResponse {
5435 identifier : string ;
5536 automation_status : string ;
5637 owner : string ;
57- steps : TestCaseStep [ ] ;
38+ steps : Array < {
39+ step : string ;
40+ result : string ;
41+ } > ;
5842 custom_fields : Array < {
5943 name : string ;
6044 value : string ;
@@ -69,7 +53,7 @@ export const UpdateTestCaseSchema = z.object({
6953 . describe (
7054 "The ID of the BrowserStack project containing the test case to update." ,
7155 ) ,
72- test_case_id : z
56+ test_case_identifier : z
7357 . string ( )
7458 . describe (
7559 "The ID of the test case to update. This can be found using the listTestCases tool." ,
@@ -79,67 +63,6 @@ export const UpdateTestCaseSchema = z.object({
7963 . string ( )
8064 . optional ( )
8165 . describe ( "Updated brief description of the test case." ) ,
82- owner : z
83- . string ( )
84- . email ( )
85- . describe ( "Updated email of the test case owner." )
86- . optional ( ) ,
87- preconditions : z
88- . string ( )
89- . optional ( )
90- . describe ( "Updated preconditions (HTML allowed)." ) ,
91- test_case_steps : z
92- . array (
93- z . object ( {
94- step : z . string ( ) . describe ( "Action to perform in this step." ) ,
95- result : z . string ( ) . describe ( "Expected result of this step." ) ,
96- } ) ,
97- )
98- . optional ( )
99- . describe ( "Updated list of steps and expected results." ) ,
100- issues : z
101- . array ( z . string ( ) )
102- . optional ( )
103- . describe (
104- "Updated list of linked Jira, Asana or Azure issues ID's. This should be strictly in array format." ,
105- ) ,
106- issue_tracker : z
107- . object ( {
108- name : z
109- . string ( )
110- . describe (
111- "Issue tracker name, For example, use jira for Jira, azure for Azure DevOps, or asana for Asana." ,
112- ) ,
113- host : z . string ( ) . url ( ) . describe ( "Base URL of the issue tracker." ) ,
114- } )
115- . optional ( )
116- . describe ( "Updated issue tracker configuration" ) ,
117- tags : z
118- . array ( z . string ( ) )
119- . optional ( )
120- . describe (
121- "Updated tags to attach to the test case. This should be strictly in array format." ,
122- ) ,
123- custom_fields : z
124- . record ( z . string ( ) )
125- . optional ( )
126- . describe ( "Updated map of custom field names to values." ) ,
127- automation_status : z
128- . string ( )
129- . optional ( )
130- . describe (
131- "Updated automation status of the test case. Common values include 'not_automated', 'automated', 'automation_not_required'." ,
132- ) ,
133- priority : z
134- . string ( )
135- . optional ( )
136- . describe (
137- "Updated priority level (e.g., 'critical', 'high', 'medium', 'low')." ,
138- ) ,
139- case_type : z
140- . string ( )
141- . optional ( )
142- . describe ( "Updated case type (e.g., 'functional', 'regression', 'smoke')." ) ,
14366} ) ;
14467
14568export function sanitizeUpdateArgs ( args : any ) {
@@ -174,67 +97,25 @@ export async function updateTestCase(
17497 const authString = getBrowserStackAuth ( config ) ;
17598 const [ username , password ] = authString . split ( ":" ) ;
17699
177- // Convert project identifier to project ID first
178- const projectId = await projectIdentifierToId (
179- params . project_identifier ,
180- config ,
181- ) ;
100+ // Build the request body with only the fields to update
101+ const testCaseBody : any = { } ;
182102
183- // Build the request body
184- const body : any = {
185- title : params . name ,
186- description : params . description ,
187- preconditions : params . preconditions ,
188- automation_status : params . automation_status ,
189- priority : params . priority ,
190- case_type : params . case_type ,
191- owner : params . owner ,
192- } ;
193-
194- // Add steps if provided
195- if ( params . test_case_steps ) {
196- body . steps = params . test_case_steps ;
103+ if ( params . name !== undefined ) {
104+ testCaseBody . name = params . name ;
197105 }
198106
199- // Add tags if provided
200- if ( params . tags ) {
201- body . tags = params . tags ;
107+ if ( params . description !== undefined ) {
108+ testCaseBody . description = params . description ;
202109 }
203110
204- // Add issues if provided
205- if ( params . issues && params . issues . length > 0 ) {
206- if ( params . issue_tracker ) {
207- body . issues = params . issues . map ( ( issue ) => ( {
208- jira_id : issue ,
209- issue_type : "story" , // default type, can be customized
210- } ) ) ;
211- body . issue_tracker = params . issue_tracker ;
212- }
213- }
214-
215- // Add custom fields if provided
216- if ( params . custom_fields ) {
217- body . custom_fields = Object . entries ( params . custom_fields ) . map (
218- ( [ name , value ] ) => ( {
219- name,
220- value,
221- } ) ,
222- ) ;
223- }
224-
225- // Remove undefined values
226- Object . keys ( body ) . forEach ( ( key ) => {
227- if ( body [ key ] === undefined ) {
228- delete body [ key ] ;
229- }
230- } ) ;
111+ const body = { test_case : testCaseBody } ;
231112
232113 try {
233114 const tmBaseUrl = await getTMBaseURL ( config ) ;
234- const response = await apiClient . put ( {
115+ const response = await apiClient . patch ( {
235116 url : `${ tmBaseUrl } /api/v2/projects/${ encodeURIComponent (
236- projectId . toString ( ) ,
237- ) } /test-cases/${ encodeURIComponent ( params . test_case_id ) } `,
117+ params . project_identifier ,
118+ ) } /test-cases/${ encodeURIComponent ( params . test_case_identifier ) } `,
238119 headers : {
239120 "Content-Type" : "application/json" ,
240121 Authorization :
@@ -261,6 +142,12 @@ export async function updateTestCase(
261142
262143 const tc = data . test_case ;
263144
145+ // Convert project identifier to project ID for dashboard URL
146+ const projectId = await projectIdentifierToId (
147+ params . project_identifier ,
148+ config ,
149+ ) ;
150+
264151 return {
265152 content : [
266153 {
@@ -271,14 +158,9 @@ export async function updateTestCase(
271158- **ID**: ${ tc . identifier }
272159- **Name**: ${ tc . title }
273160- **Description**: ${ tc . description || "N/A" }
274- - **Owner**: ${ tc . owner || "N/A" }
275- - **Priority**: ${ tc . priority }
276161- **Case Type**: ${ tc . case_type }
277- - **Automation Status**: ${ tc . automation_status || "N/A" }
278- - **Preconditions**: ${ tc . preconditions || "N/A" }
279- - **Tags**: ${ tc . tags ?. join ( ", " ) || "None" }
280- - **Steps**: ${ tc . steps ?. length || 0 } steps
281- - **Custom Fields**: ${ tc . custom_fields ?. length || 0 } fields
162+ - **Priority**: ${ tc . priority }
163+ - **Status**: ${ tc . status }
282164
283165**View on BrowserStack Dashboard:**
284166https://test-management.browserstack.com/projects/${ projectId } /folders/${ tc . folder_id } /test-cases/${ tc . identifier }
@@ -288,14 +170,20 @@ The test case has been updated successfully and is now available in your Browser
288170 ] ,
289171 } ;
290172 } catch ( err : any ) {
291- console . error ( "Update test case error:" , err ) ;
173+ logger . error ( "Failed to update test case: %s" , err ) ;
174+ logger . error (
175+ "Error details:" ,
176+ JSON . stringify ( err . response ?. data || err . message ) ,
177+ ) ;
292178
293179 if ( err . response ?. status === 404 ) {
294180 return {
295181 content : [
296182 {
297183 type : "text" ,
298- text : `Test case not found. Please verify the project_identifier ("${ params . project_identifier } ") and test_case_id ("${ params . test_case_id } ") are correct. Make sure to use actual values, not placeholders like "your_project_id".` ,
184+ text : `Test case not found. Please verify the project_identifier ("${ params . project_identifier } ") and test_case_identifier ("${ params . test_case_identifier } ") are correct. Make sure to use actual values, not placeholders like "your_project_id".
185+
186+ Error details: ${ JSON . stringify ( err . response ?. data || err . message ) } ` ,
299187 isError : true ,
300188 } ,
301189 ] ,
0 commit comments