testit-js-commons 2.2.1 → 2.2.3

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.
@@ -9,6 +9,7 @@ export interface CliOptions {
9
9
  tmsAdapterMode: AdapterMode;
10
10
  tmsConfigFile: string;
11
11
  tmsAutomaticCreationTestCases: boolean;
12
+ tmsAutomaticUpdationLinksToTestCases: boolean;
12
13
  }
13
14
  export interface EnvironmentOptions {
14
15
  TMS_URL: string;
@@ -20,6 +21,7 @@ export interface EnvironmentOptions {
20
21
  TMS_ADAPTER_MODE: AdapterMode;
21
22
  TMS_CONFIG_FILE: string;
22
23
  TMS_AUTOMATIC_CREATION_TEST_CASES: boolean;
24
+ TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES: boolean;
23
25
  TMS_CERT_VALIDATION: boolean;
24
26
  }
25
27
  export interface ProcessEnvOptions {
@@ -32,6 +34,7 @@ export interface ProcessEnvOptions {
32
34
  TMS_ADAPTER_MODE?: AdapterMode;
33
35
  TMS_CONFIG_FILE?: string;
34
36
  TMS_AUTOMATIC_CREATION_TEST_CASES?: boolean;
37
+ TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES?: boolean;
35
38
  TMS_CERT_VALIDATION?: boolean;
36
39
  }
37
40
  export interface AdapterConfig {
@@ -43,5 +46,6 @@ export interface AdapterConfig {
43
46
  testRunName?: string;
44
47
  adapterMode?: AdapterMode;
45
48
  automaticCreationTestCases?: boolean;
49
+ automaticUpdationLinksToTestCases?: boolean;
46
50
  certValidation?: boolean;
47
51
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import fs from "fs";
3
2
  export declare namespace Utils {
4
3
  function getHash(input: string): string;
@@ -51,7 +51,7 @@ class ConfigComposer {
51
51
  return config;
52
52
  }
53
53
  mergeAll(file, env, base) {
54
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
54
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
55
55
  return {
56
56
  url: this.resolveAllProperties(file.url, env === null || env === void 0 ? void 0 : env.TMS_URL, base === null || base === void 0 ? void 0 : base.url),
57
57
  projectId: this.resolveAllProperties(file.projectId, env === null || env === void 0 ? void 0 : env.TMS_PROJECT_ID, base === null || base === void 0 ? void 0 : base.projectId),
@@ -61,11 +61,12 @@ class ConfigComposer {
61
61
  adapterMode: (_c = (_b = (_a = base === null || base === void 0 ? void 0 : base.adapterMode) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.TMS_ADAPTER_MODE) !== null && _b !== void 0 ? _b : file === null || file === void 0 ? void 0 : file.adapterMode) !== null && _c !== void 0 ? _c : 0,
62
62
  configurationId: this.resolveAllProperties(file.configurationId, env === null || env === void 0 ? void 0 : env.TMS_CONFIGURATION_ID, base === null || base === void 0 ? void 0 : base.configurationId),
63
63
  automaticCreationTestCases: (_f = (_e = (_d = file.automaticCreationTestCases) !== null && _d !== void 0 ? _d : env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _e !== void 0 ? _e : base === null || base === void 0 ? void 0 : base.automaticCreationTestCases) !== null && _f !== void 0 ? _f : false,
64
- certValidation: (_j = (_h = (_g = file.certValidation) !== null && _g !== void 0 ? _g : env === null || env === void 0 ? void 0 : env.TMS_CERT_VALIDATION) !== null && _h !== void 0 ? _h : base === null || base === void 0 ? void 0 : base.certValidation) !== null && _j !== void 0 ? _j : true
64
+ automaticUpdationLinksToTestCases: (_j = (_h = (_g = file.automaticUpdationLinksToTestCases) !== null && _g !== void 0 ? _g : env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES) !== null && _h !== void 0 ? _h : base === null || base === void 0 ? void 0 : base.automaticUpdationLinksToTestCases) !== null && _j !== void 0 ? _j : false,
65
+ certValidation: (_m = (_l = (_k = file.certValidation) !== null && _k !== void 0 ? _k : env === null || env === void 0 ? void 0 : env.TMS_CERT_VALIDATION) !== null && _l !== void 0 ? _l : base === null || base === void 0 ? void 0 : base.certValidation) !== null && _m !== void 0 ? _m : true
65
66
  };
66
67
  }
67
68
  merge(env, base) {
68
- var _a, _b, _c, _d, _e, _f;
69
+ var _a, _b, _c, _d, _e, _f, _g, _h;
69
70
  return {
70
71
  url: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_URL, base === null || base === void 0 ? void 0 : base.url),
71
72
  projectId: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_PROJECT_ID, base === null || base === void 0 ? void 0 : base.projectId),
@@ -75,11 +76,12 @@ class ConfigComposer {
75
76
  adapterMode: (_b = (_a = base === null || base === void 0 ? void 0 : base.adapterMode) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.TMS_ADAPTER_MODE) !== null && _b !== void 0 ? _b : 0,
76
77
  configurationId: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_CONFIGURATION_ID, base === null || base === void 0 ? void 0 : base.configurationId),
77
78
  automaticCreationTestCases: (_d = (_c = env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _c !== void 0 ? _c : base === null || base === void 0 ? void 0 : base.automaticCreationTestCases) !== null && _d !== void 0 ? _d : false,
78
- certValidation: (_f = (_e = env === null || env === void 0 ? void 0 : env.TMS_CERT_VALIDATION) !== null && _e !== void 0 ? _e : base === null || base === void 0 ? void 0 : base.certValidation) !== null && _f !== void 0 ? _f : true
79
+ automaticUpdationLinksToTestCases: (_f = (_e = env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES) !== null && _e !== void 0 ? _e : base === null || base === void 0 ? void 0 : base.automaticUpdationLinksToTestCases) !== null && _f !== void 0 ? _f : false,
80
+ certValidation: (_h = (_g = env === null || env === void 0 ? void 0 : env.TMS_CERT_VALIDATION) !== null && _g !== void 0 ? _g : base === null || base === void 0 ? void 0 : base.certValidation) !== null && _h !== void 0 ? _h : true
79
81
  };
80
82
  }
81
83
  mergeEnv(dotEnv, processEnv) {
82
- var _a, _b, _c;
84
+ var _a, _b, _c, _d;
83
85
  return {
84
86
  TMS_URL: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_URL, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_URL),
85
87
  TMS_PROJECT_ID: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_PROJECT_ID, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_PROJECT_ID),
@@ -89,7 +91,8 @@ class ConfigComposer {
89
91
  TMS_ADAPTER_MODE: (_a = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_ADAPTER_MODE) !== null && _a !== void 0 ? _a : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_ADAPTER_MODE,
90
92
  TMS_CONFIGURATION_ID: this.resolveProperties(dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_CONFIGURATION_ID, processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_CONFIGURATION_ID),
91
93
  TMS_AUTOMATIC_CREATION_TEST_CASES: (_b = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _b !== void 0 ? _b : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_AUTOMATIC_CREATION_TEST_CASES,
92
- TMS_CERT_VALIDATION: (_c = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_CERT_VALIDATION) !== null && _c !== void 0 ? _c : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_CERT_VALIDATION
94
+ TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES: (_c = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES) !== null && _c !== void 0 ? _c : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES,
95
+ TMS_CERT_VALIDATION: (_d = dotEnv === null || dotEnv === void 0 ? void 0 : dotEnv.TMS_CERT_VALIDATION) !== null && _d !== void 0 ? _d : processEnv === null || processEnv === void 0 ? void 0 : processEnv.TMS_CERT_VALIDATION
93
96
  };
94
97
  }
95
98
  resolveAllProperties(file, env, base) {
@@ -165,6 +168,7 @@ function parseProcessEnvConfig() {
165
168
  TMS_ADAPTER_MODE: process.env.TMS_ADAPTER_MODE ? stringToAdapterMode(process.env.TMS_ADAPTER_MODE) : undefined,
166
169
  TMS_CERT_VALIDATION: process.env.TMS_CERT_VALIDATION ? stringToBoolean(process.env.TMS_CERT_VALIDATION) : undefined,
167
170
  TMS_AUTOMATIC_CREATION_TEST_CASES: process.env.TMS_AUTOMATIC_CREATION_TEST_CASES ? stringToBoolean(process.env.TMS_AUTOMATIC_CREATION_TEST_CASES) : undefined,
171
+ TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES: process.env.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES ? stringToBoolean(process.env.TMS_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES) : undefined,
168
172
  TMS_CONFIG_FILE: process.env.TMS_PRIVATE_TOKEN,
169
173
  };
170
174
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleHttpError = void 0;
3
+ exports.handleHttpError = handleHttpError;
4
4
  const testit_api_client_1 = require("testit-api-client");
5
5
  function handleHttpError(err, message = "") {
6
6
  if (err instanceof testit_api_client_1.HttpError) {
@@ -10,4 +10,3 @@ function handleHttpError(err, message = "") {
10
10
  console.log(message, err);
11
11
  }
12
12
  }
13
- exports.handleHttpError = handleHttpError;
@@ -1,4 +1,4 @@
1
- import { AutoTestsApi } from "testit-api-client";
1
+ import { AutoTestsApi, WorkItemIdentifierModel } from "testit-api-client";
2
2
  import { AdapterConfig } from "../../common";
3
3
  import { BaseService } from "../base.service";
4
4
  import { AutotestGet, AutotestPost, type IAutotestService } from "./autotests.type";
@@ -7,12 +7,16 @@ export declare class AutotestsService extends BaseService implements IAutotestSe
7
7
  protected readonly config: AdapterConfig;
8
8
  protected _client: AutoTestsApi;
9
9
  protected _converter: IAutotestConverter;
10
+ private MAX_TRIES;
11
+ private WAITING_TIME;
10
12
  constructor(config: AdapterConfig);
11
13
  createAutotest(autotest: AutotestPost): Promise<void>;
12
14
  updateAutotest(autotest: AutotestPost): Promise<void>;
13
15
  private loadPassedAutotest;
14
16
  private loadFailedAutotest;
15
17
  loadAutotest(autotest: AutotestPost, isPassed: boolean): Promise<void>;
16
- linkToWorkItems(externalId: string, workItemIds: Array<string>): Promise<void>;
18
+ linkToWorkItems(internalId: string, workItemIds: Array<string>): Promise<void>;
19
+ unlinkToWorkItem(internalId: string, workItemId: string): Promise<void>;
20
+ getWorkItemsLinkedToAutoTest(internalId: string): Promise<Array<WorkItemIdentifierModel>>;
17
21
  getAutotestByExternalId(externalId: string): Promise<AutotestGet | null>;
18
22
  }
@@ -19,6 +19,8 @@ class AutotestsService extends base_service_1.BaseService {
19
19
  constructor(config) {
20
20
  super(config);
21
21
  this.config = config;
22
+ this.MAX_TRIES = 10;
23
+ this.WAITING_TIME = 100;
22
24
  this._client = new testit_api_client_1.AutoTestsApi(config.url);
23
25
  this._client.setApiKey(autotestApiKey, `PrivateToken ${config.privateToken}`);
24
26
  this._converter = new autotests_converter_1.AutotestConverter(config);
@@ -61,16 +63,48 @@ class AutotestsService extends base_service_1.BaseService {
61
63
  isPassed ? yield this.loadPassedAutotest(autotest) : yield this.loadFailedAutotest(autotest);
62
64
  });
63
65
  }
64
- linkToWorkItems(externalId, workItemIds) {
66
+ linkToWorkItems(internalId, workItemIds) {
65
67
  return __awaiter(this, void 0, void 0, function* () {
66
- const internalId = yield this.getAutotestByExternalId(externalId).then((test) => test === null || test === void 0 ? void 0 : test.id);
67
- if (internalId === undefined) {
68
- throw new Error(`Autotest with external id ${externalId} not found`);
69
- }
70
- const promises = workItemIds.map((workItemId) => this._client.linkAutoTestToWorkItem(internalId, { id: workItemId }));
68
+ const promises = workItemIds.map((workItemId) => __awaiter(this, void 0, void 0, function* () {
69
+ for (var attempts = 0; attempts < this.MAX_TRIES; attempts++) {
70
+ try {
71
+ yield this._client.linkAutoTestToWorkItem(internalId, { id: workItemId });
72
+ console.log(`Link autotest ${internalId} to workitem ${workItemId} is successfully`);
73
+ return;
74
+ }
75
+ catch (e) {
76
+ console.log(`Cannot link autotest ${internalId} to work item ${workItemId}: ${e}`);
77
+ yield new Promise(f => setTimeout(f, this.WAITING_TIME));
78
+ }
79
+ }
80
+ }));
71
81
  yield Promise.all(promises).catch((err) => (0, autotests_handler_1.handleHttpError)(err, "Failed link work item"));
72
82
  });
73
83
  }
84
+ unlinkToWorkItem(internalId, workItemId) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ for (var attempts = 0; attempts < this.MAX_TRIES; attempts++) {
87
+ try {
88
+ yield this._client.deleteAutoTestLinkFromWorkItem(internalId, workItemId);
89
+ console.log(`Unlink autotest ${internalId} from workitem ${workItemId} is successfully`);
90
+ return;
91
+ }
92
+ catch (e) {
93
+ console.log(`Cannot unlink autotest ${internalId} to work item ${workItemId}: ${e}`);
94
+ yield new Promise(f => setTimeout(f, this.WAITING_TIME));
95
+ }
96
+ }
97
+ });
98
+ }
99
+ getWorkItemsLinkedToAutoTest(internalId) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ return yield this._client.getWorkItemsLinkedToAutoTest(internalId).then((res) => res.body)
102
+ .catch((e) => {
103
+ console.log(`Cannot get linked workitems to autotest ${internalId}: ${e}`);
104
+ return [];
105
+ });
106
+ });
107
+ }
74
108
  getAutotestByExternalId(externalId) {
75
109
  return __awaiter(this, void 0, void 0, function* () {
76
110
  const filterModel = {
@@ -1,9 +1,12 @@
1
+ import { WorkItemIdentifierModel } from "testit-api-client";
1
2
  import { Label, Link, ShortStep } from "../../common";
2
3
  export interface IAutotestService {
3
4
  createAutotest(autotest: AutotestPost): Promise<void>;
4
5
  updateAutotest(autotest: AutotestPost): Promise<void>;
5
6
  loadAutotest(autotest: AutotestPost, isPassed: boolean): Promise<void>;
6
- linkToWorkItems(externalId: string, workItemsIds: Array<string>): Promise<void>;
7
+ linkToWorkItems(internalId: string, workItemIds: Array<string>): Promise<void>;
8
+ unlinkToWorkItem(internalId: string, workItemId: string): Promise<void>;
9
+ getWorkItemsLinkedToAutoTest(internalId: string): Promise<Array<WorkItemIdentifierModel>>;
7
10
  getAutotestByExternalId(externalId: string): Promise<AutotestGet | null>;
8
11
  }
9
12
  interface AutotestBase {
@@ -10,5 +10,6 @@ export declare class BaseStrategy implements IStrategy {
10
10
  setup(): Promise<void>;
11
11
  teardown(): Promise<void>;
12
12
  loadAutotest(autotest: AutotestPost, isPassed: boolean): Promise<void>;
13
+ private updateTestLinkToWorkItems;
13
14
  loadTestRun(autotests: AutotestResult[]): Promise<void>;
14
15
  }
@@ -32,16 +32,36 @@ class BaseStrategy {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  yield this.client.autoTests.loadAutotest(autotest, isPassed);
34
34
  if (Array.isArray(autotest.workItemIds)) {
35
- this.client.autoTests.linkToWorkItems(autotest.externalId, autotest.workItemIds).catch((err) => {
36
- console.log("Failed link work items. \n", err);
37
- });
35
+ yield this.updateTestLinkToWorkItems(autotest.externalId, autotest.workItemIds);
38
36
  }
39
37
  });
40
38
  }
39
+ updateTestLinkToWorkItems(externalId, workItemIds) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const internalId = yield this.client.autoTests.getAutotestByExternalId(externalId).then((test) => test === null || test === void 0 ? void 0 : test.id);
42
+ if (internalId === undefined) {
43
+ throw new Error(`Autotest with external id ${internalId} not found`);
44
+ }
45
+ const linkedWorkItems = yield this.client.autoTests.getWorkItemsLinkedToAutoTest(internalId);
46
+ for (const linkedWorkItem of linkedWorkItems) {
47
+ const linkedWorkItemId = linkedWorkItem.globalId.toString();
48
+ if (workItemIds.includes(linkedWorkItemId)) {
49
+ delete workItemIds[workItemIds.indexOf(linkedWorkItemId)];
50
+ continue;
51
+ }
52
+ if (this.config.automaticUpdationLinksToTestCases) {
53
+ yield this.client.autoTests.unlinkToWorkItem(internalId, linkedWorkItemId);
54
+ }
55
+ }
56
+ yield this.client.autoTests.linkToWorkItems(internalId, workItemIds).catch((err) => {
57
+ console.log("Failed link work items. \n", err);
58
+ });
59
+ });
60
+ }
41
61
  loadTestRun(autotests) {
42
62
  return __awaiter(this, void 0, void 0, function* () {
43
63
  const testRunId = yield this.testRunId;
44
- return this.client.testRuns.loadAutotests(testRunId, autotests);
64
+ return yield this.client.testRuns.loadAutotests(testRunId, autotests);
45
65
  });
46
66
  }
47
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",