testit-js-commons 2.1.6 → 2.1.8

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.
@@ -8,4 +8,5 @@ export declare class ConfigComposer implements IConfigComposer {
8
8
  mergeEnv(dotEnv?: Partial<EnvironmentOptions>, processEnv?: Partial<EnvironmentOptions>): Partial<EnvironmentOptions>;
9
9
  private resolveAllProperties;
10
10
  private resolveProperties;
11
+ private validateConfig;
11
12
  }
@@ -34,16 +34,21 @@ class ConfigComposer {
34
34
  const dotEnvironment = parseDotEnvConfig();
35
35
  const environment = this.mergeEnv(dotEnvironment, processEnvironment);
36
36
  const content = common_1.Utils.readFile((_b = (_a = dotEnvironment === null || dotEnvironment === void 0 ? void 0 : dotEnvironment.TMS_CONFIG_FILE) !== null && _a !== void 0 ? _a : processEnvironment.TMS_CONFIG_FILE) !== null && _b !== void 0 ? _b : exports.DEFAULT_CONFIG_FILE);
37
+ let config;
37
38
  if (content !== "") {
38
- const config = JSON.parse(content);
39
- if (config.privateToken) {
39
+ const fileConfig = JSON.parse(content);
40
+ if (fileConfig.privateToken) {
40
41
  console.warn(`
41
42
  The configuration file specifies a private token. It is not safe.
42
43
  Use TMS_PRIVATE_TOKEN environment variable`);
43
44
  }
44
- return this.mergeAll(config, environment, base);
45
+ config = this.mergeAll(fileConfig, environment, base);
45
46
  }
46
- return this.merge(environment, base);
47
+ else {
48
+ config = this.merge(environment, base);
49
+ }
50
+ this.validateConfig(config);
51
+ return config;
47
52
  }
48
53
  mergeAll(file, env, base) {
49
54
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
@@ -112,6 +117,38 @@ class ConfigComposer {
112
117
  return "";
113
118
  }
114
119
  }
120
+ validateConfig(config) {
121
+ try {
122
+ new URL(config.url);
123
+ }
124
+ catch (err) {
125
+ console.error(`Url is invalid`);
126
+ }
127
+ if (!config.privateToken) {
128
+ console.error(`Private Token is invalid`);
129
+ }
130
+ if (config.projectId.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') === null) {
131
+ console.error(`Project ID is invalid`);
132
+ }
133
+ if (config.configurationId.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') === null) {
134
+ console.error(`Configuration ID is invalid`);
135
+ }
136
+ if (config.adapterMode == 2) {
137
+ if (config.testRunId.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') !== null) {
138
+ console.error(`Adapter works in mode 2. Config should not contains test run id.`);
139
+ }
140
+ }
141
+ else if (config.adapterMode == 1) {
142
+ if (config.testRunId.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') === null) {
143
+ console.error(`Adapter works in mode 1. Config should contains valid test run id.`);
144
+ }
145
+ }
146
+ else {
147
+ if (config.testRunId.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') === null) {
148
+ console.error(`Adapter works in mode 0. Config should contains valid test run id.`);
149
+ }
150
+ }
151
+ }
115
152
  }
116
153
  exports.ConfigComposer = ConfigComposer;
117
154
  function parseDotEnvConfig() {
@@ -144,5 +181,5 @@ function stringToAdapterMode(str) {
144
181
  }
145
182
  }
146
183
  function stringToBoolean(str) {
147
- return ((str === null || str === void 0 ? void 0 : str.toLowerCase()) === "true") ? true : false;
184
+ return ((str === null || str === void 0 ? void 0 : str.toLowerCase()) === "true");
148
185
  }
@@ -13,6 +13,6 @@ export declare class AutotestsService extends BaseService implements IAutotestSe
13
13
  private loadPassedAutotest;
14
14
  private loadFailedAutotest;
15
15
  loadAutotest(autotest: AutotestPost, isPassed: boolean): Promise<void>;
16
- linkToWorkItems(externalId: string, workItemsIds: Array<string>): Promise<void>;
16
+ linkToWorkItems(externalId: string, workItemIds: Array<string>): Promise<void>;
17
17
  getAutotestByExternalId(externalId: string): Promise<AutotestGet | null>;
18
18
  }
@@ -61,13 +61,13 @@ class AutotestsService extends base_service_1.BaseService {
61
61
  isPassed ? yield this.loadPassedAutotest(autotest) : yield this.loadFailedAutotest(autotest);
62
62
  });
63
63
  }
64
- linkToWorkItems(externalId, workItemsIds) {
64
+ linkToWorkItems(externalId, workItemIds) {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
66
  const internalId = yield this.getAutotestByExternalId(externalId).then((test) => test === null || test === void 0 ? void 0 : test.id);
67
67
  if (internalId === undefined) {
68
68
  throw new Error(`Autotest with external id ${externalId} not found`);
69
69
  }
70
- const promises = workItemsIds.map((workItemId) => this._client.linkAutoTestToWorkItem(internalId, { id: workItemId }));
70
+ const promises = workItemIds.map((workItemId) => this._client.linkAutoTestToWorkItem(internalId, { id: workItemId }));
71
71
  yield Promise.all(promises).catch((err) => (0, autotests_handler_1.handleHttpError)(err, "Failed link work item"));
72
72
  });
73
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",