@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import logger from '../utils/logger';
|
|
2
|
+
|
|
3
|
+
jest.mock('../utils/logger');
|
|
4
|
+
|
|
5
|
+
describe('src/index.ts', () => {
|
|
6
|
+
it('should construct providers and create module providers', async () => {
|
|
7
|
+
const { default: DgDataProviderAzureDevOps } = await import('../index');
|
|
8
|
+
const provider = new DgDataProviderAzureDevOps('https://dev.azure.com/org/', 'token', '5.1', 'jfrog');
|
|
9
|
+
|
|
10
|
+
expect(logger.info).toHaveBeenCalled();
|
|
11
|
+
|
|
12
|
+
await expect(provider.getMangementDataProvider()).resolves.toBeDefined();
|
|
13
|
+
await expect(provider.getTicketsDataProvider()).resolves.toBeDefined();
|
|
14
|
+
await expect(provider.getGitDataProvider()).resolves.toBeDefined();
|
|
15
|
+
await expect(provider.getPipelinesDataProvider()).resolves.toBeDefined();
|
|
16
|
+
await expect(provider.getTestDataProvider()).resolves.toBeDefined();
|
|
17
|
+
await expect(provider.getResultDataProvider()).resolves.toBeDefined();
|
|
18
|
+
await expect(provider.getJfrogDataProvider()).resolves.toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should default jfrogToken to empty string when undefined', async () => {
|
|
22
|
+
const { default: DgDataProviderAzureDevOps } = await import('../index');
|
|
23
|
+
const provider = new DgDataProviderAzureDevOps('https://dev.azure.com/org/', 'token', '5.1');
|
|
24
|
+
|
|
25
|
+
const jfrog = await provider.getJfrogDataProvider();
|
|
26
|
+
expect(jfrog).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Query,
|
|
3
|
+
QueryTree,
|
|
4
|
+
Column,
|
|
5
|
+
Workitem,
|
|
6
|
+
value,
|
|
7
|
+
QueryType,
|
|
8
|
+
TestCase,
|
|
9
|
+
TestSteps,
|
|
10
|
+
createLinkedRelation,
|
|
11
|
+
createRequirementRelation,
|
|
12
|
+
createMomRelation,
|
|
13
|
+
createBugRelation,
|
|
14
|
+
LinkedRelation,
|
|
15
|
+
} from '../../models/tfs-data';
|
|
16
|
+
|
|
17
|
+
describe('tfs-data models', () => {
|
|
18
|
+
describe('Query class', () => {
|
|
19
|
+
it('should create Query with default arrays', () => {
|
|
20
|
+
const query = new Query();
|
|
21
|
+
expect(query.columns).toEqual([]);
|
|
22
|
+
expect(query.workItems).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('Column class', () => {
|
|
27
|
+
it('should create Column with properties', () => {
|
|
28
|
+
const column = new Column();
|
|
29
|
+
column.referenceName = 'System.Title';
|
|
30
|
+
column.name = 'Title';
|
|
31
|
+
column.url = 'https://example.com';
|
|
32
|
+
|
|
33
|
+
expect(column.referenceName).toBe('System.Title');
|
|
34
|
+
expect(column.name).toBe('Title');
|
|
35
|
+
expect(column.url).toBe('https://example.com');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('Workitem class', () => {
|
|
40
|
+
it('should create Workitem with default Source of 0', () => {
|
|
41
|
+
const workitem = new Workitem();
|
|
42
|
+
expect(workitem.Source).toBe(0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should allow setting all properties', () => {
|
|
46
|
+
const workitem = new Workitem();
|
|
47
|
+
workitem.id = 123;
|
|
48
|
+
workitem.url = 'https://example.com/workitem/123';
|
|
49
|
+
workitem.parentId = 100;
|
|
50
|
+
workitem.fields = [];
|
|
51
|
+
workitem.attachments = [];
|
|
52
|
+
workitem.level = 1;
|
|
53
|
+
|
|
54
|
+
expect(workitem.id).toBe(123);
|
|
55
|
+
expect(workitem.url).toBe('https://example.com/workitem/123');
|
|
56
|
+
expect(workitem.parentId).toBe(100);
|
|
57
|
+
expect(workitem.level).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('value class', () => {
|
|
62
|
+
it('should create value with name and value', () => {
|
|
63
|
+
const v = new value();
|
|
64
|
+
v.name = 'Title';
|
|
65
|
+
v.value = 'Test Value';
|
|
66
|
+
|
|
67
|
+
expect(v.name).toBe('Title');
|
|
68
|
+
expect(v.value).toBe('Test Value');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('TestCase class', () => {
|
|
73
|
+
it('should create TestCase with empty relations array', () => {
|
|
74
|
+
const testCase = new TestCase();
|
|
75
|
+
expect(testCase.relations).toEqual([]);
|
|
76
|
+
expect(testCase.caseEvidenceAttachments).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should allow setting all properties', () => {
|
|
80
|
+
const testCase = new TestCase();
|
|
81
|
+
testCase.id = '123';
|
|
82
|
+
testCase.title = 'Test Case Title';
|
|
83
|
+
testCase.description = 'Test Description';
|
|
84
|
+
testCase.area = 'Area\\Path';
|
|
85
|
+
testCase.steps = [];
|
|
86
|
+
testCase.suit = 'Suite 1';
|
|
87
|
+
testCase.url = 'https://example.com/testcase/123';
|
|
88
|
+
|
|
89
|
+
expect(testCase.id).toBe('123');
|
|
90
|
+
expect(testCase.title).toBe('Test Case Title');
|
|
91
|
+
expect(testCase.description).toBe('Test Description');
|
|
92
|
+
expect(testCase.area).toBe('Area\\Path');
|
|
93
|
+
expect(testCase.suit).toBe('Suite 1');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('TestSteps class', () => {
|
|
98
|
+
it('should create TestSteps with all properties', () => {
|
|
99
|
+
const step = new TestSteps();
|
|
100
|
+
step.stepId = '1';
|
|
101
|
+
step.stepPosition = '1';
|
|
102
|
+
step.action = 'Click button';
|
|
103
|
+
step.expected = 'Button clicked';
|
|
104
|
+
step.isSharedStepTitle = false;
|
|
105
|
+
|
|
106
|
+
expect(step.stepId).toBe('1');
|
|
107
|
+
expect(step.stepPosition).toBe('1');
|
|
108
|
+
expect(step.action).toBe('Click button');
|
|
109
|
+
expect(step.expected).toBe('Button clicked');
|
|
110
|
+
expect(step.isSharedStepTitle).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('createLinkedRelation', () => {
|
|
115
|
+
it('should create a LinkedRelation object', () => {
|
|
116
|
+
const result = createLinkedRelation(
|
|
117
|
+
'123',
|
|
118
|
+
'Requirement',
|
|
119
|
+
'Test Requirement',
|
|
120
|
+
'https://example.com/wi/123',
|
|
121
|
+
'Parent'
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
expect(result).toEqual({
|
|
125
|
+
id: '123',
|
|
126
|
+
wiType: 'Requirement',
|
|
127
|
+
title: 'Test Requirement',
|
|
128
|
+
url: 'https://example.com/wi/123',
|
|
129
|
+
relationType: 'Parent',
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('createRequirementRelation', () => {
|
|
135
|
+
it('should create a RequirementRelation with customerId', () => {
|
|
136
|
+
const result = createRequirementRelation('123', 'Requirement Title', 'CUST-001');
|
|
137
|
+
|
|
138
|
+
expect(result).toEqual({
|
|
139
|
+
type: 'requirement',
|
|
140
|
+
id: '123',
|
|
141
|
+
title: 'Requirement Title',
|
|
142
|
+
customerId: 'CUST-001',
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should create a RequirementRelation without customerId', () => {
|
|
147
|
+
const result = createRequirementRelation('123', 'Requirement Title');
|
|
148
|
+
|
|
149
|
+
expect(result).toEqual({
|
|
150
|
+
type: 'requirement',
|
|
151
|
+
id: '123',
|
|
152
|
+
title: 'Requirement Title',
|
|
153
|
+
customerId: undefined,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('createMomRelation', () => {
|
|
159
|
+
it('should create a MomRelation object', () => {
|
|
160
|
+
const result = createMomRelation('123', 'Bug', 'Bug Title', 'https://example.com/wi/123', 'Active');
|
|
161
|
+
|
|
162
|
+
expect(result).toEqual({
|
|
163
|
+
type: 'Bug',
|
|
164
|
+
id: '123',
|
|
165
|
+
title: 'Bug Title',
|
|
166
|
+
url: 'https://example.com/wi/123',
|
|
167
|
+
status: 'Active',
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('createBugRelation', () => {
|
|
173
|
+
it('should create a BugRelation with severity', () => {
|
|
174
|
+
const result = createBugRelation('123', 'Bug Title', '1 - Critical');
|
|
175
|
+
|
|
176
|
+
expect(result).toEqual({
|
|
177
|
+
type: 'bug',
|
|
178
|
+
id: '123',
|
|
179
|
+
title: 'Bug Title',
|
|
180
|
+
severity: '1 - Critical',
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should create a BugRelation without severity', () => {
|
|
185
|
+
const result = createBugRelation('123', 'Bug Title');
|
|
186
|
+
|
|
187
|
+
expect(result).toEqual({
|
|
188
|
+
type: 'bug',
|
|
189
|
+
id: '123',
|
|
190
|
+
title: 'Bug Title',
|
|
191
|
+
severity: undefined,
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('QueryType enum', () => {
|
|
197
|
+
it('should have correct enum values', () => {
|
|
198
|
+
expect(QueryType.Flat).toBe('flat');
|
|
199
|
+
expect(QueryType.Tree).toBe('tree');
|
|
200
|
+
expect(QueryType.OneHop).toBe('oneHop');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { TFSServices } from '../../helpers/tfs';
|
|
2
|
+
import logger from '../../utils/logger';
|
|
3
|
+
import JfrogDataProvider from '../../modules/JfrogDataProvider';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../helpers/tfs');
|
|
6
|
+
jest.mock('../../utils/logger');
|
|
7
|
+
|
|
8
|
+
describe('JfrogDataProvider', () => {
|
|
9
|
+
let jfrogDataProvider: JfrogDataProvider;
|
|
10
|
+
const mockOrgUrl = 'https://dev.azure.com/organization/';
|
|
11
|
+
const mockTfsToken = 'mock-tfs-token';
|
|
12
|
+
const mockJfrogToken = 'mock-jfrog-token';
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
jfrogDataProvider = new JfrogDataProvider(mockOrgUrl, mockTfsToken, mockJfrogToken);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('getServiceConnectionUrlByConnectionId', () => {
|
|
20
|
+
it('should fetch service connection URL with correct parameters', async () => {
|
|
21
|
+
// Arrange
|
|
22
|
+
const mockTeamProject = 'test-project';
|
|
23
|
+
const mockConnectionId = 'connection-123';
|
|
24
|
+
const mockResponse = { url: 'https://jfrog.example.com' };
|
|
25
|
+
|
|
26
|
+
(TFSServices.getItemContent as jest.Mock).mockResolvedValueOnce(mockResponse);
|
|
27
|
+
|
|
28
|
+
// Act
|
|
29
|
+
const result = await jfrogDataProvider.getServiceConnectionUrlByConnectionId(
|
|
30
|
+
mockTeamProject,
|
|
31
|
+
mockConnectionId
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Assert
|
|
35
|
+
expect(TFSServices.getItemContent).toHaveBeenCalledWith(
|
|
36
|
+
`${mockOrgUrl}${mockTeamProject}/_apis/serviceendpoint/endpoints/${mockConnectionId}?api-version=6`,
|
|
37
|
+
mockTfsToken
|
|
38
|
+
);
|
|
39
|
+
expect(logger.debug).toHaveBeenCalledWith(`service connection url "${mockResponse.url}"`);
|
|
40
|
+
expect(result).toBe(mockResponse.url);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should propagate errors when API call fails', async () => {
|
|
44
|
+
// Arrange
|
|
45
|
+
const mockTeamProject = 'test-project';
|
|
46
|
+
const mockConnectionId = 'connection-123';
|
|
47
|
+
const mockError = new Error('API error');
|
|
48
|
+
|
|
49
|
+
(TFSServices.getItemContent as jest.Mock).mockRejectedValueOnce(mockError);
|
|
50
|
+
|
|
51
|
+
// Act & Assert
|
|
52
|
+
await expect(
|
|
53
|
+
jfrogDataProvider.getServiceConnectionUrlByConnectionId(mockTeamProject, mockConnectionId)
|
|
54
|
+
).rejects.toThrow('API error');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('getCiDataFromJfrog', () => {
|
|
59
|
+
it('should fetch JFrog data with token and format URLs correctly', async () => {
|
|
60
|
+
// Arrange
|
|
61
|
+
const mockJfrogUrl = 'https://jfrog.example.com';
|
|
62
|
+
const mockBuildName = 'build-name';
|
|
63
|
+
const mockBuildVersion = 'version-1.0';
|
|
64
|
+
const mockResponse = {
|
|
65
|
+
buildInfo: {
|
|
66
|
+
url: 'https://ci.example.com/build/123',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
(TFSServices.getJfrogRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
|
71
|
+
|
|
72
|
+
// Act
|
|
73
|
+
const result = await jfrogDataProvider.getCiDataFromJfrog(
|
|
74
|
+
mockJfrogUrl,
|
|
75
|
+
mockBuildName,
|
|
76
|
+
mockBuildVersion
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Assert
|
|
80
|
+
expect(TFSServices.getJfrogRequest).toHaveBeenCalledWith(
|
|
81
|
+
`${mockJfrogUrl}/api/build/${mockBuildName}/${mockBuildVersion}`,
|
|
82
|
+
{ Authorization: `Bearer ${mockJfrogToken}` }
|
|
83
|
+
);
|
|
84
|
+
expect(logger.info).toHaveBeenCalledWith(
|
|
85
|
+
`Querying Jfrog using url ${mockJfrogUrl}/api/build/${mockBuildName}/${mockBuildVersion}`
|
|
86
|
+
);
|
|
87
|
+
expect(logger.debug).toHaveBeenCalledWith(`CI Url from JFROG: ${mockResponse.buildInfo.url}`);
|
|
88
|
+
expect(result).toBe(mockResponse.buildInfo.url);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle build names and versions that already start with /', async () => {
|
|
92
|
+
// Arrange
|
|
93
|
+
const mockJfrogUrl = 'https://jfrog.example.com';
|
|
94
|
+
const mockBuildName = '/build-name';
|
|
95
|
+
const mockBuildVersion = '/version-1.0';
|
|
96
|
+
const mockResponse = {
|
|
97
|
+
buildInfo: {
|
|
98
|
+
url: 'https://ci.example.com/build/123',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
(TFSServices.getJfrogRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
|
103
|
+
|
|
104
|
+
// Act
|
|
105
|
+
const result = await jfrogDataProvider.getCiDataFromJfrog(
|
|
106
|
+
mockJfrogUrl,
|
|
107
|
+
mockBuildName,
|
|
108
|
+
mockBuildVersion
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Assert
|
|
112
|
+
expect(TFSServices.getJfrogRequest).toHaveBeenCalledWith(
|
|
113
|
+
`${mockJfrogUrl}/api/build${mockBuildName}${mockBuildVersion}`,
|
|
114
|
+
{ Authorization: `Bearer ${mockJfrogToken}` }
|
|
115
|
+
);
|
|
116
|
+
expect(result).toBe(mockResponse.buildInfo.url);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should make request without token when jfrogToken is empty', async () => {
|
|
120
|
+
// Arrange
|
|
121
|
+
const mockJfrogUrl = 'https://jfrog.example.com';
|
|
122
|
+
const mockBuildName = 'build-name';
|
|
123
|
+
const mockBuildVersion = 'version-1.0';
|
|
124
|
+
const mockResponse = {
|
|
125
|
+
buildInfo: {
|
|
126
|
+
url: 'https://ci.example.com/build/123',
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Create provider with empty jfrog token
|
|
131
|
+
const jfrogDataProviderNoToken = new JfrogDataProvider(mockOrgUrl, mockTfsToken, '');
|
|
132
|
+
(TFSServices.getJfrogRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
|
133
|
+
|
|
134
|
+
// Act
|
|
135
|
+
const result = await jfrogDataProviderNoToken.getCiDataFromJfrog(
|
|
136
|
+
mockJfrogUrl,
|
|
137
|
+
mockBuildName,
|
|
138
|
+
mockBuildVersion
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Assert
|
|
142
|
+
expect(TFSServices.getJfrogRequest).toHaveBeenCalledWith(
|
|
143
|
+
`${mockJfrogUrl}/api/build/${mockBuildName}/${mockBuildVersion}`
|
|
144
|
+
);
|
|
145
|
+
expect(result).toBe(mockResponse.buildInfo.url);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should log and rethrow errors from JFrog API', async () => {
|
|
149
|
+
// Arrange
|
|
150
|
+
const mockJfrogUrl = 'https://jfrog.example.com';
|
|
151
|
+
const mockBuildName = 'build-name';
|
|
152
|
+
const mockBuildVersion = 'version-1.0';
|
|
153
|
+
const mockError = new Error('JFrog API error');
|
|
154
|
+
|
|
155
|
+
(TFSServices.getJfrogRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
|
156
|
+
|
|
157
|
+
// Act & Assert
|
|
158
|
+
await expect(
|
|
159
|
+
jfrogDataProvider.getCiDataFromJfrog(mockJfrogUrl, mockBuildName, mockBuildVersion)
|
|
160
|
+
).rejects.toThrow('JFrog API error');
|
|
161
|
+
|
|
162
|
+
expect(logger.error).toHaveBeenCalledWith(
|
|
163
|
+
`Error occurred during querying JFrog using: JFrog API error`
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|