@@ -14,6 +14,7 @@ import {
1414import { createTestCasePayload } from "./helpers.js" ;
1515import { getBrowserStackAuth } from "../../../lib/get-auth.js" ;
1616import { BrowserStackConfig } from "../../../lib/types.js" ;
17+ import { getTMBaseURL } from "../../../lib/tm-base-url.js" ;
1718
1819/**
1920 * Fetch default and custom form fields for a project.
@@ -22,8 +23,9 @@ export async function fetchFormFields(
2223 projectId : string ,
2324 config : BrowserStackConfig ,
2425) : Promise < { default_fields : any ; custom_fields : any } > {
26+ const tmBaseUrl = await getTMBaseURL ( config ) ;
2527 const res = await apiClient . get ( {
26- url : FORM_FIELDS_URL ( projectId ) ,
28+ url : FORM_FIELDS_URL ( tmBaseUrl , projectId ) ,
2729 headers : {
2830 "API-TOKEN" : getBrowserStackAuth ( config ) ,
2931 } ,
@@ -42,8 +44,9 @@ export async function triggerTestCaseGeneration(
4244 source : string ,
4345 config : BrowserStackConfig ,
4446) : Promise < string > {
47+ const tmBaseUrl = await getTMBaseURL ( config ) ;
4548 const res = await apiClient . post ( {
46- url : TCG_TRIGGER_URL ,
49+ url : TCG_TRIGGER_URL ( tmBaseUrl ) ,
4750 headers : {
4851 "API-TOKEN" : getBrowserStackAuth ( config ) ,
4952 "Content-Type" : "application/json" ,
@@ -55,7 +58,7 @@ export async function triggerTestCaseGeneration(
5558 folderId,
5659 projectId,
5760 source,
58- webhookUrl : `https://test-management.browserstack.com /api/v1/projects/${ projectId } /folder/${ folderId } /webhooks/tcg` ,
61+ webhookUrl : `${ tmBaseUrl } /api/v1/projects/${ projectId } /folder/${ folderId } /webhooks/tcg` ,
5962 } ,
6063 } ) ;
6164 if ( res . status !== 200 ) {
@@ -78,8 +81,9 @@ export async function fetchTestCaseDetails(
7881 if ( testCaseIds . length === 0 ) {
7982 throw new Error ( "No testCaseIds provided to fetchTestCaseDetails" ) ;
8083 }
84+ const tmBaseUrl = await getTMBaseURL ( config ) ;
8185 const res = await apiClient . post ( {
82- url : FETCH_DETAILS_URL ,
86+ url : FETCH_DETAILS_URL ( tmBaseUrl ) ,
8387 headers : {
8488 "API-TOKEN" : getBrowserStackAuth ( config ) ,
8589 "request-source" : source ,
@@ -107,13 +111,15 @@ export async function pollTestCaseDetails(
107111) : Promise < Record < string , any > > {
108112 const detailMap : Record < string , any > = { } ;
109113 let done = false ;
114+ const tmBaseUrl = await getTMBaseURL ( config ) ;
115+ const TCG_POLL_URL_VALUE = TCG_POLL_URL ( tmBaseUrl ) ;
110116
111117 while ( ! done ) {
112118 // add a bit of jitter to avoid synchronized polling storms
113119 await new Promise ( ( r ) => setTimeout ( r , 10000 + Math . random ( ) * 5000 ) ) ;
114120
115121 const poll = await apiClient . post ( {
116- url : `${ TCG_POLL_URL } ?x-bstack-traceRequestId=${ encodeURIComponent ( traceRequestId ) } ` ,
122+ url : `${ TCG_POLL_URL_VALUE } ?x-bstack-traceRequestId=${ encodeURIComponent ( traceRequestId ) } ` ,
117123 headers : {
118124 "API-TOKEN" : getBrowserStackAuth ( config ) ,
119125 } ,
@@ -157,13 +163,15 @@ export async function pollScenariosTestDetails(
157163 const scenariosMap : Record < string , Scenario > = { } ;
158164 const detailPromises : Promise < Record < string , any > > [ ] = [ ] ;
159165 let iteratorCount = 0 ;
166+ const tmBaseUrl = await getTMBaseURL ( config ) ;
167+ const TCG_POLL_URL_VALUE = TCG_POLL_URL ( tmBaseUrl ) ;
160168
161169 // Promisify interval-style polling using a wrapper
162170 await new Promise < void > ( ( resolve , reject ) => {
163171 const intervalId = setInterval ( async ( ) => {
164172 try {
165173 const poll = await apiClient . post ( {
166- url : `${ TCG_POLL_URL } ?x-bstack-traceRequestId=${ encodeURIComponent ( traceId ) } ` ,
174+ url : `${ TCG_POLL_URL_VALUE } ?x-bstack-traceRequestId=${ encodeURIComponent ( traceId ) } ` ,
167175 headers : {
168176 "API-TOKEN" : getBrowserStackAuth ( config ) ,
169177 } ,
@@ -279,6 +287,8 @@ export async function bulkCreateTestCases(
279287 const total = Object . keys ( scenariosMap ) . length ;
280288 let doneCount = 0 ;
281289 let testCaseCount = 0 ;
290+ const tmBaseUrl = await getTMBaseURL ( config ) ;
291+ const BULK_CREATE_URL_VALUE = BULK_CREATE_URL ( tmBaseUrl , projectId , folderId ) ;
282292
283293 for ( const { id, testcases } of Object . values ( scenariosMap ) ) {
284294 const testCaseLength = testcases . length ;
@@ -300,7 +310,7 @@ export async function bulkCreateTestCases(
300310
301311 try {
302312 const resp = await apiClient . post ( {
303- url : BULK_CREATE_URL ( projectId , folderId ) ,
313+ url : BULK_CREATE_URL_VALUE ,
304314 headers : {
305315 "API-TOKEN" : getBrowserStackAuth ( config ) ,
306316 "Content-Type" : "application/json" ,
@@ -341,7 +351,8 @@ export async function projectIdentifierToId(
341351 projectId : string ,
342352 config : BrowserStackConfig ,
343353) : Promise < string > {
344- const url = `https://test-management.browserstack.com/api/v1/projects/?q=${ projectId } ` ;
354+ const tmBaseUrl = await getTMBaseURL ( config ) ;
355+ const url = `${ tmBaseUrl } /api/v1/projects/?q=${ projectId } ` ;
345356
346357 const response = await apiClient . get ( {
347358 url,
@@ -368,7 +379,8 @@ export async function testCaseIdentifierToDetails(
368379 testCaseIdentifier : string ,
369380 config : BrowserStackConfig ,
370381) : Promise < { testCaseId : string ; folderId : string } > {
371- const url = `https://test-management.browserstack.com/api/v1/projects/${ projectId } /test-cases/search?q[query]=${ testCaseIdentifier } ` ;
382+ const tmBaseUrl = await getTMBaseURL ( config ) ;
383+ const url = `${ tmBaseUrl } /api/v1/projects/${ projectId } /test-cases/search?q[query]=${ testCaseIdentifier } ` ;
372384
373385 const response = await apiClient . get ( {
374386 url,
0 commit comments