@elisra-devops/docgen-data-provider 1.68.0 → 1.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1285,6 +1285,156 @@ describe('ResultDataProvider', () => {
1285
1285
  expect.arrayContaining([expect.objectContaining({ id: 200, title: 'B200', workItemType: 'Bug' })])
1286
1286
  );
1287
1287
  });
1288
+
1289
+ it('should return only the most recent System.History entry by default', async () => {
1290
+ (TFSServices.getItemContent as jest.Mock).mockReset();
1291
+
1292
+ const selectedFields = ['System.History@testCaseWorkItemField'];
1293
+
1294
+ (TFSServices.getItemContent as jest.Mock)
1295
+ // 1) run result
1296
+ .mockResolvedValueOnce({
1297
+ testCase: { id: 123 },
1298
+ testCaseRevision: 7,
1299
+ testSuite: { name: 'S' },
1300
+ })
1301
+ // 2) attachments
1302
+ .mockResolvedValueOnce({ value: [] })
1303
+ // 3) wiByRevision (no System.History field on this revision)
1304
+ .mockResolvedValueOnce({
1305
+ id: 123,
1306
+ fields: { 'Microsoft.VSTS.TCM.Steps': '<steps></steps>' },
1307
+ relations: [],
1308
+ })
1309
+ // 4) comments
1310
+ .mockResolvedValueOnce({
1311
+ comments: [
1312
+ {
1313
+ text: 'First comment',
1314
+ createdDate: '2024-01-01T00:00:00Z',
1315
+ createdBy: { displayName: 'Alice' },
1316
+ },
1317
+ {
1318
+ text: 'Second comment',
1319
+ createdDate: '2024-01-02T00:00:00Z',
1320
+ createdBy: { displayName: 'Bob' },
1321
+ },
1322
+ ],
1323
+ });
1324
+
1325
+ const res = await (resultDataProvider as any).fetchResultDataBasedOnWiBase(
1326
+ mockProjectName,
1327
+ '10',
1328
+ '20',
1329
+ true,
1330
+ selectedFields,
1331
+ false
1332
+ );
1333
+
1334
+ expect(res.filteredFields['System.History']).toEqual([
1335
+ { createdDate: '2024-01-02T00:00:00Z', createdBy: 'Bob', text: 'Second comment' },
1336
+ ]);
1337
+ });
1338
+
1339
+ it('should backfill System.History from work item comments when requested (includeAllHistory=true)', async () => {
1340
+ (TFSServices.getItemContent as jest.Mock).mockReset();
1341
+
1342
+ const selectedFields = ['System.History@testCaseWorkItemField'];
1343
+
1344
+ (TFSServices.getItemContent as jest.Mock)
1345
+ // 1) run result
1346
+ .mockResolvedValueOnce({
1347
+ testCase: { id: 123 },
1348
+ testCaseRevision: 7,
1349
+ testSuite: { name: 'S' },
1350
+ })
1351
+ // 2) attachments
1352
+ .mockResolvedValueOnce({ value: [] })
1353
+ // 3) wiByRevision (no System.History field on this revision)
1354
+ .mockResolvedValueOnce({
1355
+ id: 123,
1356
+ fields: { 'Microsoft.VSTS.TCM.Steps': '<steps></steps>' },
1357
+ relations: [],
1358
+ })
1359
+ // 4) comments
1360
+ .mockResolvedValueOnce({
1361
+ comments: [
1362
+ {
1363
+ text: 'First comment',
1364
+ createdDate: '2024-01-01T00:00:00Z',
1365
+ createdBy: { displayName: 'Alice' },
1366
+ },
1367
+ {
1368
+ text: 'Second comment',
1369
+ createdDate: '2024-01-02T00:00:00Z',
1370
+ createdBy: { displayName: 'Bob' },
1371
+ },
1372
+ ],
1373
+ });
1374
+
1375
+ const res = await (resultDataProvider as any).fetchResultDataBasedOnWiBase(
1376
+ mockProjectName,
1377
+ '10',
1378
+ '20',
1379
+ true,
1380
+ selectedFields,
1381
+ false,
1382
+ undefined,
1383
+ true
1384
+ );
1385
+
1386
+ expect(res.filteredFields['System.History']).toEqual([
1387
+ { createdDate: '2024-01-02T00:00:00Z', createdBy: 'Bob', text: 'Second comment' },
1388
+ { createdDate: '2024-01-01T00:00:00Z', createdBy: 'Alice', text: 'First comment' },
1389
+ ]);
1390
+ });
1391
+
1392
+ it('should fallback to updates when comments endpoint fails', async () => {
1393
+ (TFSServices.getItemContent as jest.Mock).mockReset();
1394
+
1395
+ const selectedFields = ['System.History@testCaseWorkItemField'];
1396
+
1397
+ (TFSServices.getItemContent as jest.Mock)
1398
+ // 1) run result
1399
+ .mockResolvedValueOnce({
1400
+ testCase: { id: 123 },
1401
+ testCaseRevision: 7,
1402
+ testSuite: { name: 'S' },
1403
+ })
1404
+ // 2) attachments
1405
+ .mockResolvedValueOnce({ value: [] })
1406
+ // 3) wiByRevision
1407
+ .mockResolvedValueOnce({
1408
+ id: 123,
1409
+ fields: { 'Microsoft.VSTS.TCM.Steps': '<steps></steps>' },
1410
+ relations: [],
1411
+ })
1412
+ // 4) comments (fails)
1413
+ .mockRejectedValueOnce(new Error('comments failed'))
1414
+ // 5) updates (fallback)
1415
+ .mockResolvedValueOnce({
1416
+ value: [
1417
+ {
1418
+ revisedDate: '2024-01-03T00:00:00Z',
1419
+ revisedBy: { displayName: 'Carol' },
1420
+ fields: { 'System.History': { newValue: 'Legacy history entry' } },
1421
+ },
1422
+ ],
1423
+ });
1424
+
1425
+ const res = await (resultDataProvider as any).fetchResultDataBasedOnWiBase(
1426
+ mockProjectName,
1427
+ '10',
1428
+ '20',
1429
+ true,
1430
+ selectedFields,
1431
+ false
1432
+ );
1433
+
1434
+ expect(res.filteredFields['System.History']).toEqual([
1435
+ { createdDate: '2024-01-03T00:00:00Z', createdBy: 'Carol', text: 'Legacy history entry' },
1436
+ ]);
1437
+ });
1288
1438
  });
1289
1439
 
1290
1440
  describe('alignStepsWithIterationsBase - additional branches', () => {
@@ -1792,25 +1792,6 @@ describe('TicketsDataProvider', () => {
1792
1792
  });
1793
1793
  });
1794
1794
 
1795
- describe('flattenTreeToWorkItems', () => {
1796
- it('should flatten a roots tree into a list of work items', () => {
1797
- const roots = [
1798
- {
1799
- id: 1,
1800
- title: 'R1',
1801
- description: 'D1',
1802
- htmlUrl: 'h1',
1803
- children: [{ id: 2, title: 'R2', description: 'D2', htmlUrl: 'h2', children: [] }],
1804
- },
1805
- ];
1806
-
1807
- const res = (ticketsDataProvider as any).flattenTreeToWorkItems(roots);
1808
- expect(res).toHaveLength(2);
1809
- expect(res[0]).toEqual(expect.objectContaining({ id: 1, url: 'h1' }));
1810
- expect(res[1]).toEqual(expect.objectContaining({ id: 2, url: 'h2' }));
1811
- });
1812
- });
1813
-
1814
1795
  describe('GetQueryResultsByWiqlHref', () => {
1815
1796
  it('should fetch and model query results', async () => {
1816
1797
  // Arrange