@@ -97,11 +97,17 @@ vi.mock('../../src/lib/inmemory-store', () => ({ signedUrlMap: new Map() }));
9797vi . mock ( '../../src/lib/get-auth' , ( ) => ( {
9898 getBrowserStackAuth : vi . fn ( ( ) => 'fake-user:fake-key' )
9999} ) ) ;
100- vi . mock ( '../../src/tools/testmanagement-utils/TCG-utils/api' , ( ) => ( {
101- projectIdentifierToId : vi . fn ( ( ) => Promise . resolve ( '999' ) ) ,
102- fetchFormFields : vi . fn ( ) ,
103- normalizeDefaultFieldValue : vi . fn ( ) ,
104- } ) ) ;
100+ vi . mock ( '../../src/tools/testmanagement-utils/TCG-utils/api' , async ( importActual ) => {
101+ const actual = await importActual <
102+ typeof import ( '../../src/tools/testmanagement-utils/TCG-utils/api' )
103+ > ( ) ;
104+ return {
105+ ...actual ,
106+ projectIdentifierToId : vi . fn ( ( ) => Promise . resolve ( '999' ) ) ,
107+ fetchFormFields : vi . fn ( ) ,
108+ normalizeDefaultFieldValue : vi . fn ( ) ,
109+ } ;
110+ } ) ;
105111vi . mock ( 'form-data' , ( ) => {
106112 return {
107113 default : vi . fn ( ) . mockImplementation ( ( ) => ( {
@@ -1077,7 +1083,6 @@ describe('createTestCase — priority normalization', () => {
10771083 let createTestCaseReal : typeof import ( '../../src/tools/testmanagement-utils/create-testcase' ) . createTestCase ;
10781084 let apiClientMock : typeof import ( '../../src/lib/apiClient' ) . apiClient ;
10791085 let fetchFormFieldsMock : Mock ;
1080- let normalizeMock : Mock ;
10811086
10821087 beforeAll ( async ( ) => {
10831088 const actual = await vi . importActual <
@@ -1087,7 +1092,6 @@ describe('createTestCase — priority normalization', () => {
10871092 apiClientMock = ( await import ( '../../src/lib/apiClient' ) ) . apiClient ;
10881093 const api = await import ( '../../src/tools/testmanagement-utils/TCG-utils/api' ) ;
10891094 fetchFormFieldsMock = api . fetchFormFields as unknown as Mock ;
1090- normalizeMock = api . normalizeDefaultFieldValue as unknown as Mock ;
10911095 } ) ;
10921096
10931097 beforeEach ( ( ) => {
@@ -1126,7 +1130,6 @@ describe('createTestCase — priority normalization', () => {
11261130
11271131 it ( 'looks up the project form fields and sends the normalized priority in the request body' , async ( ) => {
11281132 fetchFormFieldsMock . mockResolvedValue ( formFields ) ;
1129- normalizeMock . mockReturnValue ( 'Critical' ) ;
11301133 ( apiClientMock . post as Mock ) . mockResolvedValueOnce ( createSuccess ) ;
11311134
11321135 const result = await createTestCaseReal (
@@ -1135,7 +1138,8 @@ describe('createTestCase — priority normalization', () => {
11351138 ) ;
11361139
11371140 expect ( result . isError ) . toBeFalsy ( ) ;
1138- expect ( normalizeMock ) . toHaveBeenCalledWith ( priorityValues , 'critical' , 'name' ) ;
1141+ // Real normalizeDefaultFields maps the internal name 'critical' to the
1142+ // display name 'Critical' the create endpoint requires.
11391143 const body = ( apiClientMock . post as Mock ) . mock . calls [ 0 ] [ 0 ] . body ;
11401144 expect ( body . test_case . priority ) . toBe ( 'Critical' ) ;
11411145 } ) ;
@@ -1173,7 +1177,6 @@ describe('createTestCase — priority normalization', () => {
11731177 default_fields : { case_type : { values : caseTypeValues } } ,
11741178 custom_fields : { } ,
11751179 } ) ;
1176- normalizeMock . mockReturnValue ( 'Functional' ) ;
11771180 ( apiClientMock . post as Mock ) . mockResolvedValueOnce ( createSuccess ) ;
11781181
11791182 const result = await createTestCaseReal (
@@ -1182,7 +1185,7 @@ describe('createTestCase — priority normalization', () => {
11821185 ) ;
11831186
11841187 expect ( result . isError ) . toBeFalsy ( ) ;
1185- expect ( normalizeMock ) . toHaveBeenCalledWith ( caseTypeValues , 'functional' , ' name' ) ;
1188+ // Real normalizeDefaultFields maps 'functional' to the display name 'Functional'.
11861189 const body = ( apiClientMock . post as Mock ) . mock . calls [ 0 ] [ 0 ] . body ;
11871190 expect ( body . test_case . case_type ) . toBe ( 'Functional' ) ;
11881191 } ) ;
@@ -1217,9 +1220,6 @@ describe('createTestCase — priority normalization', () => {
12171220 } ,
12181221 custom_fields : { } ,
12191222 } ) ;
1220- normalizeMock . mockImplementation ( ( _values , input ) =>
1221- input === 'critical' ? 'Critical' : 'Functional' ,
1222- ) ;
12231223 ( apiClientMock . post as Mock ) . mockResolvedValueOnce ( createSuccess ) ;
12241224
12251225 await createTestCaseReal (
@@ -1410,6 +1410,30 @@ describe('createTestCase — template & multi-select custom_fields', () => {
14101410 expect ( call . body . test_case . folder_id ) . toBeUndefined ( ) ;
14111411 } ) ;
14121412
1413+ // case_type must survive into the v1 test_case body (spread from
1414+ // testCaseParams), normalized to the display name the endpoint accepts.
1415+ it ( 'carries the normalized case_type into the v1 body when template_id is set' , async ( ) => {
1416+ const api = await import ( '../../src/tools/testmanagement-utils/TCG-utils/api' ) ;
1417+ ( api . fetchFormFields as Mock ) . mockResolvedValue ( {
1418+ default_fields : {
1419+ case_type : {
1420+ values : [ { name : 'Functional' , internal_name : 'functional' , value : 1 } ] ,
1421+ } ,
1422+ } ,
1423+ custom_fields : [ ] ,
1424+ } ) ;
1425+ ( apiClientMock . post as Mock ) . mockResolvedValueOnce ( respWithId ( 656127 ) ) ;
1426+
1427+ await createTestCaseReal (
1428+ { ...baseArgs , template_id : 656127 , case_type : 'functional' } ,
1429+ mockConfig as any ,
1430+ ) ;
1431+
1432+ const call = ( apiClientMock . post as Mock ) . mock . calls [ 0 ] [ 0 ] ;
1433+ expect ( call . url ) . toContain ( '/api/v1/projects/' ) ;
1434+ expect ( call . body . test_case . case_type ) . toBe ( 'Functional' ) ;
1435+ } ) ;
1436+
14131437 it ( 'translates custom_fields name→id and option value→id on the v1 path' , async ( ) => {
14141438 const api = await import ( '../../src/tools/testmanagement-utils/TCG-utils/api' ) ;
14151439 ( api . fetchFormFields as Mock ) . mockResolvedValueOnce ( {
0 commit comments