@@ -285,13 +285,224 @@ describe("configureWorkItemTools", () => {
285
285
expect ( mockWorkItemTrackingApi . getWorkItemsBatch ) . toHaveBeenCalledWith (
286
286
{
287
287
ids : params . ids ,
288
- fields : [ "System.Id" , "System.WorkItemType" , "System.Title" , "System.State" , "System.Parent" , "System.Tags" , "Microsoft.VSTS.Common.StackRank" ] ,
288
+ fields : [ "System.Id" , "System.WorkItemType" , "System.Title" , "System.State" , "System.Parent" , "System.Tags" , "Microsoft.VSTS.Common.StackRank" , "System.AssignedTo" ] ,
289
289
} ,
290
290
params . project
291
291
) ;
292
292
293
293
expect ( result . content [ 0 ] . text ) . toBe ( JSON . stringify ( [ _mockWorkItems ] , null , 2 ) ) ;
294
294
} ) ;
295
+
296
+ it ( "should transform System.AssignedTo object to formatted string" , async ( ) => {
297
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
298
+
299
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
300
+
301
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
302
+ const [ , , , handler ] = call ;
303
+
304
+ // Mock work items with System.AssignedTo as objects
305
+ const mockWorkItemsWithAssignedTo = [
306
+ {
307
+ id : 297 ,
308
+ fields : {
309
+ "System.Id" : 297 ,
310
+ "System.WorkItemType" : "Bug" ,
311
+ "System.Title" : "Test Bug" ,
312
+ "System.AssignedTo" : {
313
+ displayName : "John Doe" ,
314
+
315
+ id : "12345" ,
316
+ } ,
317
+ } ,
318
+ } ,
319
+ {
320
+ id : 298 ,
321
+ fields : {
322
+ "System.Id" : 298 ,
323
+ "System.WorkItemType" : "User Story" ,
324
+ "System.Title" : "Test Story" ,
325
+ "System.AssignedTo" : {
326
+ displayName : "Jane Smith" ,
327
+
328
+ id : "67890" ,
329
+ } ,
330
+ } ,
331
+ } ,
332
+ ] ;
333
+
334
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( mockWorkItemsWithAssignedTo ) ;
335
+
336
+ const params = {
337
+ ids : [ 297 , 298 ] ,
338
+ project : "Contoso" ,
339
+ } ;
340
+
341
+ const result = await handler ( params ) ;
342
+
343
+ // Parse the returned JSON to verify transformation
344
+ const resultData = JSON . parse ( result . content [ 0 ] . text ) ;
345
+
346
+ expect ( resultData [ 0 ] . fields [ "System.AssignedTo" ] ) . toBe ( "John Doe <[email protected] >" ) ;
347
+ expect ( resultData [ 1 ] . fields [ "System.AssignedTo" ] ) . toBe ( "Jane Smith <[email protected] >" ) ;
348
+ } ) ;
349
+
350
+ it ( "should handle System.AssignedTo with only displayName" , async ( ) => {
351
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
352
+
353
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
354
+
355
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
356
+ const [ , , , handler ] = call ;
357
+
358
+ const mockWorkItemsWithPartialAssignedTo = [
359
+ {
360
+ id : 297 ,
361
+ fields : {
362
+ "System.Id" : 297 ,
363
+ "System.WorkItemType" : "Bug" ,
364
+ "System.Title" : "Test Bug" ,
365
+ "System.AssignedTo" : {
366
+ displayName : "John Doe" ,
367
+ id : "12345" ,
368
+ } ,
369
+ } ,
370
+ } ,
371
+ ] ;
372
+
373
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( mockWorkItemsWithPartialAssignedTo ) ;
374
+
375
+ const params = {
376
+ ids : [ 297 ] ,
377
+ project : "Contoso" ,
378
+ } ;
379
+
380
+ const result = await handler ( params ) ;
381
+
382
+ const resultData = JSON . parse ( result . content [ 0 ] . text ) ;
383
+ expect ( resultData [ 0 ] . fields [ "System.AssignedTo" ] ) . toBe ( "John Doe <>" ) ;
384
+ } ) ;
385
+
386
+ it ( "should handle System.AssignedTo with only uniqueName" , async ( ) => {
387
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
388
+
389
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
390
+
391
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
392
+ const [ , , , handler ] = call ;
393
+
394
+ const mockWorkItemsWithPartialAssignedTo = [
395
+ {
396
+ id : 297 ,
397
+ fields : {
398
+ "System.Id" : 297 ,
399
+ "System.WorkItemType" : "Bug" ,
400
+ "System.Title" : "Test Bug" ,
401
+ "System.AssignedTo" : {
402
+
403
+ id : "12345" ,
404
+ } ,
405
+ } ,
406
+ } ,
407
+ ] ;
408
+
409
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( mockWorkItemsWithPartialAssignedTo ) ;
410
+
411
+ const params = {
412
+ ids : [ 297 ] ,
413
+ project : "Contoso" ,
414
+ } ;
415
+
416
+ const result = await handler ( params ) ;
417
+
418
+ const resultData = JSON . parse ( result . content [ 0 ] . text ) ;
419
+ expect ( resultData [ 0 ] . fields [ "System.AssignedTo" ] ) . toBe ( "<[email protected] >" ) ;
420
+ } ) ;
421
+
422
+ it ( "should not transform System.AssignedTo if it's not an object" , async ( ) => {
423
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
424
+
425
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
426
+
427
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
428
+ const [ , , , handler ] = call ;
429
+
430
+ const mockWorkItemsWithStringAssignedTo = [
431
+ {
432
+ id : 297 ,
433
+ fields : {
434
+ "System.Id" : 297 ,
435
+ "System.WorkItemType" : "Bug" ,
436
+ "System.Title" : "Test Bug" ,
437
+ "System.AssignedTo" : "Already a string" ,
438
+ } ,
439
+ } ,
440
+ ] ;
441
+
442
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( mockWorkItemsWithStringAssignedTo ) ;
443
+
444
+ const params = {
445
+ ids : [ 297 ] ,
446
+ project : "Contoso" ,
447
+ } ;
448
+
449
+ const result = await handler ( params ) ;
450
+
451
+ const resultData = JSON . parse ( result . content [ 0 ] . text ) ;
452
+ expect ( resultData [ 0 ] . fields [ "System.AssignedTo" ] ) . toBe ( "Already a string" ) ;
453
+ } ) ;
454
+
455
+ it ( "should handle work items without System.AssignedTo field" , async ( ) => {
456
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
457
+
458
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
459
+
460
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
461
+ const [ , , , handler ] = call ;
462
+
463
+ const mockWorkItemsWithoutAssignedTo = [
464
+ {
465
+ id : 297 ,
466
+ fields : {
467
+ "System.Id" : 297 ,
468
+ "System.WorkItemType" : "Bug" ,
469
+ "System.Title" : "Test Bug" ,
470
+ } ,
471
+ } ,
472
+ ] ;
473
+
474
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( mockWorkItemsWithoutAssignedTo ) ;
475
+
476
+ const params = {
477
+ ids : [ 297 ] ,
478
+ project : "Contoso" ,
479
+ } ;
480
+
481
+ const result = await handler ( params ) ;
482
+
483
+ const resultData = JSON . parse ( result . content [ 0 ] . text ) ;
484
+ expect ( resultData [ 0 ] . fields [ "System.AssignedTo" ] ) . toBeUndefined ( ) ;
485
+ } ) ;
486
+
487
+ it ( "should handle null or undefined workitems response" , async ( ) => {
488
+ configureWorkItemTools ( server , tokenProvider , connectionProvider , userAgentProvider ) ;
489
+
490
+ const call = ( server . tool as jest . Mock ) . mock . calls . find ( ( [ toolName ] ) => toolName === "wit_get_work_items_batch_by_ids" ) ;
491
+
492
+ if ( ! call ) throw new Error ( "wit_get_work_items_batch_by_ids tool not registered" ) ;
493
+ const [ , , , handler ] = call ;
494
+
495
+ ( mockWorkItemTrackingApi . getWorkItemsBatch as jest . Mock ) . mockResolvedValue ( null ) ;
496
+
497
+ const params = {
498
+ ids : [ 297 ] ,
499
+ project : "Contoso" ,
500
+ } ;
501
+
502
+ const result = await handler ( params ) ;
503
+
504
+ expect ( result . content [ 0 ] . text ) . toBe ( JSON . stringify ( null , null , 2 ) ) ;
505
+ } ) ;
295
506
} ) ;
296
507
297
508
describe ( "get_work_item tool" , ( ) => {
0 commit comments