@elisra-devops/docgen-data-provider 1.63.12 → 1.67.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.
Files changed (94) hide show
  1. package/.github/workflows/ci.yml +26 -9
  2. package/.github/workflows/release.yml +9 -10
  3. package/bin/helpers/tfs.d.ts +3 -0
  4. package/bin/helpers/tfs.js +44 -7
  5. package/bin/helpers/tfs.js.map +1 -1
  6. package/bin/modules/GitDataProvider.d.ts +10 -0
  7. package/bin/modules/GitDataProvider.js +10 -0
  8. package/bin/modules/GitDataProvider.js.map +1 -1
  9. package/bin/modules/MangementDataProvider.js +7 -1
  10. package/bin/modules/MangementDataProvider.js.map +1 -1
  11. package/bin/modules/TestDataProvider.js +0 -1
  12. package/bin/modules/TestDataProvider.js.map +1 -1
  13. package/bin/modules/TicketsDataProvider.d.ts +63 -27
  14. package/bin/modules/TicketsDataProvider.js +226 -122
  15. package/bin/modules/TicketsDataProvider.js.map +1 -1
  16. package/bin/tests/helpers/helper.test.js +279 -0
  17. package/bin/tests/helpers/helper.test.js.map +1 -0
  18. package/bin/{helpers/test → tests/helpers}/tfs.test.js +312 -49
  19. package/bin/tests/helpers/tfs.test.js.map +1 -0
  20. package/bin/tests/index.test.js +25 -0
  21. package/bin/tests/index.test.js.map +1 -0
  22. package/bin/tests/models/tfs-data.test.js +160 -0
  23. package/bin/tests/models/tfs-data.test.js.map +1 -0
  24. package/bin/{modules/test → tests/modules}/JfrogDataProvider.test.js +9 -9
  25. package/bin/tests/modules/JfrogDataProvider.test.js.map +1 -0
  26. package/bin/tests/modules/ResultDataProvider.test.js +1942 -0
  27. package/bin/tests/modules/ResultDataProvider.test.js.map +1 -0
  28. package/bin/tests/modules/gitDataProvider.test.js +1888 -0
  29. package/bin/tests/modules/gitDataProvider.test.js.map +1 -0
  30. package/bin/{modules/test → tests/modules}/managmentDataProvider.test.js +39 -31
  31. package/bin/tests/modules/managmentDataProvider.test.js.map +1 -0
  32. package/bin/tests/modules/pipelineDataProvider.test.d.ts +1 -0
  33. package/bin/tests/modules/pipelineDataProvider.test.js +783 -0
  34. package/bin/tests/modules/pipelineDataProvider.test.js.map +1 -0
  35. package/bin/tests/modules/testDataProvider.test.d.ts +1 -0
  36. package/bin/tests/modules/testDataProvider.test.js +717 -0
  37. package/bin/tests/modules/testDataProvider.test.js.map +1 -0
  38. package/bin/tests/modules/ticketsDataProvider.test.d.ts +1 -0
  39. package/bin/tests/modules/ticketsDataProvider.test.js +1681 -0
  40. package/bin/tests/modules/ticketsDataProvider.test.js.map +1 -0
  41. package/bin/tests/utils/DataProviderUtils.test.d.ts +1 -0
  42. package/bin/tests/utils/DataProviderUtils.test.js +61 -0
  43. package/bin/tests/utils/DataProviderUtils.test.js.map +1 -0
  44. package/bin/tests/utils/testStepParserHelper.test.d.ts +1 -0
  45. package/bin/tests/utils/testStepParserHelper.test.js +359 -0
  46. package/bin/tests/utils/testStepParserHelper.test.js.map +1 -0
  47. package/package.json +10 -1
  48. package/src/helpers/tfs.ts +51 -7
  49. package/src/modules/GitDataProvider.ts +10 -0
  50. package/src/modules/MangementDataProvider.ts +6 -1
  51. package/src/modules/TestDataProvider.ts +0 -1
  52. package/src/modules/TicketsDataProvider.ts +311 -151
  53. package/src/tests/helpers/helper.test.ts +337 -0
  54. package/src/tests/helpers/tfs.test.ts +1092 -0
  55. package/src/tests/index.test.ts +28 -0
  56. package/src/tests/models/tfs-data.test.ts +203 -0
  57. package/src/tests/modules/JfrogDataProvider.test.ts +167 -0
  58. package/src/tests/modules/ResultDataProvider.test.ts +2571 -0
  59. package/src/tests/modules/gitDataProvider.test.ts +2628 -0
  60. package/src/{modules/test → tests/modules}/managmentDataProvider.test.ts +63 -32
  61. package/src/tests/modules/pipelineDataProvider.test.ts +1038 -0
  62. package/src/tests/modules/testDataProvider.test.ts +1046 -0
  63. package/src/tests/modules/ticketsDataProvider.test.ts +2204 -0
  64. package/src/tests/utils/DataProviderUtils.test.ts +76 -0
  65. package/src/tests/utils/testStepParserHelper.test.ts +437 -0
  66. package/tsconfig.json +1 -0
  67. package/bin/helpers/test/tfs.test.js.map +0 -1
  68. package/bin/modules/test/JfrogDataProvider.test.js.map +0 -1
  69. package/bin/modules/test/ResultDataProvider.test.js +0 -444
  70. package/bin/modules/test/ResultDataProvider.test.js.map +0 -1
  71. package/bin/modules/test/gitDataProvider.test.js +0 -433
  72. package/bin/modules/test/gitDataProvider.test.js.map +0 -1
  73. package/bin/modules/test/managmentDataProvider.test.js.map +0 -1
  74. package/bin/modules/test/pipelineDataProvider.test.js +0 -237
  75. package/bin/modules/test/pipelineDataProvider.test.js.map +0 -1
  76. package/bin/modules/test/testDataProvider.test.js +0 -234
  77. package/bin/modules/test/testDataProvider.test.js.map +0 -1
  78. package/bin/modules/test/ticketsDataProvider.test.js +0 -322
  79. package/bin/modules/test/ticketsDataProvider.test.js.map +0 -1
  80. package/src/helpers/test/tfs.test.ts +0 -748
  81. package/src/modules/test/JfrogDataProvider.test.ts +0 -171
  82. package/src/modules/test/ResultDataProvider.test.ts +0 -542
  83. package/src/modules/test/gitDataProvider.test.ts +0 -691
  84. package/src/modules/test/pipelineDataProvider.test.ts +0 -292
  85. package/src/modules/test/testDataProvider.test.ts +0 -318
  86. package/src/modules/test/ticketsDataProvider.test.ts +0 -434
  87. /package/bin/{helpers/test/tfs.test.d.ts → tests/helpers/helper.test.d.ts} +0 -0
  88. /package/bin/{modules/test/JfrogDataProvider.test.d.ts → tests/helpers/tfs.test.d.ts} +0 -0
  89. /package/bin/{modules/test/ResultDataProvider.test.d.ts → tests/index.test.d.ts} +0 -0
  90. /package/bin/{modules/test/gitDataProvider.test.d.ts → tests/models/tfs-data.test.d.ts} +0 -0
  91. /package/bin/{modules/test/managmentDataProvider.test.d.ts → tests/modules/JfrogDataProvider.test.d.ts} +0 -0
  92. /package/bin/{modules/test/pipelineDataProvider.test.d.ts → tests/modules/ResultDataProvider.test.d.ts} +0 -0
  93. /package/bin/{modules/test/testDataProvider.test.d.ts → tests/modules/gitDataProvider.test.d.ts} +0 -0
  94. /package/bin/{modules/test/ticketsDataProvider.test.d.ts → tests/modules/managmentDataProvider.test.d.ts} +0 -0
@@ -1,691 +0,0 @@
1
- import axios from 'axios';
2
- import { TFSServices } from '../../helpers/tfs';
3
- import GitDataProvider from '../GitDataProvider';
4
- import logger from '../../utils/logger';
5
-
6
- jest.mock('../../helpers/tfs');
7
- jest.mock('../../utils/logger');
8
-
9
- describe('GitDataProvider - GetCommitForPipeline', () => {
10
- let gitDataProvider: GitDataProvider;
11
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
12
- const mockToken = 'mock-token';
13
- const mockProjectId = 'project-123';
14
- const mockBuildId = 456;
15
-
16
- beforeEach(() => {
17
- jest.clearAllMocks();
18
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
19
- });
20
-
21
- it('should return the sourceVersion from build information', async () => {
22
- // Arrange
23
- const mockCommitSha = 'abc123def456';
24
- const mockResponse = {
25
- id: mockBuildId,
26
- sourceVersion: mockCommitSha,
27
- status: 'completed'
28
- };
29
-
30
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
31
-
32
- // Act
33
- const result = await gitDataProvider.GetCommitForPipeline(mockProjectId, mockBuildId);
34
-
35
- // Assert
36
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
37
- `${mockOrgUrl}${mockProjectId}/_apis/build/builds/${mockBuildId}`,
38
- mockToken,
39
- 'get'
40
- );
41
- expect(result).toBe(mockCommitSha);
42
- });
43
-
44
- it('should throw an error if the API call fails', async () => {
45
- // Arrange
46
- const expectedError = new Error('API call failed');
47
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(expectedError);
48
-
49
- // Act & Assert
50
- await expect(gitDataProvider.GetCommitForPipeline(mockProjectId, mockBuildId))
51
- .rejects.toThrow('API call failed');
52
-
53
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
54
- `${mockOrgUrl}${mockProjectId}/_apis/build/builds/${mockBuildId}`,
55
- mockToken,
56
- 'get'
57
- );
58
- });
59
-
60
- it('should return undefined if the response does not contain sourceVersion', async () => {
61
- // Arrange
62
- const mockResponse = {
63
- id: mockBuildId,
64
- status: 'completed'
65
- // No sourceVersion property
66
- };
67
-
68
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
69
-
70
- // Act
71
- const result = await gitDataProvider.GetCommitForPipeline(mockProjectId, mockBuildId);
72
-
73
- // Assert
74
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
75
- `${mockOrgUrl}${mockProjectId}/_apis/build/builds/${mockBuildId}`,
76
- mockToken,
77
- 'get'
78
- );
79
- expect(result).toBeUndefined();
80
- });
81
-
82
- it('should correctly construct URL with given project ID and build ID', async () => {
83
- // Arrange
84
- const customProjectId = 'custom-project';
85
- const customBuildId = 789;
86
- const mockCommitSha = 'xyz789abc';
87
- const mockResponse = { sourceVersion: mockCommitSha };
88
-
89
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
90
-
91
- // Act
92
- await gitDataProvider.GetCommitForPipeline(customProjectId, customBuildId);
93
-
94
- // Assert
95
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
96
- `${mockOrgUrl}${customProjectId}/_apis/build/builds/${customBuildId}`,
97
- mockToken,
98
- 'get'
99
- );
100
- });
101
-
102
- it('should handle different organization URLs correctly', async () => {
103
- // Arrange
104
- const altOrgUrl = 'https://dev.azure.com/different-org/';
105
- const altGitDataProvider = new GitDataProvider(altOrgUrl, mockToken);
106
- const mockResponse = { sourceVersion: 'commit-sha' };
107
-
108
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
109
-
110
- // Act
111
- await altGitDataProvider.GetCommitForPipeline(mockProjectId, mockBuildId);
112
-
113
- // Assert
114
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
115
- `${altOrgUrl}${mockProjectId}/_apis/build/builds/${mockBuildId}`,
116
- mockToken,
117
- 'get'
118
- );
119
- });
120
- });
121
- describe('GitDataProvider - GetTeamProjectGitReposList', () => {
122
- let gitDataProvider: GitDataProvider;
123
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
124
- const mockToken = 'mock-token';
125
- const mockTeamProject = 'project-123';
126
-
127
- beforeEach(() => {
128
- jest.clearAllMocks();
129
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
130
- });
131
-
132
- it('should return sorted repositories when API call succeeds', async () => {
133
- // Arrange
134
- const mockRepos = {
135
- value: [
136
- { id: 'repo2', name: 'ZRepo' },
137
- { id: 'repo1', name: 'ARepo' },
138
- { id: 'repo3', name: 'MRepo' }
139
- ]
140
- };
141
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockRepos);
142
-
143
- // Act
144
- const result = await gitDataProvider.GetTeamProjectGitReposList(mockTeamProject);
145
-
146
- // Assert
147
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
148
- `${mockOrgUrl}/${mockTeamProject}/_apis/git/repositories`,
149
- mockToken,
150
- 'get'
151
- );
152
- expect(result).toHaveLength(3);
153
- expect(result[0].name).toBe('ARepo');
154
- expect(result[1].name).toBe('MRepo');
155
- expect(result[2].name).toBe('ZRepo');
156
- expect(logger.debug).toHaveBeenCalledWith(
157
- expect.stringContaining(`fetching repos list for team project - ${mockTeamProject}`)
158
- );
159
- });
160
-
161
- it('should return empty array when no repositories exist', async () => {
162
- // Arrange
163
- const mockEmptyRepos = { value: [] };
164
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockEmptyRepos);
165
-
166
- // Act
167
- const result = await gitDataProvider.GetTeamProjectGitReposList(mockTeamProject);
168
-
169
- // Assert
170
- expect(result).toEqual([]);
171
- });
172
-
173
- it('should handle API errors appropriately', async () => {
174
- // Arrange
175
- const mockError = new Error('API Error');
176
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(mockError);
177
-
178
- // Act & Assert
179
- await expect(gitDataProvider.GetTeamProjectGitReposList(mockTeamProject))
180
- .rejects.toThrow('API Error');
181
- });
182
- });
183
-
184
- describe('GitDataProvider - GetFileFromGitRepo', () => {
185
- let gitDataProvider: GitDataProvider;
186
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
187
- const mockToken = 'mock-token';
188
- const mockProjectName = 'project-123';
189
- const mockRepoId = 'repo-456';
190
- const mockFileName = 'README.md';
191
- const mockVersion = { version: 'main', versionType: 'branch' };
192
-
193
- beforeEach(() => {
194
- jest.clearAllMocks();
195
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
196
- });
197
-
198
- it('should return file content when file exists', async () => {
199
- // Arrange
200
- const mockContent = 'This is a test readme file';
201
- const mockResponse = { content: mockContent };
202
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
203
-
204
- // Act
205
- const result = await gitDataProvider.GetFileFromGitRepo(
206
- mockProjectName,
207
- mockRepoId,
208
- mockFileName,
209
- mockVersion
210
- );
211
-
212
- // Assert
213
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
214
- expect.stringContaining(`${mockOrgUrl}${mockProjectName}/_apis/git/repositories/${mockRepoId}/items`),
215
- mockToken,
216
- 'get',
217
- {},
218
- {},
219
- false
220
- );
221
- expect(result).toBe(mockContent);
222
- });
223
-
224
- it('should handle special characters in version by encoding them', async () => {
225
- // Arrange
226
- const specialVersion = { version: 'feature/branch#123', versionType: 'branch' };
227
- const mockResponse = { content: 'content' };
228
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
229
-
230
- // Act
231
- await gitDataProvider.GetFileFromGitRepo(
232
- mockProjectName,
233
- mockRepoId,
234
- mockFileName,
235
- specialVersion
236
- );
237
-
238
- // Assert
239
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
240
- expect.stringContaining('versionDescriptor.version=feature%2Fbranch%23123'),
241
- expect.anything(),
242
- expect.anything(),
243
- expect.anything(),
244
- expect.anything(),
245
- expect.anything()
246
- );
247
- });
248
-
249
- it('should use custom gitRepoUrl if provided', async () => {
250
- // Arrange
251
- const mockCustomUrl = 'https://custom.git.url';
252
- const mockResponse = { content: 'content' };
253
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
254
-
255
- // Act
256
- await gitDataProvider.GetFileFromGitRepo(
257
- mockProjectName,
258
- mockRepoId,
259
- mockFileName,
260
- mockVersion,
261
- mockCustomUrl
262
- );
263
-
264
- // Assert
265
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
266
- expect.stringContaining(mockCustomUrl),
267
- expect.anything(),
268
- expect.anything(),
269
- expect.anything(),
270
- expect.anything(),
271
- expect.anything()
272
- );
273
- });
274
-
275
- it('should return undefined when file does not exist', async () => {
276
- // Arrange
277
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce({});
278
-
279
- // Act
280
- const result = await gitDataProvider.GetFileFromGitRepo(
281
- mockProjectName,
282
- mockRepoId,
283
- mockFileName,
284
- mockVersion
285
- );
286
-
287
- // Assert
288
- expect(result).toBeUndefined();
289
- });
290
-
291
- it('should log warning and return undefined when error occurs', async () => {
292
- // Arrange
293
- const mockError = new Error('File not found');
294
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(mockError);
295
-
296
- // Act
297
- const result = await gitDataProvider.GetFileFromGitRepo(
298
- mockProjectName,
299
- mockRepoId,
300
- mockFileName,
301
- mockVersion
302
- );
303
-
304
- // Assert
305
- expect(logger.warn).toHaveBeenCalledWith(
306
- expect.stringContaining(`File ${mockFileName} could not be read: ${mockError.message}`)
307
- );
308
- expect(result).toBeUndefined();
309
- });
310
- });
311
-
312
- describe('GitDataProvider - CheckIfItemExist', () => {
313
- let gitDataProvider: GitDataProvider;
314
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
315
- const mockToken = 'mock-token';
316
- const mockGitApiUrl = 'https://dev.azure.com/orgname/project/_apis/git/repositories/repo-id';
317
- const mockItemPath = 'path/to/file.txt';
318
- const mockVersion = { version: 'main', versionType: 'branch' };
319
-
320
- beforeEach(() => {
321
- jest.clearAllMocks();
322
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
323
- });
324
-
325
- it('should return true when item exists', async () => {
326
- // Arrange
327
- const mockResponse = { path: mockItemPath, content: 'content' };
328
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
329
-
330
- // Act
331
- const result = await gitDataProvider.CheckIfItemExist(
332
- mockGitApiUrl,
333
- mockItemPath,
334
- mockVersion
335
- );
336
-
337
- // Assert
338
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
339
- expect.stringContaining(`${mockGitApiUrl}/items?path=${mockItemPath}`),
340
- mockToken,
341
- 'get',
342
- {},
343
- {},
344
- false
345
- );
346
- expect(result).toBe(true);
347
- });
348
-
349
- it('should return false when item does not exist', async () => {
350
- // Arrange
351
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(new Error('Not found'));
352
-
353
- // Act
354
- const result = await gitDataProvider.CheckIfItemExist(
355
- mockGitApiUrl,
356
- mockItemPath,
357
- mockVersion
358
- );
359
-
360
- // Assert
361
- expect(result).toBe(false);
362
- });
363
-
364
- it('should return false when API returns null', async () => {
365
- // Arrange
366
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(null);
367
-
368
- // Act
369
- const result = await gitDataProvider.CheckIfItemExist(
370
- mockGitApiUrl,
371
- mockItemPath,
372
- mockVersion
373
- );
374
-
375
- // Assert
376
- expect(result).toBe(false);
377
- });
378
-
379
- it('should handle special characters in version', async () => {
380
- // Arrange
381
- const specialVersion = { version: 'feature/branch#123', versionType: 'branch' };
382
- const mockResponse = { path: mockItemPath };
383
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
384
-
385
- // Act
386
- await gitDataProvider.CheckIfItemExist(
387
- mockGitApiUrl,
388
- mockItemPath,
389
- specialVersion
390
- );
391
-
392
- // Assert
393
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
394
- expect.stringContaining('versionDescriptor.version=feature%2Fbranch%23123'),
395
- expect.anything(),
396
- expect.anything(),
397
- expect.anything(),
398
- expect.anything(),
399
- expect.anything()
400
- );
401
- });
402
- });
403
-
404
- describe('GitDataProvider - GetPullRequestsInCommitRangeWithoutLinkedItems', () => {
405
- let gitDataProvider: GitDataProvider;
406
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
407
- const mockToken = 'mock-token';
408
- const mockProjectId = 'project-123';
409
- const mockRepoId = 'repo-456';
410
-
411
- beforeEach(() => {
412
- jest.clearAllMocks();
413
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
414
- });
415
-
416
- it('should return filtered pull requests matching commit ids', async () => {
417
- // Arrange
418
- const mockCommits = {
419
- value: [
420
- { commitId: 'commit-1' },
421
- { commitId: 'commit-2' }
422
- ]
423
- };
424
-
425
- const mockPullRequests = {
426
- count: 3,
427
- value: [
428
- {
429
- pullRequestId: 101,
430
- title: 'PR 1',
431
- createdBy: { displayName: 'User 1' },
432
- creationDate: '2023-01-01',
433
- closedDate: '2023-01-02',
434
- description: 'Description 1',
435
- lastMergeCommit: { commitId: 'commit-1' }
436
- },
437
- {
438
- pullRequestId: 102,
439
- title: 'PR 2',
440
- createdBy: { displayName: 'User 2' },
441
- creationDate: '2023-02-01',
442
- closedDate: '2023-02-02',
443
- description: 'Description 2',
444
- lastMergeCommit: { commitId: 'commit-3' } // Not in our commit range
445
- },
446
- {
447
- pullRequestId: 103,
448
- title: 'PR 3',
449
- createdBy: { displayName: 'User 3' },
450
- creationDate: '2023-03-01',
451
- closedDate: '2023-03-02',
452
- description: 'Description 3',
453
- lastMergeCommit: { commitId: 'commit-2' }
454
- }
455
- ]
456
- };
457
-
458
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockPullRequests);
459
-
460
- // Act
461
- const result = await gitDataProvider.GetPullRequestsInCommitRangeWithoutLinkedItems(
462
- mockProjectId,
463
- mockRepoId,
464
- mockCommits
465
- );
466
-
467
- // Assert
468
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
469
- expect.stringContaining(`${mockOrgUrl}${mockProjectId}/_apis/git/repositories/${mockRepoId}/pullrequests`),
470
- mockToken,
471
- 'get'
472
- );
473
- expect(result).toHaveLength(2);
474
- expect(result[0].pullRequestId).toBe(101);
475
- expect(result[1].pullRequestId).toBe(103);
476
- expect(logger.info).toHaveBeenCalledWith(
477
- expect.stringContaining('filtered in commit range 2 pullrequests')
478
- );
479
- });
480
-
481
- it('should return empty array when no matching pull requests', async () => {
482
- // Arrange
483
- const mockCommits = {
484
- value: [
485
- { commitId: 'commit-999' } // Not matching any PRs
486
- ]
487
- };
488
-
489
- const mockPullRequests = {
490
- count: 2,
491
- value: [
492
- {
493
- pullRequestId: 101,
494
- lastMergeCommit: { commitId: 'commit-1' }
495
- },
496
- {
497
- pullRequestId: 102,
498
- lastMergeCommit: { commitId: 'commit-2' }
499
- }
500
- ]
501
- };
502
-
503
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockPullRequests);
504
-
505
- // Act
506
- const result = await gitDataProvider.GetPullRequestsInCommitRangeWithoutLinkedItems(
507
- mockProjectId,
508
- mockRepoId,
509
- mockCommits
510
- );
511
-
512
- // Assert
513
- expect(result).toHaveLength(0);
514
- });
515
-
516
- it('should handle API errors appropriately', async () => {
517
- // Arrange
518
- const mockCommits = { value: [{ commitId: 'commit-1' }] };
519
- const mockError = new Error('API Error');
520
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(mockError);
521
-
522
- // Act & Assert
523
- await expect(gitDataProvider.GetPullRequestsInCommitRangeWithoutLinkedItems(
524
- mockProjectId,
525
- mockRepoId,
526
- mockCommits
527
- )).rejects.toThrow('API Error');
528
- });
529
- });
530
-
531
- describe('GitDataProvider - GetRepoReferences', () => {
532
- let gitDataProvider: GitDataProvider;
533
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
534
- const mockToken = 'mock-token';
535
- const mockProjectId = 'project-123';
536
- const mockRepoId = 'repo-456';
537
-
538
- beforeEach(() => {
539
- jest.clearAllMocks();
540
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
541
- });
542
-
543
- it('should return formatted tags when gitObjectType is "tag"', async () => {
544
- // Arrange
545
- const mockTags = {
546
- count: 2,
547
- value: [
548
- { name: 'refs/tags/v1.0.0', objectId: 'tag-1' },
549
- { name: 'refs/tags/v2.0.0', objectId: 'tag-2' }
550
- ]
551
- };
552
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockTags);
553
-
554
- // Act
555
- const result = await gitDataProvider.GetRepoReferences(
556
- mockProjectId,
557
- mockRepoId,
558
- 'tag'
559
- );
560
-
561
- // Assert
562
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
563
- `${mockOrgUrl}${mockProjectId}/_apis/git/repositories/${mockRepoId}/refs/tags?api-version=5.1`,
564
- mockToken,
565
- 'get'
566
- );
567
- expect(result).toHaveLength(2);
568
- expect(result[0].name).toBe('v1.0.0');
569
- expect(result[0].value).toBe('refs/tags/v1.0.0');
570
- expect(result[1].name).toBe('v2.0.0');
571
- expect(result[1].value).toBe('refs/tags/v2.0.0');
572
- });
573
-
574
- it('should return formatted branches when gitObjectType is "branch"', async () => {
575
- // Arrange
576
- const mockBranches = {
577
- count: 2,
578
- value: [
579
- { name: 'refs/heads/main', objectId: 'branch-1' },
580
- { name: 'refs/heads/develop', objectId: 'branch-2' }
581
- ]
582
- };
583
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockBranches);
584
-
585
- // Act
586
- const result = await gitDataProvider.GetRepoReferences(
587
- mockProjectId,
588
- mockRepoId,
589
- 'branch'
590
- );
591
-
592
- // Assert
593
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
594
- `${mockOrgUrl}${mockProjectId}/_apis/git/repositories/${mockRepoId}/refs/heads?api-version=5.1`,
595
- mockToken,
596
- 'get'
597
- );
598
- expect(result).toHaveLength(2);
599
- expect(result[0].name).toBe('main');
600
- expect(result[0].value).toBe('refs/heads/main');
601
- expect(result[1].name).toBe('develop');
602
- expect(result[1].value).toBe('refs/heads/develop');
603
- });
604
-
605
- it('should throw error for unsupported git object type', async () => {
606
- // Act & Assert
607
- await expect(gitDataProvider.GetRepoReferences(
608
- mockProjectId,
609
- mockRepoId,
610
- 'invalid-type'
611
- )).rejects.toThrow('Unsupported git object type: invalid-type');
612
- });
613
-
614
- it('should return empty array when no references exist', async () => {
615
- // Arrange
616
- const mockEmptyRefs = { count: 0, value: [] };
617
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockEmptyRefs);
618
-
619
- // Act
620
- const result = await gitDataProvider.GetRepoReferences(
621
- mockProjectId,
622
- mockRepoId,
623
- 'branch'
624
- );
625
-
626
- // Assert
627
- expect(result).toEqual([]);
628
- });
629
- });
630
-
631
- describe('GitDataProvider - GetJsonFileFromGitRepo', () => {
632
- let gitDataProvider: GitDataProvider;
633
- const mockOrgUrl = 'https://dev.azure.com/orgname/';
634
- const mockToken = 'mock-token';
635
- const mockProjectName = 'project-123';
636
- const mockRepoName = 'repo-456';
637
- const mockFilePath = 'config/settings.json';
638
-
639
- beforeEach(() => {
640
- jest.clearAllMocks();
641
- gitDataProvider = new GitDataProvider(mockOrgUrl, mockToken);
642
- });
643
-
644
- it('should parse and return JSON content when file exists', async () => {
645
- // Arrange
646
- const mockJsonContent = { setting1: 'value1', setting2: 'value2' };
647
- const mockResponse = { content: JSON.stringify(mockJsonContent) };
648
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
649
-
650
- // Act
651
- const result = await gitDataProvider.GetJsonFileFromGitRepo(
652
- mockProjectName,
653
- mockRepoName,
654
- mockFilePath
655
- );
656
-
657
- // Assert
658
- expect(TFSServices.getItemContent).toHaveBeenCalledWith(
659
- `${mockOrgUrl}${mockProjectName}/_apis/git/repositories/${mockRepoName}/items?path=${mockFilePath}&includeContent=true`,
660
- mockToken,
661
- 'get'
662
- );
663
- expect(result).toEqual(mockJsonContent);
664
- });
665
-
666
- it('should throw an error for invalid JSON content', async () => {
667
- // Arrange
668
- const mockInvalidJson = { content: '{ invalid json' };
669
- (TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockInvalidJson);
670
-
671
- // Act & Assert
672
- await expect(gitDataProvider.GetJsonFileFromGitRepo(
673
- mockProjectName,
674
- mockRepoName,
675
- mockFilePath
676
- )).rejects.toThrow(SyntaxError);
677
- });
678
-
679
- it('should handle API errors appropriately', async () => {
680
- // Arrange
681
- const mockError = new Error('API Error');
682
- (TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(mockError);
683
-
684
- // Act & Assert
685
- await expect(gitDataProvider.GetJsonFileFromGitRepo(
686
- mockProjectName,
687
- mockRepoName,
688
- mockFilePath
689
- )).rejects.toThrow('API Error');
690
- });
691
- });