testit-js-commons 5.0.5 → 5.0.6-TMS-5.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.
- package/lib/adapters-api/dist/ApiClient.js +5 -6
- package/lib/adapters-api/dist/api/AttachmentsApi.js +5 -5
- package/lib/adapters-api/dist/api/AutoTestsApi.js +11 -11
- package/lib/adapters-api/dist/api/ConfigurationsApi.js +1 -1
- package/lib/adapters-api/dist/api/ParametersApi.js +3 -3
- package/lib/adapters-api/dist/api/ProjectAttributesApi.js +6 -6
- package/lib/adapters-api/dist/api/ProjectSectionsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +1 -1
- package/lib/adapters-api/dist/api/ProjectsApi.js +4 -4
- package/lib/adapters-api/dist/api/SectionsApi.js +2 -2
- package/lib/adapters-api/dist/api/TestResultsApi.js +3 -3
- package/lib/adapters-api/dist/api/TestRunsApi.js +8 -8
- package/lib/adapters-api/dist/api/WorkItemsApi.js +3 -3
- package/lib/adapters-api/dist/api/WorkflowsApi.js +1 -1
- package/lib/adapters-api/dist/index.js +3 -3
- package/lib/adapters-api/dist/model/AttachmentPutModelAutoTestStepResultsModel.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestStepResult.js +1 -1
- package/lib/adapters-api/dist/model/AutoTestStepResultUpdateRequest.js +1 -1
- package/lib/adapters-api/dist/model/CreateEmptyTestRunApiModel.js +2 -2
- package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +2 -2
- package/lib/adapters-api/dist/model/{CustomAttributeModel.js → CustomAttributeGetModel.js} +39 -89
- package/lib/adapters-api/dist/model/CustomAttributePutModel.js +1 -1
- package/lib/adapters-api/dist/model/LabelApiModel.js +15 -4
- package/lib/adapters-api/dist/model/TestResultResponse.js +4 -18
- package/lib/adapters-api/dist/model/UpdateEmptyTestRunApiModel.js +1 -1
- package/lib/adapters-api/index.d.ts +196 -40
- package/lib/common/utils/tms-load-test-run-debug.d.ts +0 -2
- package/lib/common/utils/tms-load-test-run-debug.js +0 -6
- package/lib/services/attachments/attachments.service.d.ts +1 -0
- package/lib/services/attachments/attachments.service.js +10 -2
- package/lib/services/syncstorage/syncstorage.runner.js +5 -6
- package/lib/services/syncstorage/syncstorage.runner.test.js +0 -16
- package/lib/services/testresults/testresults.converter.d.ts +5 -4
- package/lib/services/testresults/testresults.converter.js +8 -0
- package/lib/services/testresults/testresults.service.js +18 -1
- package/lib/services/testruns/testruns.handler.d.ts +2 -2
- package/lib/services/testruns/testruns.handler.js +2 -12
- package/lib/services/testruns/testruns.service.js +6 -21
- package/lib/services/testruns/testruns.service.test.js +43 -0
- package/lib/strategy/base.strategy.js +1 -0
- package/lib/strategy/zero.strategy.js +1 -1
- package/lib/sync-storage/dist/ApiClient.js +0 -3
- package/package.json +1 -1
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TestResultsConverter = void 0;
|
|
4
|
+
exports.isValidTestRunId = isValidTestRunId;
|
|
4
5
|
const common_1 = require("../../common");
|
|
6
|
+
const TEST_RUN_ID_GUID = /^[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}$/;
|
|
7
|
+
function isValidTestRunId(value) {
|
|
8
|
+
return typeof value === "string" && TEST_RUN_ID_GUID.test(value);
|
|
9
|
+
}
|
|
5
10
|
class TestResultsConverter extends common_1.BaseConverter {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
super(config);
|
|
8
13
|
}
|
|
9
14
|
buildRunFilter(statusTypes) {
|
|
15
|
+
if (!isValidTestRunId(this.config.testRunId)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
testRunIds: [this.config.testRunId],
|
|
12
20
|
configurationIds: [this.config.configurationId],
|
|
@@ -8,12 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.TestResultsService = void 0;
|
|
13
16
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
17
|
const AdaptersApi = require("../../adapters-api/dist/index");
|
|
15
18
|
const common_1 = require("../../common");
|
|
16
19
|
const utils_1 = require("../../common/utils");
|
|
20
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
17
21
|
const testresults_handler_1 = require("./testresults.handler");
|
|
18
22
|
const testresults_converter_1 = require("./testresults.converter");
|
|
19
23
|
class TestResultsService extends common_1.BaseService {
|
|
@@ -26,9 +30,15 @@ class TestResultsService extends common_1.BaseService {
|
|
|
26
30
|
}
|
|
27
31
|
getExternalIdsForRun() {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const model = this._converter.getTestResultsFilterApiModel();
|
|
34
|
+
if (!model) {
|
|
35
|
+
logger_1.default.warn("[testresults] skip search: testRunId is empty or not a GUID", {
|
|
36
|
+
testRunId: this.config.testRunId,
|
|
37
|
+
});
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
29
40
|
var skip = 0;
|
|
30
41
|
var externalIds = [];
|
|
31
|
-
const model = this._converter.getTestResultsFilterApiModel();
|
|
32
42
|
while (true) {
|
|
33
43
|
const testResults = yield this.getTestResults(skip, model);
|
|
34
44
|
if (testResults.length != 0) {
|
|
@@ -46,6 +56,13 @@ class TestResultsService extends common_1.BaseService {
|
|
|
46
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
57
|
var _a, _b;
|
|
48
58
|
const model = this._converter.getTestResultsFilterForRun();
|
|
59
|
+
if (!model) {
|
|
60
|
+
logger_1.default.warn("[testresults] skip search by externalId: testRunId is empty or not a GUID", {
|
|
61
|
+
externalId,
|
|
62
|
+
testRunId: this.config.testRunId,
|
|
63
|
+
});
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
49
66
|
let skip = 0;
|
|
50
67
|
while (true) {
|
|
51
68
|
const batch = yield this.getTestResults(skip, model);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare class TestRunErrorHandler {
|
|
2
|
-
static handleErrorStartTestRun(err:
|
|
3
|
-
static handleErrorCompletedTestRun(err:
|
|
2
|
+
static handleErrorStartTestRun(err: any, message?: string): void;
|
|
3
|
+
static handleErrorCompletedTestRun(err: any, message?: string): void;
|
|
4
4
|
}
|
|
@@ -4,23 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TestRunErrorHandler = void 0;
|
|
7
|
-
const utils_1 = require("../../common/utils");
|
|
8
7
|
const logger_1 = __importDefault(require("../../logger"));
|
|
9
|
-
function logTestRunHttpError(action, err, message = "") {
|
|
10
|
-
var _a;
|
|
11
|
-
const e = (0, utils_1.unwrapHttpError)(err);
|
|
12
|
-
const status = e ? (0, utils_1.getHttpStatus)(e) : undefined;
|
|
13
|
-
const code = e ? (0, utils_1.getNetworkErrorCode)(e) : undefined;
|
|
14
|
-
const body = (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : e === null || e === void 0 ? void 0 : e.body;
|
|
15
|
-
const detail = message || (err instanceof Error ? err.message : String(err));
|
|
16
|
-
logger_1.default.error(`Failed ${action}. Message: ${detail}. status=${status !== null && status !== void 0 ? status : "n/a"} code=${code !== null && code !== void 0 ? code : "n/a"}`, body !== null && body !== void 0 ? body : err);
|
|
17
|
-
}
|
|
18
8
|
class TestRunErrorHandler {
|
|
19
9
|
static handleErrorStartTestRun(err, message = "") {
|
|
20
|
-
|
|
10
|
+
logger_1.default.error(`HttpError ${err.statusCode}. Failed start test run in system. Message: ${message}. Error body:\n`, err.body);
|
|
21
11
|
}
|
|
22
12
|
static handleErrorCompletedTestRun(err, message = "") {
|
|
23
|
-
|
|
13
|
+
logger_1.default.error(`HttpError ${err.statusCode}. Failed completed test run in system. Message: ${message}. Error body:\n`, err.body);
|
|
24
14
|
}
|
|
25
15
|
}
|
|
26
16
|
exports.TestRunErrorHandler = TestRunErrorHandler;
|
|
@@ -74,9 +74,10 @@ class TestRunsService extends common_1.BaseService {
|
|
|
74
74
|
getTestRun(testRunId) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
return yield (0, utils_1.withHttpRetry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
const
|
|
77
|
+
// Temporary: adapters GET omits/empties links, attachments, description, launchSource (TMS 5.8).
|
|
78
|
+
// Read via public API v2; PUT stays on adapters.
|
|
79
|
+
const apiClient = AdaptersApi.ApiClient.instance;
|
|
80
|
+
const { data } = yield apiClient.callApi("/api/v2/testRuns/{id}", "GET", { id: testRunId }, {}, {}, {}, null, ["PrivateToken"], [], ["application/json"], Object, null);
|
|
80
81
|
return this._converter.toLocalTestRun(data);
|
|
81
82
|
}), { label: `getTestRun:${testRunId}` });
|
|
82
83
|
});
|
|
@@ -120,24 +121,8 @@ class TestRunsService extends common_1.BaseService {
|
|
|
120
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
122
|
try {
|
|
122
123
|
const testRun = yield this.getTestRun(testRunId);
|
|
123
|
-
if (testRun.stateName
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
yield (0, utils_1.withHttpRetry)(() => this._client.adaptersTestRunsIdStartPost(testRunId), {
|
|
128
|
-
label: `startTestRun:${testRunId}`,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
const refreshed = yield this.getTestRun(testRunId);
|
|
133
|
-
if (refreshed.stateName !== "NotStarted") {
|
|
134
|
-
logger_1.default.debug("[testruns] startTestRun skipped: run already started", {
|
|
135
|
-
testRunId,
|
|
136
|
-
stateName: refreshed.stateName,
|
|
137
|
-
});
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
throw err;
|
|
124
|
+
if (testRun.stateName === "NotStarted") {
|
|
125
|
+
yield this._client.adaptersTestRunsIdStartPost(testRunId);
|
|
141
126
|
}
|
|
142
127
|
}
|
|
143
128
|
catch (err) {
|
|
@@ -17,11 +17,18 @@ jest.mock("../../adapters-api/dist/index", () => ({
|
|
|
17
17
|
authentications: {
|
|
18
18
|
PrivateToken: { apiKeyPrefix: "", apiKey: "" },
|
|
19
19
|
},
|
|
20
|
+
callApi: jest.fn(),
|
|
20
21
|
},
|
|
21
22
|
},
|
|
22
23
|
TestRunsApi: jest.fn().mockImplementation(() => ({
|
|
23
24
|
adaptersTestRunsIdTestResultsPost: jest.fn().mockResolvedValue(["result-id-1"]),
|
|
24
25
|
})),
|
|
26
|
+
TestRunState: {
|
|
27
|
+
NotStarted: "NotStarted",
|
|
28
|
+
InProgress: "InProgress",
|
|
29
|
+
Stopped: "Stopped",
|
|
30
|
+
Completed: "Completed",
|
|
31
|
+
},
|
|
25
32
|
}));
|
|
26
33
|
jest.mock("../testresults/testresults.service", () => ({
|
|
27
34
|
TestResultsService: jest.fn().mockImplementation(() => ({
|
|
@@ -29,6 +36,9 @@ jest.mock("../testresults/testresults.service", () => ({
|
|
|
29
36
|
updateTestResult: jest.fn().mockResolvedValue(undefined),
|
|
30
37
|
})),
|
|
31
38
|
}));
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
40
|
+
const AdaptersApi = require("../../adapters-api/dist/index");
|
|
41
|
+
const callApi = AdaptersApi.ApiClient.instance.callApi;
|
|
32
42
|
function makeConfig() {
|
|
33
43
|
return {
|
|
34
44
|
url: "http://localhost:8080",
|
|
@@ -41,6 +51,39 @@ function makeConfig() {
|
|
|
41
51
|
function makeResult(overrides = {}) {
|
|
42
52
|
return Object.assign({ autoTestExternalId: "ext-1", outcome: "Passed", stepResults: [{ title: "step-1" }] }, overrides);
|
|
43
53
|
}
|
|
54
|
+
describe("TestRunsService.getTestRun", () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
callApi.mockReset();
|
|
57
|
+
});
|
|
58
|
+
it("reads metadata via public API v2 (links/attachments/description/launchSource)", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
callApi.mockResolvedValue({
|
|
60
|
+
data: {
|
|
61
|
+
id: "run-1",
|
|
62
|
+
name: "run",
|
|
63
|
+
description: "213123123",
|
|
64
|
+
launchSource: "Test IT",
|
|
65
|
+
stateName: "Completed",
|
|
66
|
+
status: { code: "PASSED", type: "Succeeded" },
|
|
67
|
+
testResults: [{ id: "ignored" }],
|
|
68
|
+
attachments: [{ id: "att-1" }],
|
|
69
|
+
links: [{ url: "https://example.com/1", title: "one", hasInfo: true }],
|
|
70
|
+
tags: ["a"],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
74
|
+
const run = yield service.getTestRun("run-1");
|
|
75
|
+
expect(callApi).toHaveBeenCalledWith("/api/v2/testRuns/{id}", "GET", { id: "run-1" }, expect.any(Object), expect.any(Object), expect.any(Object), null, ["PrivateToken"], expect.any(Array), expect.any(Array), Object, null);
|
|
76
|
+
expect(run.description).toBe("213123123");
|
|
77
|
+
expect(run.launchSource).toBe("Test IT");
|
|
78
|
+
expect(run.stateName).toBe("Completed");
|
|
79
|
+
expect(run.links).toEqual([
|
|
80
|
+
expect.objectContaining({ url: "https://example.com/1", title: "one" }),
|
|
81
|
+
]);
|
|
82
|
+
expect(run.attachments).toEqual([{ id: "att-1" }]);
|
|
83
|
+
expect(run.tags).toEqual(["a"]);
|
|
84
|
+
expect(run).not.toHaveProperty("testResults");
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
44
87
|
describe("TestRunsService.loadAutotests", () => {
|
|
45
88
|
it("always POST final result even when in-progress id exists in cache", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
89
|
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
@@ -7,7 +7,7 @@ class ZeroStrategy extends base_strategy_1.BaseStrategy {
|
|
|
7
7
|
super(config);
|
|
8
8
|
if (!config.testRunId)
|
|
9
9
|
throw new Error("testRunId is required when mode is 0");
|
|
10
|
-
this.testsInRun = this.client.testResults.getExternalIdsForRun();
|
|
10
|
+
this.testsInRun = this.testRunId.then(() => this.client.testResults.getExternalIdsForRun());
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ZeroStrategy = ZeroStrategy;
|
|
@@ -289,9 +289,6 @@ class ApiClient {
|
|
|
289
289
|
applyAuthToRequest(request, authNames) {
|
|
290
290
|
authNames.forEach(authName => {
|
|
291
291
|
var auth = this.authentications[authName];
|
|
292
|
-
if (!auth) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
292
|
switch (auth.type) {
|
|
296
293
|
case 'basic':
|
|
297
294
|
if (auth.username || auth.password) {
|