testit-js-commons 3.6.0 → 3.6.1

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.
@@ -1,11 +1,41 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
36
  exports.BaseService = void 0;
7
37
  // @ts-ignore
8
- const testit_api_client_1 = __importDefault(require("testit-api-client"));
38
+ const TestitApiClient = __importStar(require("testit-api-client"));
9
39
  class BaseService {
10
40
  constructor(config) {
11
41
  this.config = config;
@@ -19,9 +49,9 @@ class BaseService {
19
49
  throw new Error("Configuration id is not defined");
20
50
  if (!config.projectId)
21
51
  throw new Error("Project id is not defined");
22
- var defaultClient = testit_api_client_1.default.ApiClient.instance;
52
+ const defaultClient = TestitApiClient.ApiClient.instance;
23
53
  defaultClient.basePath = config.url;
24
- var auth = defaultClient.authentications['Bearer or PrivateToken'];
54
+ const auth = defaultClient.authentications["Bearer or PrivateToken"];
25
55
  auth.apiKeyPrefix = "PrivateToken";
26
56
  auth.apiKey = config.privateToken;
27
57
  if (config.certValidation === false) {
@@ -1,4 +1,4 @@
1
- import TestitApiClient from "testit-api-client";
1
+ import * as TestitApiClient from "testit-api-client";
2
2
  import { BaseService, AdapterConfig, Attachment } from "../../common";
3
3
  import { IAttachmentsService } from "./attachments.type";
4
4
  import { Buffer } from "buffer";
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,40 +41,98 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
44
  Object.defineProperty(exports, "__esModule", { value: true });
15
45
  exports.AttachmentsService = void 0;
16
46
  // @ts-ignore
17
- const testit_api_client_1 = __importDefault(require("testit-api-client"));
47
+ const TestitApiClient = __importStar(require("testit-api-client"));
18
48
  const common_1 = require("../../common");
19
49
  const buffer_1 = require("buffer");
50
+ const fs = __importStar(require("fs"));
20
51
  class AttachmentsService extends common_1.BaseService {
21
52
  constructor(config) {
22
53
  super(config);
23
54
  this.config = config;
24
- this._client = new testit_api_client_1.default.AttachmentsApi();
55
+ this._client = new TestitApiClient.AttachmentsApi();
56
+ // Set the base path from config if provided
57
+ if (this.config.url) {
58
+ this._client.apiClient.basePath = this.config.url.replace(/\/+$/, "");
59
+ }
25
60
  }
26
61
  uploadTextAttachment(content, filename) {
27
62
  return __awaiter(this, void 0, void 0, function* () {
28
- const request = {
29
- value: typeof content === "string" ? buffer_1.Buffer.from(content, "utf-8") : content,
30
- options: { filename: filename !== null && filename !== void 0 ? filename : common_1.Utils.generateFileName() },
31
- };
32
- // @ts-ignore
33
- return yield this._client.apiV2AttachmentsPost({ file: request }).then(({ body }) => [{ id: body.id }]);
63
+ // Create a Buffer for the content
64
+ const bufferContent = typeof content === "string" ? buffer_1.Buffer.from(content, "utf-8") : content;
65
+ const fileName = filename !== null && filename !== void 0 ? filename : common_1.Utils.generateFileName();
66
+ try {
67
+ // Try to create a temporary file with the correct name to workaround filename issue
68
+ const tempDir = common_1.Utils.createTempDir();
69
+ const tempFilePath = `${tempDir}/${fileName}`;
70
+ try {
71
+ // Write buffer to temporary file
72
+ fs.writeFileSync(tempFilePath, bufferContent);
73
+ // Use the temporary file with the API client
74
+ const fileStream = fs.createReadStream(tempFilePath);
75
+ // @ts-ignore
76
+ const response = yield this._client.apiV2AttachmentsPost({ file: fileStream });
77
+ const data = response.body || response;
78
+ return [{ id: data.id }];
79
+ }
80
+ finally {
81
+ // Clean up temporary file and directory
82
+ try {
83
+ if (fs.existsSync(tempFilePath)) {
84
+ fs.unlinkSync(tempFilePath);
85
+ }
86
+ // Try to remove the temp directory
87
+ if (fs.existsSync(tempDir)) {
88
+ fs.rmdirSync(tempDir);
89
+ }
90
+ }
91
+ catch (cleanupError) {
92
+ console.warn("Failed to cleanup temporary files:", cleanupError);
93
+ }
94
+ }
95
+ }
96
+ catch (error) {
97
+ console.error("Error uploading text attachment:", error);
98
+ if (error.response) {
99
+ console.error("Response details:", {
100
+ status: error.response.status,
101
+ text: error.response.text,
102
+ });
103
+ }
104
+ throw error;
105
+ }
34
106
  });
35
107
  }
36
108
  uploadAttachments(paths) {
37
109
  return __awaiter(this, void 0, void 0, function* () {
38
- return yield Promise.all(paths.map((path) => {
39
- return this._client
40
- // @ts-ignore
41
- .apiV2AttachmentsPost({ file: common_1.Utils.readStream(path) })
110
+ const attachmentIds = yield Promise.all(paths.map((path) => __awaiter(this, void 0, void 0, function* () {
111
+ try {
112
+ // Verify file exists
113
+ if (!fs.existsSync(path)) {
114
+ throw new Error(`File not found: ${path}`);
115
+ }
116
+ // Create a read stream directly from the file
117
+ const fileStream = common_1.Utils.readStream(path);
42
118
  // @ts-ignore
43
- .then(({ body }) => ({ id: body.id }));
44
- }));
119
+ const response = yield this._client.apiV2AttachmentsPost({ file: fileStream });
120
+ const data = response.body || response;
121
+ return data.id;
122
+ }
123
+ catch (error) {
124
+ console.error(`Error uploading attachment ${path}:`, error);
125
+ if (error.response) {
126
+ console.error("Response details:", {
127
+ status: error.response.status,
128
+ text: error.response.text,
129
+ });
130
+ }
131
+ throw error;
132
+ }
133
+ })));
134
+ // Convert array of IDs to array of Attachment objects
135
+ return attachmentIds.map((id) => ({ id }));
45
136
  });
46
137
  }
47
138
  }
@@ -1,4 +1,4 @@
1
- import TestitApiClient from "testit-api-client";
1
+ import * as TestitApiClient from "testit-api-client";
2
2
  import { BaseService, AdapterConfig } from "../../common";
3
3
  import { AutotestGet, AutotestPost, type IAutotestService } from "./autotests.type";
4
4
  import { type IAutotestConverter } from "./autotests.converter";
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,13 +41,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
44
  Object.defineProperty(exports, "__esModule", { value: true });
15
45
  exports.AutotestsService = void 0;
16
46
  // @ts-ignore
17
- const testit_api_client_1 = __importDefault(require("testit-api-client"));
47
+ const TestitApiClient = __importStar(require("testit-api-client"));
18
48
  const common_1 = require("../../common");
19
49
  const autotests_type_1 = require("./autotests.type");
20
50
  const autotests_converter_1 = require("./autotests.converter");
@@ -25,7 +55,7 @@ class AutotestsService extends common_1.BaseService {
25
55
  this.config = config;
26
56
  this.MAX_TRIES = 10;
27
57
  this.WAITING_TIME = 100;
28
- this._client = new testit_api_client_1.default.AutoTestsApi();
58
+ this._client = new TestitApiClient.AutoTestsApi();
29
59
  this._converter = new autotests_converter_1.AutotestConverter(config);
30
60
  }
31
61
  createAutotest(autotest) {
@@ -90,9 +120,11 @@ class AutotestsService extends common_1.BaseService {
90
120
  yield this._client.linkAutoTestToWorkItem(internalId, { workItemIdApiModel: { id: workItemId } });
91
121
  console.log(`Link autotest ${internalId} to workitem ${workItemId} is successfully`);
92
122
  return;
123
+ // @ts-ignore
93
124
  }
94
125
  catch (e) {
95
- console.log(`Cannot link autotest ${internalId} to work item ${workItemId}: ${e}`);
126
+ console.error(`Cannot link autotest ${internalId} to work item ${workItemId}`);
127
+ // console.error(e);
96
128
  yield new Promise((f) => setTimeout(f, this.WAITING_TIME));
97
129
  }
98
130
  }
@@ -147,9 +179,16 @@ class AutotestsService extends common_1.BaseService {
147
179
  return yield this._client
148
180
  .apiV2AutoTestsSearchPost({ autoTestSearchApiModel: requestModel })
149
181
  // @ts-ignore
150
- .then(({ body }) => body[0])
182
+ .then((response) => {
183
+ const data = response.body || response;
184
+ return data ? data[0] : null;
185
+ })
151
186
  .then((autotest) => {
152
187
  return autotest ? this._converter.toLocalAutotest(autotest) : null;
188
+ })
189
+ .catch((reason) => {
190
+ console.error(reason);
191
+ return null;
153
192
  });
154
193
  });
155
194
  }
@@ -1,4 +1,4 @@
1
- import TestitApiClient from "testit-api-client";
1
+ import * as TestitApiClient from "testit-api-client";
2
2
  import { AdapterConfig, BaseService } from "../../common";
3
3
  import { ITestResultsConverter } from "./testresults.converter";
4
4
  import { ITestResultsService } from "./testresults.type";
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,13 +41,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
44
  Object.defineProperty(exports, "__esModule", { value: true });
15
45
  exports.TestResultsService = void 0;
16
46
  // @ts-ignore
17
- const testit_api_client_1 = __importDefault(require("testit-api-client"));
47
+ const TestitApiClient = __importStar(require("testit-api-client"));
18
48
  const common_1 = require("../../common");
19
49
  const testresults_handler_1 = require("./testresults.handler");
20
50
  const testresults_converter_1 = require("./testresults.converter");
@@ -23,7 +53,7 @@ class TestResultsService extends common_1.BaseService {
23
53
  super(config);
24
54
  this.config = config;
25
55
  this._testsLimit = 100;
26
- this._client = new testit_api_client_1.default.TestResultsApi();
56
+ this._client = new TestitApiClient.TestResultsApi();
27
57
  this._converter = new testresults_converter_1.TestResultsConverter(config);
28
58
  }
29
59
  getExternalIdsForRun() {
@@ -48,7 +78,10 @@ class TestResultsService extends common_1.BaseService {
48
78
  return yield this._client
49
79
  .apiV2TestResultsSearchPost({ skip: skip, take: this._testsLimit, testResultsFilterApiModel: model })
50
80
  // @ts-ignore
51
- .then(({ body }) => body)
81
+ .then((response) => {
82
+ const data = response.body || response;
83
+ return data;
84
+ })
52
85
  // @ts-ignore
53
86
  .catch((err) => {
54
87
  (0, testresults_handler_1.handleHttpError)(err);
@@ -1,4 +1,4 @@
1
- import TestitApiClient from "testit-api-client";
1
+ import * as TestitApiClient from "testit-api-client";
2
2
  import { AdapterConfig, BaseService } from "../../common";
3
3
  import { type ITestRunsService, TestRunId, AutotestResult, TestRunGet } from "./testruns.type";
4
4
  import { type ITestRunConverter } from "./testruns.converter";
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,13 +41,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
44
  Object.defineProperty(exports, "__esModule", { value: true });
15
45
  exports.TestRunsService = void 0;
16
46
  // @ts-ignore
17
- const testit_api_client_1 = __importDefault(require("testit-api-client"));
47
+ const TestitApiClient = __importStar(require("testit-api-client"));
18
48
  const common_1 = require("../../common");
19
49
  const utils_1 = require("../../common/utils");
20
50
  const testruns_converter_1 = require("./testruns.converter");
@@ -23,7 +53,7 @@ class TestRunsService extends common_1.BaseService {
23
53
  constructor(config) {
24
54
  super(config);
25
55
  this.config = config;
26
- this._client = new testit_api_client_1.default.TestRunsApi();
56
+ this._client = new TestitApiClient.TestRunsApi();
27
57
  this._converter = new testruns_converter_1.TestRunConverter(config);
28
58
  }
29
59
  createTestRun() {
@@ -35,7 +65,21 @@ class TestRunsService extends common_1.BaseService {
35
65
  return yield this._client
36
66
  .createEmpty({ createEmptyTestRunApiModel: (0, utils_1.escapeHtmlInObject)(createRequest) })
37
67
  // @ts-ignore
38
- .then(({ body }) => body.id);
68
+ .then((response) => {
69
+ //console.debug("Full response from createEmpty:", response);
70
+ const data = response.body || response;
71
+ if (!data) {
72
+ throw new Error("API returned undefined response");
73
+ }
74
+ if (!data.id) {
75
+ throw new Error("API response missing 'id' field: " + JSON.stringify(data));
76
+ }
77
+ return data.id;
78
+ })
79
+ .catch((err) => {
80
+ console.error("Error in createTestRun:", err);
81
+ throw err;
82
+ });
39
83
  });
40
84
  }
41
85
  getTestRun(testRunId) {
@@ -43,7 +87,10 @@ class TestRunsService extends common_1.BaseService {
43
87
  return yield this._client
44
88
  .getTestRunById(testRunId)
45
89
  // @ts-ignore
46
- .then(({ body }) => body)
90
+ .then((response) => {
91
+ const data = response.body || response;
92
+ return data;
93
+ })
47
94
  // @ts-ignore
48
95
  .then((run) => this._converter.toLocalTestRun(run));
49
96
  });
@@ -53,7 +100,14 @@ class TestRunsService extends common_1.BaseService {
53
100
  yield this._client
54
101
  .updateEmpty({ updateEmptyTestRunApiModel: testRun })
55
102
  // @ts-ignore
56
- .then(({ body }) => body)
103
+ .then((response) => {
104
+ console.log("Full response from updateEmpty:", response);
105
+ const data = response.body || response;
106
+ if (!data) {
107
+ throw new Error("API returned undefined response");
108
+ }
109
+ return data;
110
+ })
57
111
  // @ts-ignore
58
112
  .then((run) => this._converter.toLocalTestRun(run));
59
113
  });
@@ -39,22 +39,28 @@ class BaseStrategy {
39
39
  }
40
40
  updateTestLinkToWorkItems(externalId, workItemIds) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
- const internalId = yield this.client.autoTests.getAutotestByExternalId(externalId).then((test) => test === null || test === void 0 ? void 0 : test.id);
43
- if (internalId === undefined) {
44
- throw new Error(`Autotest with external id ${internalId} not found`);
42
+ const existingAutotest = yield this.client.autoTests.getAutotestByExternalId(externalId).then((test) => test === null || test === void 0 ? void 0 : test.id);
43
+ if (existingAutotest === undefined) {
44
+ throw new Error(`Autotest with external id ${externalId} not found`);
45
45
  }
46
- const linkedWorkItems = yield this.client.autoTests.getWorkItemsLinkedToAutoTest(internalId);
47
- for (const linkedWorkItem of linkedWorkItems) {
46
+ const linkedWorkItems = yield this.client.autoTests.getWorkItemsLinkedToAutoTest(existingAutotest);
47
+ // Проверяем, является ли linkedWorkItems массивом, если нет - делаем его массивом
48
+ const workItemsArray = Array.isArray(linkedWorkItems) ? linkedWorkItems : linkedWorkItems ? [linkedWorkItems] : [];
49
+ for (const linkedWorkItem of workItemsArray) {
48
50
  const linkedWorkItemId = linkedWorkItem.globalId.toString();
49
51
  if (workItemIds.includes(linkedWorkItemId)) {
50
- delete workItemIds[workItemIds.indexOf(linkedWorkItemId)];
52
+ // Правильно удаляем элемент из массива
53
+ const index = workItemIds.indexOf(linkedWorkItemId);
54
+ if (index > -1) {
55
+ workItemIds.splice(index, 1);
56
+ }
51
57
  continue;
52
58
  }
53
59
  if (this.config.automaticUpdationLinksToTestCases) {
54
- yield this.client.autoTests.unlinkToWorkItem(internalId, linkedWorkItemId);
60
+ yield this.client.autoTests.unlinkToWorkItem(existingAutotest, linkedWorkItemId);
55
61
  }
56
62
  }
57
- yield this.client.autoTests.linkToWorkItems(internalId, workItemIds).catch((err) => {
63
+ yield this.client.autoTests.linkToWorkItems(existingAutotest, workItemIds).catch((err) => {
58
64
  console.log("Failed link work items. \n", err);
59
65
  });
60
66
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "@types/jest": "^27.5.2",
27
27
  "@types/node": "^20.2.4",
28
28
  "@types/request": "^2.48.8",
29
+ "@types/superagent": "^8.1.9",
29
30
  "@typescript-eslint/eslint-plugin": "^8.54.0",
30
31
  "@typescript-eslint/parser": "^8.54.0",
31
32
  "eslint": "^9.39.2",