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