@elisra-devops/docgen-data-provider 0.4.6
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/sonar-project.properties +5 -0
- package/.github/workflows/ci.yml +21 -0
- package/.github/workflows/release.yml +40 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/enviroment.d.ts +12 -0
- package/package.json +53 -0
- package/src/helpers/helper.ts +117 -0
- package/src/helpers/tfs.ts +92 -0
- package/src/index.ts +36 -0
- package/src/models/tfs-data.ts +137 -0
- package/src/modules/GitDataProvider.ts +446 -0
- package/src/modules/MangementDataProvider.ts +59 -0
- package/src/modules/PipelinesDataProvider.ts +142 -0
- package/src/modules/TestDataProvider.ts +423 -0
- package/src/modules/TicketsDataProvider.ts +435 -0
- package/src/modules/test/gitDataProvider.test.ts +207 -0
- package/src/modules/test/managmentDataProvider.test.ts +34 -0
- package/src/modules/test/pipelineDataProvider.test.ts +80 -0
- package/src/modules/test/testDataProvider.test.ts +140 -0
- package/src/modules/test/ticketsDataProvider.test.ts +138 -0
- package/src/utils/logger.ts +37 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { TFSServices } from "../helpers/tfs";
|
|
2
|
+
import { Workitem } from "../models/tfs-data";
|
|
3
|
+
import { Helper, suiteData, Links, Trace, Relations } from "../helpers/helper";
|
|
4
|
+
import { Query, TestSteps } from "../models/tfs-data";
|
|
5
|
+
import { QueryType } from "../models/tfs-data";
|
|
6
|
+
import { QueryAllTypes } from "../models/tfs-data";
|
|
7
|
+
import { Column } from "../models/tfs-data";
|
|
8
|
+
import { value } from "../models/tfs-data";
|
|
9
|
+
import { TestCase } from "../models/tfs-data";
|
|
10
|
+
import * as xml2js from "xml2js";
|
|
11
|
+
|
|
12
|
+
import logger from "../utils/logger";
|
|
13
|
+
|
|
14
|
+
export default class TestDataProvider {
|
|
15
|
+
orgUrl: string = "";
|
|
16
|
+
token: string = "";
|
|
17
|
+
|
|
18
|
+
constructor(orgUrl: string, token: string) {
|
|
19
|
+
this.orgUrl = orgUrl;
|
|
20
|
+
this.token = token;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async GetTestSuiteByTestCase(
|
|
24
|
+
testCaseId: string
|
|
25
|
+
): Promise<any> {
|
|
26
|
+
let url = `${this.orgUrl}/_apis/testplan/suites?testCaseId=${testCaseId}`;
|
|
27
|
+
let testCaseData = await TFSServices.getItemContent(url, this.token);
|
|
28
|
+
return testCaseData;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//get all test plans in the project
|
|
32
|
+
async GetTestPlans(
|
|
33
|
+
project: string
|
|
34
|
+
): Promise<string> {
|
|
35
|
+
let testPlanUrl: string = `${this.orgUrl}${project}/_apis/test/plans`;
|
|
36
|
+
return TFSServices.getItemContent(testPlanUrl,this.token);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// get all test suits in projct test plan
|
|
40
|
+
async GetTestSuites(
|
|
41
|
+
project: string,
|
|
42
|
+
planId: string
|
|
43
|
+
): Promise<any> {
|
|
44
|
+
let testsuitesUrl: string =
|
|
45
|
+
this.orgUrl + project + "/_apis/test/Plans/" + planId + "/suites";
|
|
46
|
+
try {
|
|
47
|
+
let testSuites = await TFSServices.getItemContent(
|
|
48
|
+
testsuitesUrl,
|
|
49
|
+
this.token
|
|
50
|
+
);
|
|
51
|
+
return testSuites;
|
|
52
|
+
} catch (e) {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async GetTestSuitesForPlan(
|
|
56
|
+
project: string,
|
|
57
|
+
planid: string
|
|
58
|
+
): Promise<any> {
|
|
59
|
+
let url =
|
|
60
|
+
this.orgUrl +
|
|
61
|
+
"/" +
|
|
62
|
+
project +
|
|
63
|
+
"/_api/_testManagement/GetTestSuitesForPlan?__v=5&planId=" +
|
|
64
|
+
planid;
|
|
65
|
+
let suites = await TFSServices.getItemContent(url, this.token);
|
|
66
|
+
return suites;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async GetTestSuitesByPlan(
|
|
70
|
+
project: string,
|
|
71
|
+
planId: string,
|
|
72
|
+
recursive: boolean
|
|
73
|
+
): Promise<any> {
|
|
74
|
+
let suiteId = Number(planId) + 1;
|
|
75
|
+
let suites = await this.GetTestSuiteById(
|
|
76
|
+
project,
|
|
77
|
+
planId,
|
|
78
|
+
suiteId.toString(),
|
|
79
|
+
recursive
|
|
80
|
+
);
|
|
81
|
+
return suites;
|
|
82
|
+
}
|
|
83
|
+
//gets all testsuits recorsivly under test suite
|
|
84
|
+
|
|
85
|
+
async GetTestSuiteById(
|
|
86
|
+
project: string,
|
|
87
|
+
planId: string,
|
|
88
|
+
suiteId: string,
|
|
89
|
+
recursive: boolean
|
|
90
|
+
): Promise<any> {
|
|
91
|
+
let testSuites = await this.GetTestSuitesForPlan(project, planId);
|
|
92
|
+
// GetTestSuites(project, planId);
|
|
93
|
+
Helper.suitList = [];
|
|
94
|
+
Helper.level = 1;
|
|
95
|
+
let dataSuites: any = Helper.findSuitesRecursive(
|
|
96
|
+
planId,
|
|
97
|
+
this.orgUrl,
|
|
98
|
+
project,
|
|
99
|
+
testSuites.testSuites,
|
|
100
|
+
suiteId,
|
|
101
|
+
recursive
|
|
102
|
+
);
|
|
103
|
+
Helper.first = true;
|
|
104
|
+
// let levledSuites: any = Helper.buildSuiteslevel(dataSuites);
|
|
105
|
+
|
|
106
|
+
return dataSuites;
|
|
107
|
+
}
|
|
108
|
+
//gets all testcase under test suite acording to recursive flag
|
|
109
|
+
|
|
110
|
+
async GetTestCasesBySuites(
|
|
111
|
+
project: string,
|
|
112
|
+
planId: string,
|
|
113
|
+
suiteId: string,
|
|
114
|
+
recursiv: boolean
|
|
115
|
+
): Promise<Array<any>> {
|
|
116
|
+
let testCasesList: Array<any> = new Array<any>();
|
|
117
|
+
let suitesTestCasesList: Array<suiteData> = await this.GetTestSuiteById(
|
|
118
|
+
project,
|
|
119
|
+
planId,
|
|
120
|
+
suiteId,
|
|
121
|
+
recursiv
|
|
122
|
+
);
|
|
123
|
+
for (let i = 0; i < suitesTestCasesList.length; i++) {
|
|
124
|
+
let testCases: any = await this.GetTestCases(
|
|
125
|
+
project,
|
|
126
|
+
planId,
|
|
127
|
+
suitesTestCasesList[i].id
|
|
128
|
+
);
|
|
129
|
+
let testCseseWithSteps: any = await this.StructureTestCase(
|
|
130
|
+
project,
|
|
131
|
+
testCases,
|
|
132
|
+
suitesTestCasesList[i]
|
|
133
|
+
);
|
|
134
|
+
if (testCseseWithSteps.length > 0)
|
|
135
|
+
testCasesList = [...testCasesList, ...testCseseWithSteps];
|
|
136
|
+
}
|
|
137
|
+
return testCasesList;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async StructureTestCase(
|
|
141
|
+
project: string,
|
|
142
|
+
testCases: any,
|
|
143
|
+
suite: suiteData
|
|
144
|
+
): Promise<Array<any>> {
|
|
145
|
+
let url = this.orgUrl + project + "/_workitems/edit/";
|
|
146
|
+
let testCasesUrlList: Array<any> = new Array<any>();
|
|
147
|
+
//let tesrCase:TestCase;
|
|
148
|
+
for (let i = 0; i < testCases.count; i++) {
|
|
149
|
+
try{
|
|
150
|
+
let test: any = await TFSServices.getItemContent(
|
|
151
|
+
testCases.value[i].testCase.url,
|
|
152
|
+
this.token
|
|
153
|
+
);
|
|
154
|
+
let testCase: TestCase = new TestCase();
|
|
155
|
+
testCase.title = test.fields["System.Title"];
|
|
156
|
+
testCase.area = test.fields["System.AreaPath"];
|
|
157
|
+
testCase.description = test.fields["System.Description"];
|
|
158
|
+
testCase.url = url + test.id;
|
|
159
|
+
//testCase.steps = test.fields["Microsoft.VSTS.TCM.Steps"];
|
|
160
|
+
testCase.id = test.id;
|
|
161
|
+
testCase.suit = suite.id;
|
|
162
|
+
if (test.fields["Microsoft.VSTS.TCM.Steps"] != null) {
|
|
163
|
+
let steps: Array<TestSteps> = this.ParseSteps(
|
|
164
|
+
test.fields["Microsoft.VSTS.TCM.Steps"]
|
|
165
|
+
);
|
|
166
|
+
testCase.steps = steps;
|
|
167
|
+
}
|
|
168
|
+
testCasesUrlList.push(testCase);
|
|
169
|
+
}
|
|
170
|
+
catch{
|
|
171
|
+
logger.error(`ran into an issue while retriving testCase ${testCases.value[i].testCase.id}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return testCasesUrlList;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
ParseSteps(
|
|
179
|
+
steps: string
|
|
180
|
+
) {
|
|
181
|
+
let stepsLsist: Array<TestSteps> = new Array<TestSteps>();
|
|
182
|
+
const start: string = ";P>";
|
|
183
|
+
const end: string = "</P";
|
|
184
|
+
let totalString: String = steps;
|
|
185
|
+
xml2js.parseString(steps, function (err, result) {
|
|
186
|
+
if (err) console.log(err);
|
|
187
|
+
if (result.steps.step != null)
|
|
188
|
+
for (let i = 0; i < result.steps.step.length; i++) {
|
|
189
|
+
let step: TestSteps = new TestSteps();
|
|
190
|
+
try {
|
|
191
|
+
if (result.steps.step[i].parameterizedString[0]._ != null)
|
|
192
|
+
step.action = result.steps.step[
|
|
193
|
+
i
|
|
194
|
+
].parameterizedString[0]._
|
|
195
|
+
} catch (e) {
|
|
196
|
+
logger.warn(`No test step action data to parse for testcase `);
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
if (result.steps.step[i].parameterizedString[1]._ != null)
|
|
200
|
+
step.expected = result.steps.step[
|
|
201
|
+
i
|
|
202
|
+
].parameterizedString[1]._
|
|
203
|
+
} catch (e) {
|
|
204
|
+
logger.warn(`No test step expected data to parse for testcase `);
|
|
205
|
+
}
|
|
206
|
+
stepsLsist.push(step);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return stepsLsist;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async GetTestCases(
|
|
214
|
+
project: string,
|
|
215
|
+
planId: string,
|
|
216
|
+
suiteId: string
|
|
217
|
+
): Promise<any> {
|
|
218
|
+
let testCaseUrl: string =
|
|
219
|
+
this.orgUrl +
|
|
220
|
+
project +
|
|
221
|
+
"/_apis/test/Plans/" +
|
|
222
|
+
planId +
|
|
223
|
+
"/suites/" +
|
|
224
|
+
suiteId +
|
|
225
|
+
"/testcases/";
|
|
226
|
+
let testCases: any = await TFSServices.getItemContent(
|
|
227
|
+
testCaseUrl,
|
|
228
|
+
this.token
|
|
229
|
+
);
|
|
230
|
+
return testCases;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//gets all test point in a test case
|
|
234
|
+
async GetTestPoint(
|
|
235
|
+
project: string,
|
|
236
|
+
planId: string,
|
|
237
|
+
suiteId: string,
|
|
238
|
+
testCaseId: string
|
|
239
|
+
): Promise<any> {
|
|
240
|
+
let testPointUrl: string =
|
|
241
|
+
`${this.orgUrl}${project}/_apis/test/Plans/${planId}/Suites/${suiteId}/points?testCaseId=${testCaseId}`;
|
|
242
|
+
let testPoints: any = await TFSServices.getItemContent(
|
|
243
|
+
testPointUrl,
|
|
244
|
+
this.token
|
|
245
|
+
);
|
|
246
|
+
return testPoints;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async CreateTestRun(
|
|
250
|
+
projectName: string,
|
|
251
|
+
testRunName: string,
|
|
252
|
+
testPlanId: string,
|
|
253
|
+
testPointId: string
|
|
254
|
+
): Promise<any> {
|
|
255
|
+
try {
|
|
256
|
+
logger.info(
|
|
257
|
+
`Create test run op test point ${testPointId} ,test planId : ${testPlanId}`
|
|
258
|
+
);
|
|
259
|
+
let Url = `${this.orgUrl}${projectName}/_apis/test/runs`;
|
|
260
|
+
let data = {
|
|
261
|
+
name: testRunName,
|
|
262
|
+
plan: {
|
|
263
|
+
id: testPlanId,
|
|
264
|
+
},
|
|
265
|
+
pointIds: [testPointId],
|
|
266
|
+
};
|
|
267
|
+
let res = await TFSServices.postRequest(
|
|
268
|
+
Url,
|
|
269
|
+
this.token,
|
|
270
|
+
"Post",
|
|
271
|
+
data,
|
|
272
|
+
null
|
|
273
|
+
);
|
|
274
|
+
return res;
|
|
275
|
+
} catch (err) {
|
|
276
|
+
logger.error(`Error : ${err}`);
|
|
277
|
+
throw new Error(String(err));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async UpdateTestRun(
|
|
282
|
+
projectName: string,
|
|
283
|
+
runId: string,
|
|
284
|
+
state: string
|
|
285
|
+
): Promise<any> {
|
|
286
|
+
logger.info(`Update runId : ${runId} to state : ${state}`);
|
|
287
|
+
let Url = `${this.orgUrl}${projectName}/_apis/test/Runs/${runId}?api-version=5.0`;
|
|
288
|
+
let data = {
|
|
289
|
+
state: state,
|
|
290
|
+
};
|
|
291
|
+
let res = await TFSServices.postRequest(
|
|
292
|
+
Url,
|
|
293
|
+
this.token,
|
|
294
|
+
"PATCH",
|
|
295
|
+
data,
|
|
296
|
+
null
|
|
297
|
+
);
|
|
298
|
+
return res;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async UpdateTestCase(
|
|
302
|
+
projectName: string,
|
|
303
|
+
runId: string,
|
|
304
|
+
state: number
|
|
305
|
+
): Promise<any> {
|
|
306
|
+
let data: any;
|
|
307
|
+
logger.info(`Update test case, runId : ${runId} to state : ${state}`);
|
|
308
|
+
let Url = `${this.orgUrl}${projectName}/_apis/test/Runs/${runId}/results?api-version=5.0`;
|
|
309
|
+
switch (state) {
|
|
310
|
+
case 0:
|
|
311
|
+
logger.info(`Reset test case to Active state `);
|
|
312
|
+
data = [
|
|
313
|
+
{
|
|
314
|
+
id: 100000,
|
|
315
|
+
outcome: "0",
|
|
316
|
+
},
|
|
317
|
+
];
|
|
318
|
+
break;
|
|
319
|
+
case 1:
|
|
320
|
+
logger.info(`Update test case to complite state `);
|
|
321
|
+
data = [
|
|
322
|
+
{
|
|
323
|
+
id: 100000,
|
|
324
|
+
state: "Completed",
|
|
325
|
+
outcome: "1",
|
|
326
|
+
},
|
|
327
|
+
];
|
|
328
|
+
break;
|
|
329
|
+
case 2:
|
|
330
|
+
logger.info(`Update test case to passed state `);
|
|
331
|
+
data = [
|
|
332
|
+
{
|
|
333
|
+
id: 100000,
|
|
334
|
+
state: "Completed",
|
|
335
|
+
outcome: "2",
|
|
336
|
+
},
|
|
337
|
+
];
|
|
338
|
+
break;
|
|
339
|
+
case 3:
|
|
340
|
+
logger.info(`Update test case to failed state `);
|
|
341
|
+
data = [
|
|
342
|
+
{
|
|
343
|
+
id: 100000,
|
|
344
|
+
state: "Completed",
|
|
345
|
+
outcome: "3",
|
|
346
|
+
},
|
|
347
|
+
];
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
let res = await TFSServices.postRequest(
|
|
351
|
+
Url,
|
|
352
|
+
this.token,
|
|
353
|
+
"PATCH",
|
|
354
|
+
data,
|
|
355
|
+
null
|
|
356
|
+
);
|
|
357
|
+
return res;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async UploadTestAttachment(
|
|
361
|
+
runID: string,
|
|
362
|
+
projectName: string,
|
|
363
|
+
stream: any,
|
|
364
|
+
fileName: string,
|
|
365
|
+
comment: string,
|
|
366
|
+
attachmentType: string
|
|
367
|
+
): Promise<any> {
|
|
368
|
+
logger.info(`Upload attachment to test run : ${runID}`);
|
|
369
|
+
let Url = `${this.orgUrl}${projectName}/_apis/test/Runs/${runID}/attachments?api-version=5.0-preview.1`;
|
|
370
|
+
let data = {
|
|
371
|
+
stream: stream,
|
|
372
|
+
fileName: fileName,
|
|
373
|
+
comment: comment,
|
|
374
|
+
attachmentType: attachmentType,
|
|
375
|
+
};
|
|
376
|
+
let res = await TFSServices.postRequest(
|
|
377
|
+
Url,
|
|
378
|
+
this.token,
|
|
379
|
+
"Post",
|
|
380
|
+
data,
|
|
381
|
+
null
|
|
382
|
+
);
|
|
383
|
+
return res;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async GetTestRunById(
|
|
387
|
+
projectName: string, runId: string
|
|
388
|
+
): Promise<any> {
|
|
389
|
+
logger.info(`getting test run id: ${runId}`);
|
|
390
|
+
let url = `${this.orgUrl}${projectName}/_apis/test/Runs/${runId}`;
|
|
391
|
+
let res = await TFSServices.getItemContent(
|
|
392
|
+
url,
|
|
393
|
+
this.token,
|
|
394
|
+
"get",
|
|
395
|
+
null,
|
|
396
|
+
null
|
|
397
|
+
);
|
|
398
|
+
return res;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
async GetTestPointByTestCaseId(
|
|
402
|
+
projectName: string,
|
|
403
|
+
testCaseId: string
|
|
404
|
+
): Promise<any> {
|
|
405
|
+
logger.info(
|
|
406
|
+
`get test points at project ${projectName} , of testCaseId : ${testCaseId}`
|
|
407
|
+
);
|
|
408
|
+
let url = `${this.orgUrl}${projectName}/_apis/test/points`;
|
|
409
|
+
let data = {
|
|
410
|
+
PointsFilter: {
|
|
411
|
+
TestcaseIds: [testCaseId],
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
let res = await TFSServices.postRequest(
|
|
415
|
+
url,
|
|
416
|
+
this.token,
|
|
417
|
+
"Post",
|
|
418
|
+
data,
|
|
419
|
+
null
|
|
420
|
+
);
|
|
421
|
+
return res;
|
|
422
|
+
}
|
|
423
|
+
}
|