@reportportal/client-javascript 5.0.5 → 5.0.7
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/CHANGELOG.md +12 -1
- package/README.md +14 -9
- package/VERSION +1 -1
- package/analytics/analytics.js +7 -7
- package/analytics/constants.js +1 -1
- package/analytics/events.js +8 -7
- package/lib/constants/events.js +7 -7
- package/lib/constants/statuses.js +8 -8
- package/lib/helpers.js +68 -61
- package/lib/publicReportingAPI.js +77 -77
- package/lib/report-portal-client.js +652 -539
- package/lib/rest.js +101 -82
- package/package.json +34 -15
- package/.eslintrc +0 -17
- package/.istanbul.yml +0 -3
- package/spec/analytics.spec.js +0 -46
- package/spec/helper.spec.js +0 -142
- package/spec/publicReportingAPI.spec.js +0 -75
- package/spec/report-portal-client.spec.js +0 -744
- package/spec/rest.spec.js +0 -315
- package/spec/support/jasmine.json +0 -11
- package/version_fragment +0 -1
|
@@ -5,126 +5,128 @@ const helpers = require('./helpers');
|
|
|
5
5
|
const RestClient = require('./rest');
|
|
6
6
|
const Analytics = require('../analytics/analytics');
|
|
7
7
|
const { RP_STATUSES } = require('./constants/statuses');
|
|
8
|
-
const { CLIENT_JAVASCRIPT_EVENTS, getAgentEventLabel } = require('
|
|
8
|
+
const { CLIENT_JAVASCRIPT_EVENTS, getAgentEventLabel } = require('../analytics/events');
|
|
9
9
|
|
|
10
10
|
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
|
|
11
11
|
|
|
12
12
|
class RPClient {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Create a client for RP.
|
|
15
|
+
* @param {Object} params - config object.
|
|
16
|
+
* params should look like this
|
|
17
|
+
* {
|
|
18
|
+
* token: "00000000-0000-0000-0000-000000000000",
|
|
19
|
+
* endpoint: "http://localhost:8080/api/v1",
|
|
20
|
+
* launch: "YOUR LAUNCH NAME",
|
|
21
|
+
* project: "PROJECT NAME",
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} agentParams - agent's info object.
|
|
25
|
+
* agentParams should look like this
|
|
26
|
+
* {
|
|
27
|
+
* name: "AGENT NAME",
|
|
28
|
+
* version: "AGENT VERSION",
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
constructor(params, agentParams) {
|
|
32
|
+
this.debug = params.debug;
|
|
33
|
+
this.isLaunchMergeRequired =
|
|
34
|
+
params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
|
|
35
|
+
this.map = {};
|
|
36
|
+
this.baseURL = [params.endpoint, params.project].join('/');
|
|
37
|
+
const headers = {
|
|
38
|
+
'User-Agent': 'NodeJS',
|
|
39
|
+
Authorization: `bearer ${params.token}`,
|
|
40
|
+
...(params.headers || {}),
|
|
41
|
+
};
|
|
42
|
+
this.headers = headers;
|
|
43
|
+
this.token = params.token;
|
|
44
|
+
this.config = params;
|
|
45
|
+
this.helpers = helpers;
|
|
46
|
+
this.restClient = new RestClient({
|
|
47
|
+
baseURL: this.baseURL,
|
|
48
|
+
headers: this.headers,
|
|
49
|
+
restClientConfig: params.restClientConfig,
|
|
50
|
+
});
|
|
51
|
+
this.analytics = new Analytics(agentParams);
|
|
52
|
+
this.launchUuid = '';
|
|
53
|
+
this.nonRetriedItemMap = new Map();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line valid-jsdoc
|
|
57
|
+
/**
|
|
56
58
|
*
|
|
57
59
|
* @Private
|
|
58
60
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
61
|
+
logDebug(msg, dataMsg = '') {
|
|
62
|
+
if (this.debug) {
|
|
63
|
+
console.log(msg, dataMsg);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') {
|
|
68
|
+
return `${launchId}__${parentId}__${name}__${itemId}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getUniqId() {
|
|
72
|
+
return UniqId();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getRejectAnswer(tempId, error) {
|
|
76
|
+
return {
|
|
77
|
+
tempId,
|
|
78
|
+
promise: Promise.reject(error),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getNewItemObj(startPromiseFunc) {
|
|
83
|
+
let resolveFinish;
|
|
84
|
+
let rejectFinish;
|
|
85
|
+
const obj = {
|
|
86
|
+
promiseStart: new Promise(startPromiseFunc),
|
|
87
|
+
realId: '',
|
|
88
|
+
children: [],
|
|
89
|
+
finishSend: false,
|
|
90
|
+
promiseFinish: new Promise((resolve, reject) => {
|
|
91
|
+
resolveFinish = resolve;
|
|
92
|
+
rejectFinish = reject;
|
|
93
|
+
}),
|
|
94
|
+
};
|
|
95
|
+
obj.resolveFinish = resolveFinish;
|
|
96
|
+
obj.rejectFinish = rejectFinish;
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// eslint-disable-next-line valid-jsdoc
|
|
101
|
+
/**
|
|
100
102
|
*
|
|
101
103
|
* @Private
|
|
102
104
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
cleanMap(ids) {
|
|
106
|
+
ids.forEach((id) => {
|
|
107
|
+
delete this.map[id];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
checkConnect() {
|
|
112
|
+
const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join('/');
|
|
113
|
+
return RestClient.request('GET', url, {}, { headers: this.headers });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
triggerAnalyticsEvent() {
|
|
117
|
+
if (process.env.REPORTPORTAL_CLIENT_JS_NO_ANALYTICS) {
|
|
118
|
+
return;
|
|
107
119
|
}
|
|
108
120
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
if (this.analytics.agentParams) {
|
|
122
|
+
const label = getAgentEventLabel(this.analytics.agentParams);
|
|
123
|
+
this.analytics.trackEvent(Object.assign(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label }));
|
|
124
|
+
} else {
|
|
125
|
+
this.analytics.trackEvent(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH);
|
|
112
126
|
}
|
|
127
|
+
}
|
|
113
128
|
|
|
114
|
-
|
|
115
|
-
if (process.env.REPORTPORTAL_CLIENT_JS_NO_ANALYTICS) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (this.analytics.agentParams) {
|
|
120
|
-
const label = getAgentEventLabel(this.analytics.agentParams);
|
|
121
|
-
this.analytics.trackEvent(Object.assign(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label }));
|
|
122
|
-
} else {
|
|
123
|
-
this.analytics.trackEvent(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
129
|
+
/**
|
|
128
130
|
* Start launch and report it.
|
|
129
131
|
* @param {Object} launchDataRQ - request object.
|
|
130
132
|
* launchDataRQ should look like this
|
|
@@ -163,167 +165,191 @@ class RPClient {
|
|
|
163
165
|
* or it would throw an error.
|
|
164
166
|
* @Returns {Object} - an object which contains a tempID and a promise
|
|
165
167
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
resolve(response);
|
|
197
|
-
}, (error) => {
|
|
198
|
-
console.dir(error);
|
|
199
|
-
reject(error);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
this.triggerAnalyticsEvent();
|
|
204
|
-
return {
|
|
205
|
-
tempId,
|
|
206
|
-
promise: this.map[tempId].promiseStart,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Finish launch.
|
|
212
|
-
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
213
|
-
* @param {Object} finishExecutionRQ - finish launch info should include time and status.
|
|
214
|
-
* finishExecutionRQ should look like this
|
|
215
|
-
* {
|
|
216
|
-
* "endTime": this.helper.now(),
|
|
217
|
-
* "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
|
|
218
|
-
* }
|
|
219
|
-
* @Returns {Object} - an object which contains a tempID and a promise
|
|
220
|
-
*/
|
|
221
|
-
finishLaunch(launchTempId, finishExecutionRQ) {
|
|
222
|
-
const launchObj = this.map[launchTempId];
|
|
223
|
-
if (!launchObj) {
|
|
224
|
-
return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const finishExecutionData = Object.assign({ endTime: this.helpers.now() }, finishExecutionRQ);
|
|
228
|
-
|
|
229
|
-
launchObj.finishSend = true;
|
|
230
|
-
Promise.all(launchObj.children.map(itemId => this.map[itemId].promiseFinish))
|
|
231
|
-
.then(() => {
|
|
232
|
-
launchObj.promiseStart
|
|
233
|
-
.then(() => {
|
|
234
|
-
this.logDebug(`Finish launch ${launchTempId}`);
|
|
235
|
-
const url = ['launch', launchObj.realId, 'finish'].join('/');
|
|
236
|
-
this.restClient.update(url, finishExecutionData, { headers: this.headers })
|
|
237
|
-
.then((response) => {
|
|
238
|
-
this.logDebug(`Success finish launch ${launchTempId}`);
|
|
239
|
-
launchObj.resolveFinish(response);
|
|
240
|
-
}, (error) => {
|
|
241
|
-
this.logDebug(`Error finish launch ${launchTempId}`);
|
|
242
|
-
console.dir(error);
|
|
243
|
-
launchObj.rejectFinish(error);
|
|
244
|
-
});
|
|
245
|
-
}, (error) => {
|
|
246
|
-
launchObj.rejectFinish(error);
|
|
247
|
-
});
|
|
248
|
-
}, (error) => {
|
|
249
|
-
launchObj.rejectFinish(error);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
tempId: launchTempId,
|
|
254
|
-
promise: launchObj.promiseFinish,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
168
|
+
startLaunch(launchDataRQ) {
|
|
169
|
+
const tempId = this.getUniqId();
|
|
170
|
+
|
|
171
|
+
if (launchDataRQ.id) {
|
|
172
|
+
this.map[tempId] = this.getNewItemObj((resolve) => resolve(launchDataRQ));
|
|
173
|
+
this.map[tempId].realId = launchDataRQ.id;
|
|
174
|
+
this.launchUuid = launchDataRQ.id;
|
|
175
|
+
} else {
|
|
176
|
+
const systemAttr = helpers.getSystemAttribute();
|
|
177
|
+
const attributes = Array.isArray(launchDataRQ.attributes)
|
|
178
|
+
? launchDataRQ.attributes.concat(systemAttr)
|
|
179
|
+
: systemAttr;
|
|
180
|
+
const launchData = {
|
|
181
|
+
name: this.config.launch || 'Test launch name',
|
|
182
|
+
startTime: this.helpers.now(),
|
|
183
|
+
...launchDataRQ,
|
|
184
|
+
attributes,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
188
|
+
const url = 'launch';
|
|
189
|
+
this.logDebug(`Start launch with tempId ${tempId}`, launchDataRQ);
|
|
190
|
+
this.restClient.create(url, launchData, { headers: this.headers }).then(
|
|
191
|
+
(response) => {
|
|
192
|
+
this.map[tempId].realId = response.id;
|
|
193
|
+
this.launchUuid = response.id;
|
|
194
|
+
|
|
195
|
+
if (this.isLaunchMergeRequired) {
|
|
196
|
+
helpers.saveLaunchIdToFile(response.id);
|
|
197
|
+
}
|
|
257
198
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
launches: launchIds,
|
|
269
|
-
mergeType: "BASIC",
|
|
270
|
-
mode: "DEFAULT",
|
|
271
|
-
name: this.config.launch || 'Test launch name',
|
|
272
|
-
attributes: this.config.attributes,
|
|
273
|
-
};
|
|
199
|
+
this.logDebug(`Success start launch with tempId ${tempId}`, response);
|
|
200
|
+
resolve(response);
|
|
201
|
+
},
|
|
202
|
+
(error) => {
|
|
203
|
+
this.logDebug(`Error start launch with tempId ${tempId}`, error);
|
|
204
|
+
console.dir(error);
|
|
205
|
+
reject(error);
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
});
|
|
274
209
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return this.restClient.create(mergeURL, request, { headers: this.headers });
|
|
301
|
-
})
|
|
302
|
-
.then(() => {
|
|
303
|
-
this.logDebug(`Launches successfully merged!`);
|
|
304
|
-
})
|
|
305
|
-
.catch((error) => {
|
|
306
|
-
this.logDebug('ERROR');
|
|
307
|
-
this.logDebug(error);
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
this.logDebug('Option isLaunchMergeRequired is false');
|
|
210
|
+
this.triggerAnalyticsEvent();
|
|
211
|
+
return {
|
|
212
|
+
tempId,
|
|
213
|
+
promise: this.map[tempId].promiseStart,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Finish launch.
|
|
219
|
+
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
220
|
+
* @param {Object} finishExecutionRQ - finish launch info should include time and status.
|
|
221
|
+
* finishExecutionRQ should look like this
|
|
222
|
+
* {
|
|
223
|
+
* "endTime": this.helper.now(),
|
|
224
|
+
* "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
|
|
225
|
+
* }
|
|
226
|
+
* @Returns {Object} - an object which contains a tempID and a promise
|
|
227
|
+
*/
|
|
228
|
+
finishLaunch(launchTempId, finishExecutionRQ) {
|
|
229
|
+
const launchObj = this.map[launchTempId];
|
|
230
|
+
if (!launchObj) {
|
|
231
|
+
return this.getRejectAnswer(
|
|
232
|
+
launchTempId,
|
|
233
|
+
new Error(`Launch with tempId "${launchTempId}" not found`),
|
|
234
|
+
);
|
|
311
235
|
}
|
|
312
236
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
237
|
+
const finishExecutionData = { endTime: this.helpers.now(), ...finishExecutionRQ };
|
|
238
|
+
|
|
239
|
+
launchObj.finishSend = true;
|
|
240
|
+
Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish)).then(
|
|
241
|
+
() => {
|
|
242
|
+
launchObj.promiseStart.then(
|
|
243
|
+
() => {
|
|
244
|
+
this.logDebug(`Finish launch with tempId ${launchTempId}`, finishExecutionData);
|
|
245
|
+
const url = ['launch', launchObj.realId, 'finish'].join('/');
|
|
246
|
+
this.restClient.update(url, finishExecutionData, { headers: this.headers }).then(
|
|
247
|
+
(response) => {
|
|
248
|
+
this.logDebug(`Success finish launch with tempId ${launchTempId}`, response);
|
|
249
|
+
launchObj.resolveFinish(response);
|
|
250
|
+
},
|
|
251
|
+
(error) => {
|
|
252
|
+
this.logDebug(`Error finish launch with tempId ${launchTempId}`, error);
|
|
253
|
+
console.dir(error);
|
|
254
|
+
launchObj.rejectFinish(error);
|
|
255
|
+
},
|
|
256
|
+
);
|
|
257
|
+
},
|
|
258
|
+
(error) => {
|
|
259
|
+
console.dir(error);
|
|
260
|
+
launchObj.rejectFinish(error);
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
},
|
|
264
|
+
(error) => {
|
|
265
|
+
console.dir(error);
|
|
266
|
+
launchObj.rejectFinish(error);
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
tempId: launchTempId,
|
|
272
|
+
promise: launchObj.promiseFinish,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/*
|
|
277
|
+
* This method is used to create data object for merge request to ReportPortal.
|
|
278
|
+
*
|
|
279
|
+
* @Returns {Object} - an object which contains a data for merge launches in ReportPortal.
|
|
280
|
+
*/
|
|
281
|
+
getMergeLaunchesRequest(launchIds) {
|
|
282
|
+
return {
|
|
283
|
+
description: 'Merged launch',
|
|
284
|
+
endTime: this.helpers.now(),
|
|
285
|
+
extendSuitesDescription: true,
|
|
286
|
+
launches: launchIds,
|
|
287
|
+
mergeType: 'BASIC',
|
|
288
|
+
mode: 'DEFAULT',
|
|
289
|
+
name: this.config.launch || 'Test launch name',
|
|
290
|
+
attributes: this.config.attributes,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/*
|
|
295
|
+
* This method is used for merge launches in ReportPortal.
|
|
296
|
+
*
|
|
297
|
+
* Please, keep in mind that this method is work only in case
|
|
298
|
+
* the option isLaunchMergeRequired is true.
|
|
299
|
+
*/
|
|
300
|
+
mergeLaunches() {
|
|
301
|
+
if (this.isLaunchMergeRequired) {
|
|
302
|
+
const launchUUIds = helpers.readLaunchesFromFile();
|
|
303
|
+
const params = new URLSearchParams({
|
|
304
|
+
'filter.in.uuid': launchUUIds,
|
|
305
|
+
});
|
|
306
|
+
const launchSearchUrl = `launch?${params.toString()}`;
|
|
307
|
+
this.logDebug(`Find launches with UUIDs to merge: ${launchUUIds}`);
|
|
308
|
+
return this.restClient
|
|
309
|
+
.retrieveSyncAPI(launchSearchUrl, { headers: this.headers })
|
|
310
|
+
.then(
|
|
311
|
+
(response) => {
|
|
312
|
+
const launchIds = response.content.map((launch) => launch.id);
|
|
313
|
+
this.logDebug(`Found launches: ${launchIds}`, response.content);
|
|
314
|
+
return launchIds;
|
|
315
|
+
},
|
|
316
|
+
(error) => {
|
|
317
|
+
this.logDebug(`Error during launches search with UUIDs: ${launchUUIds}`, error);
|
|
318
|
+
console.dir(error);
|
|
319
|
+
},
|
|
320
|
+
)
|
|
321
|
+
.then((launchIds) => {
|
|
322
|
+
const request = this.getMergeLaunchesRequest(launchIds);
|
|
323
|
+
this.logDebug(`Merge launches with ids: ${launchIds}`, request);
|
|
324
|
+
const mergeURL = 'launch/merge';
|
|
325
|
+
return this.restClient.create(mergeURL, request, { headers: this.headers });
|
|
326
|
+
})
|
|
327
|
+
.then(() => {
|
|
328
|
+
this.logDebug(`Launches with UUIDs: ${launchUUIds} were successfully merged!`);
|
|
329
|
+
})
|
|
330
|
+
.catch((error) => {
|
|
331
|
+
this.logDebug(`Error merging launches with UUIDs: ${launchUUIds}`, error);
|
|
332
|
+
console.dir(error);
|
|
333
|
+
});
|
|
323
334
|
}
|
|
335
|
+
this.logDebug(
|
|
336
|
+
'Option isLaunchMergeRequired is false, merge process cannot be done as no launch UUIDs where saved.',
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/*
|
|
341
|
+
* This method is used for frameworks as Jasmine. There is problem when
|
|
342
|
+
* it doesn't wait for promise resolve and stop the process. So it better to call
|
|
343
|
+
* this method at the spec's function as @afterAll() and manually resolve this promise.
|
|
344
|
+
*
|
|
345
|
+
* @return Promise
|
|
346
|
+
*/
|
|
347
|
+
getPromiseFinishAllItems(launchTempId) {
|
|
348
|
+
const launchObj = this.map[launchTempId];
|
|
349
|
+
return Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish));
|
|
350
|
+
}
|
|
324
351
|
|
|
325
|
-
|
|
326
|
-
/**
|
|
352
|
+
/**
|
|
327
353
|
* Update launch.
|
|
328
354
|
* @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
|
|
329
355
|
* @param {Object} launchData - new launch data
|
|
@@ -343,37 +369,48 @@ class RPClient {
|
|
|
343
369
|
}
|
|
344
370
|
* @Returns {Object} - an object which contains a tempId and a promise
|
|
345
371
|
*/
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const promise = new Promise((resolve, reject) => {
|
|
354
|
-
resolvePromise = resolve;
|
|
355
|
-
rejectPromise = reject;
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
launchObj.promiseFinish.then(() => {
|
|
359
|
-
const url = ['launch', launchObj.realId, 'update'].join('/');
|
|
360
|
-
this.restClient.update(url, launchData, { headers: this.headers })
|
|
361
|
-
.then((response) => {
|
|
362
|
-
resolvePromise(response);
|
|
363
|
-
}, (error) => {
|
|
364
|
-
rejectPromise(error);
|
|
365
|
-
});
|
|
366
|
-
}, (error) => {
|
|
367
|
-
rejectPromise(error);
|
|
368
|
-
});
|
|
369
|
-
return {
|
|
370
|
-
tempId: launchTempId,
|
|
371
|
-
promise,
|
|
372
|
-
};
|
|
372
|
+
updateLaunch(launchTempId, launchData) {
|
|
373
|
+
const launchObj = this.map[launchTempId];
|
|
374
|
+
if (!launchObj) {
|
|
375
|
+
return this.getRejectAnswer(
|
|
376
|
+
launchTempId,
|
|
377
|
+
new Error(`Launch with tempId "${launchTempId}" not found`),
|
|
378
|
+
);
|
|
373
379
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
380
|
+
let resolvePromise;
|
|
381
|
+
let rejectPromise;
|
|
382
|
+
const promise = new Promise((resolve, reject) => {
|
|
383
|
+
resolvePromise = resolve;
|
|
384
|
+
rejectPromise = reject;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
launchObj.promiseFinish.then(
|
|
388
|
+
() => {
|
|
389
|
+
const url = ['launch', launchObj.realId, 'update'].join('/');
|
|
390
|
+
this.logDebug(`Update launch with tempId ${launchTempId}`, launchData);
|
|
391
|
+
this.restClient.update(url, launchData, { headers: this.headers }).then(
|
|
392
|
+
(response) => {
|
|
393
|
+
this.logDebug(`Launch with tempId ${launchTempId} were successfully updated`, response);
|
|
394
|
+
resolvePromise(response);
|
|
395
|
+
},
|
|
396
|
+
(error) => {
|
|
397
|
+
this.logDebug(`Error when updating launch with tempId ${launchTempId}`, error);
|
|
398
|
+
console.dir(error);
|
|
399
|
+
rejectPromise(error);
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
},
|
|
403
|
+
(error) => {
|
|
404
|
+
rejectPromise(error);
|
|
405
|
+
},
|
|
406
|
+
);
|
|
407
|
+
return {
|
|
408
|
+
tempId: launchTempId,
|
|
409
|
+
promise,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
377
414
|
* If there is no parentItemId starts Suite, else starts test or item.
|
|
378
415
|
* @param {Object} testItemDataRQ - object with item parameters
|
|
379
416
|
* testItemDataRQ should look like this
|
|
@@ -400,83 +437,100 @@ class RPClient {
|
|
|
400
437
|
* @param {string} parentTempId (optional) - temp item id (returned in the query "startTestItem").
|
|
401
438
|
* @Returns {Object} - an object which contains a tempId and a promise
|
|
402
439
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
let parentPromise = launchObj.promiseStart;
|
|
421
|
-
if (parentTempId) {
|
|
422
|
-
parentMapId = parentTempId;
|
|
423
|
-
const parentObj = this.map[parentTempId];
|
|
424
|
-
if (!parentObj) {
|
|
425
|
-
return this.getRejectAnswer(launchTempId, new Error(`Item "${parentTempId}" not found`));
|
|
426
|
-
}
|
|
427
|
-
parentPromise = parentObj.promiseStart;
|
|
428
|
-
}
|
|
440
|
+
startTestItem(testItemDataRQ, launchTempId, parentTempId) {
|
|
441
|
+
let parentMapId = launchTempId;
|
|
442
|
+
const launchObj = this.map[launchTempId];
|
|
443
|
+
if (!launchObj) {
|
|
444
|
+
return this.getRejectAnswer(
|
|
445
|
+
launchTempId,
|
|
446
|
+
new Error(`Launch with tempId "${launchTempId}" not found`),
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
// TODO: Allow items reporting to finished launch
|
|
450
|
+
if (launchObj.finishSend) {
|
|
451
|
+
const err = new Error(
|
|
452
|
+
`Launch with tempId "${launchTempId}" is already finished, you can not add an item to it`,
|
|
453
|
+
);
|
|
454
|
+
return this.getRejectAnswer(launchTempId, err);
|
|
455
|
+
}
|
|
429
456
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
457
|
+
const testCaseId =
|
|
458
|
+
testItemDataRQ.testCaseId ||
|
|
459
|
+
helpers.generateTestCaseId(testItemDataRQ.codeRef, testItemDataRQ.parameters);
|
|
460
|
+
const testItemData = {
|
|
461
|
+
startTime: this.helpers.now(),
|
|
462
|
+
...testItemDataRQ,
|
|
463
|
+
...(testCaseId && { testCaseId }),
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
let parentPromise = launchObj.promiseStart;
|
|
467
|
+
if (parentTempId) {
|
|
468
|
+
parentMapId = parentTempId;
|
|
469
|
+
const parentObj = this.map[parentTempId];
|
|
470
|
+
if (!parentObj) {
|
|
471
|
+
return this.getRejectAnswer(
|
|
472
|
+
launchTempId,
|
|
473
|
+
new Error(`Item with tempId "${parentTempId}" not found`),
|
|
435
474
|
);
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
475
|
+
}
|
|
476
|
+
parentPromise = parentObj.promiseStart;
|
|
477
|
+
}
|
|
440
478
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.logDebug(`Start test item ${tempId}`);
|
|
452
|
-
this.restClient.create(url, testItemData, { headers: this.headers })
|
|
453
|
-
.then((response) => {
|
|
454
|
-
this.logDebug(`Success start item ${tempId}`);
|
|
455
|
-
this.map[tempId].realId = response.id;
|
|
456
|
-
this.nonRetriedItemMap.delete(itemKey);
|
|
457
|
-
resolve(response);
|
|
458
|
-
}, (error) => {
|
|
459
|
-
this.logDebug(`Error start item ${tempId}:`);
|
|
460
|
-
console.dir(error);
|
|
461
|
-
reject(error);
|
|
462
|
-
});
|
|
463
|
-
}, (error) => {
|
|
464
|
-
reject(error);
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
this.map[parentMapId].children.push(tempId);
|
|
479
|
+
const itemKey = this.calculateNonRetriedItemMapKey(
|
|
480
|
+
launchTempId,
|
|
481
|
+
parentTempId,
|
|
482
|
+
testItemDataRQ.name,
|
|
483
|
+
testItemDataRQ.uniqueId,
|
|
484
|
+
);
|
|
485
|
+
const firstNonRetriedItemPromise = testItemDataRQ.retry && this.nonRetriedItemMap.get(itemKey);
|
|
486
|
+
if (firstNonRetriedItemPromise) {
|
|
487
|
+
parentPromise = Promise.all([parentPromise, firstNonRetriedItemPromise]);
|
|
488
|
+
}
|
|
468
489
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
490
|
+
const tempId = this.getUniqId();
|
|
491
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
492
|
+
parentPromise.then(
|
|
493
|
+
() => {
|
|
494
|
+
const realLaunchId = this.map[launchTempId].realId;
|
|
495
|
+
let url = 'item/';
|
|
496
|
+
if (parentTempId) {
|
|
497
|
+
const realParentId = this.map[parentTempId].realId;
|
|
498
|
+
url += `${realParentId}`;
|
|
499
|
+
}
|
|
500
|
+
testItemData.launchUuid = realLaunchId;
|
|
501
|
+
this.logDebug(`Start test item with tempId ${tempId}`, testItemData);
|
|
502
|
+
this.restClient.create(url, testItemData, { headers: this.headers }).then(
|
|
503
|
+
(response) => {
|
|
504
|
+
this.logDebug(`Success start item with tempId ${tempId}`, response);
|
|
505
|
+
this.map[tempId].realId = response.id;
|
|
506
|
+
this.nonRetriedItemMap.delete(itemKey);
|
|
507
|
+
resolve(response);
|
|
508
|
+
},
|
|
509
|
+
(error) => {
|
|
510
|
+
this.logDebug(`Error start item with tempId ${tempId}`, error);
|
|
511
|
+
console.dir(error);
|
|
512
|
+
reject(error);
|
|
513
|
+
},
|
|
514
|
+
);
|
|
515
|
+
},
|
|
516
|
+
(error) => {
|
|
517
|
+
reject(error);
|
|
518
|
+
},
|
|
519
|
+
);
|
|
520
|
+
});
|
|
521
|
+
this.map[parentMapId].children.push(tempId);
|
|
472
522
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
promise: this.map[tempId].promiseStart,
|
|
476
|
-
};
|
|
523
|
+
if (!testItemDataRQ.retry) {
|
|
524
|
+
this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart);
|
|
477
525
|
}
|
|
478
526
|
|
|
479
|
-
|
|
527
|
+
return {
|
|
528
|
+
tempId,
|
|
529
|
+
promise: this.map[tempId].promiseStart,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
480
534
|
* Finish Suite or Step level.
|
|
481
535
|
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
482
536
|
* @param {Object} finishTestItemRQ - object with item parameters.
|
|
@@ -500,112 +554,142 @@ class RPClient {
|
|
|
500
554
|
}
|
|
501
555
|
* @Returns {Object} - an object which contains a tempId and a promise
|
|
502
556
|
*/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
endTime: this.helpers.now(),
|
|
511
|
-
}, itemObj.children.length ? {} : { status: RP_STATUSES.PASSED }, finishTestItemRQ);
|
|
512
|
-
|
|
513
|
-
itemObj.finishSend = true;
|
|
514
|
-
Promise.all(itemObj.children.map(itemId => this.map[itemId] && this.map[itemId].promiseFinish))
|
|
515
|
-
.then(() => {
|
|
516
|
-
this.cleanMap(itemObj.children);
|
|
517
|
-
this.finishTestItemPromiseStart(itemObj,
|
|
518
|
-
itemTempId,
|
|
519
|
-
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }));
|
|
520
|
-
}, () => {
|
|
521
|
-
this.cleanMap(itemObj.children);
|
|
522
|
-
this.logDebug(`Error finish children of test item ${itemTempId}`);
|
|
523
|
-
this.logDebug(`Finish test item ${itemTempId}`);
|
|
524
|
-
this.finishTestItemPromiseStart(itemObj,
|
|
525
|
-
itemTempId,
|
|
526
|
-
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }));
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
return {
|
|
530
|
-
tempId: itemTempId,
|
|
531
|
-
promise: itemObj.promiseFinish,
|
|
532
|
-
};
|
|
557
|
+
finishTestItem(itemTempId, finishTestItemRQ) {
|
|
558
|
+
const itemObj = this.map[itemTempId];
|
|
559
|
+
if (!itemObj) {
|
|
560
|
+
return this.getRejectAnswer(
|
|
561
|
+
itemTempId,
|
|
562
|
+
new Error(`Item with tempId "${itemTempId}" not found`),
|
|
563
|
+
);
|
|
533
564
|
}
|
|
534
565
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
566
|
+
const finishTestItemData = {
|
|
567
|
+
endTime: this.helpers.now(),
|
|
568
|
+
...(itemObj.children.length ? {} : { status: RP_STATUSES.PASSED }),
|
|
569
|
+
...finishTestItemRQ,
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
itemObj.finishSend = true;
|
|
573
|
+
this.logDebug(`Finish all children for test item with tempId ${itemTempId}`);
|
|
574
|
+
Promise.all(
|
|
575
|
+
itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish),
|
|
576
|
+
).then(
|
|
577
|
+
() => {
|
|
578
|
+
this.cleanMap(itemObj.children);
|
|
579
|
+
this.logDebug(
|
|
580
|
+
`All children for test item with tempId ${itemTempId} successfully finished.`,
|
|
581
|
+
);
|
|
582
|
+
this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
|
|
583
|
+
this.finishTestItemPromiseStart(
|
|
584
|
+
itemObj,
|
|
585
|
+
itemTempId,
|
|
586
|
+
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
587
|
+
);
|
|
588
|
+
},
|
|
589
|
+
() => {
|
|
590
|
+
this.cleanMap(itemObj.children);
|
|
591
|
+
this.logDebug(`Error finish children of test item with tempId ${itemTempId}`);
|
|
592
|
+
this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
|
|
593
|
+
this.finishTestItemPromiseStart(
|
|
594
|
+
itemObj,
|
|
595
|
+
itemTempId,
|
|
596
|
+
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
597
|
+
);
|
|
598
|
+
},
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
return {
|
|
602
|
+
tempId: itemTempId,
|
|
603
|
+
promise: itemObj.promiseFinish,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
saveLog(itemObj, requestPromiseFunc) {
|
|
608
|
+
const tempId = this.getUniqId();
|
|
609
|
+
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
610
|
+
itemObj.promiseStart.then(
|
|
611
|
+
() => {
|
|
612
|
+
this.logDebug(`Save log with tempId ${tempId}`, itemObj);
|
|
613
|
+
requestPromiseFunc(itemObj.realId, this.launchUuid).then(
|
|
614
|
+
(response) => {
|
|
615
|
+
this.logDebug(`Successfully save log with tempId ${tempId}`, response);
|
|
616
|
+
resolve(response);
|
|
617
|
+
},
|
|
618
|
+
(error) => {
|
|
619
|
+
this.logDebug(`Error save log with tempId ${tempId}`, error);
|
|
620
|
+
console.dir(error);
|
|
621
|
+
reject(error);
|
|
622
|
+
},
|
|
623
|
+
);
|
|
624
|
+
},
|
|
625
|
+
(error) => {
|
|
626
|
+
reject(error);
|
|
627
|
+
},
|
|
628
|
+
);
|
|
629
|
+
});
|
|
630
|
+
itemObj.children.push(tempId);
|
|
631
|
+
|
|
632
|
+
const logObj = this.map[tempId];
|
|
633
|
+
logObj.finishSend = true;
|
|
634
|
+
logObj.promiseStart.then(
|
|
635
|
+
(response) => logObj.resolveFinish(response),
|
|
636
|
+
(error) => logObj.rejectFinish(error),
|
|
637
|
+
);
|
|
638
|
+
|
|
639
|
+
return {
|
|
640
|
+
tempId,
|
|
641
|
+
promise: this.map[tempId].promiseFinish,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
sendLog(itemTempId, saveLogRQ, fileObj) {
|
|
646
|
+
const saveLogData = {
|
|
647
|
+
time: this.helpers.now(),
|
|
648
|
+
message: '',
|
|
649
|
+
level: '',
|
|
650
|
+
...saveLogRQ,
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
if (fileObj) {
|
|
654
|
+
return this.sendLogWithFile(itemTempId, saveLogData, fileObj);
|
|
574
655
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
return this.restClient.create(
|
|
598
|
-
url,
|
|
599
|
-
Object.assign(saveLogRQ,
|
|
600
|
-
{ launchUuid },
|
|
601
|
-
isItemUuid && { itemUuid }),
|
|
602
|
-
{ headers: this.headers },
|
|
603
|
-
);
|
|
604
|
-
};
|
|
605
|
-
return this.saveLog(itemObj, requestPromise);
|
|
656
|
+
return this.sendLogWithoutFile(itemTempId, saveLogData);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Send log of test results.
|
|
661
|
+
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
662
|
+
* @param {Object} saveLogRQ - object with data of test result.
|
|
663
|
+
* saveLogRQ should look like this
|
|
664
|
+
* {
|
|
665
|
+
* level: 'error' or one of 'trace', 'debug', 'info', 'warn', 'error', '',
|
|
666
|
+
* message: 'string' (support markdown),
|
|
667
|
+
* time: this.helpers.now()
|
|
668
|
+
* }
|
|
669
|
+
* @Returns {Object} - an object which contains a tempId and a promise
|
|
670
|
+
*/
|
|
671
|
+
sendLogWithoutFile(itemTempId, saveLogRQ) {
|
|
672
|
+
const itemObj = this.map[itemTempId];
|
|
673
|
+
if (!itemObj) {
|
|
674
|
+
return this.getRejectAnswer(
|
|
675
|
+
itemTempId,
|
|
676
|
+
new Error(`Item with tempId "${itemTempId}" not found`),
|
|
677
|
+
);
|
|
606
678
|
}
|
|
607
679
|
|
|
608
|
-
|
|
680
|
+
const requestPromise = (itemUuid, launchUuid) => {
|
|
681
|
+
const url = 'log';
|
|
682
|
+
const isItemUuid = itemUuid !== launchUuid;
|
|
683
|
+
return this.restClient.create(
|
|
684
|
+
url,
|
|
685
|
+
Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
|
|
686
|
+
{ headers: this.headers },
|
|
687
|
+
);
|
|
688
|
+
};
|
|
689
|
+
return this.saveLog(itemObj, requestPromise);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
609
693
|
* Send log of test results with file.
|
|
610
694
|
* @param {string} itemTempId - temp item id (returned in the query "startTestItem").
|
|
611
695
|
* @param {Object} saveLogRQ - object with data of test result.
|
|
@@ -626,89 +710,118 @@ class RPClient {
|
|
|
626
710
|
* }
|
|
627
711
|
* @Returns {Object} - an object which contains a tempId and a promise
|
|
628
712
|
*/
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const isItemUuid = itemUuid !== launchUuid;
|
|
637
|
-
|
|
638
|
-
// eslint-disable-next-line max-len
|
|
639
|
-
return this.getRequestLogWithFile(Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }), fileObj);
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
return this.saveLog(itemObj, requestPromise);
|
|
713
|
+
sendLogWithFile(itemTempId, saveLogRQ, fileObj) {
|
|
714
|
+
const itemObj = this.map[itemTempId];
|
|
715
|
+
if (!itemObj) {
|
|
716
|
+
return this.getRejectAnswer(
|
|
717
|
+
itemTempId,
|
|
718
|
+
new Error(`Item with tempId "${itemTempId}" not found`),
|
|
719
|
+
);
|
|
643
720
|
}
|
|
644
721
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
722
|
+
const requestPromise = (itemUuid, launchUuid) => {
|
|
723
|
+
const isItemUuid = itemUuid !== launchUuid;
|
|
724
|
+
|
|
725
|
+
return this.getRequestLogWithFile(
|
|
726
|
+
Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
|
|
727
|
+
fileObj,
|
|
728
|
+
);
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
return this.saveLog(itemObj, requestPromise);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
getRequestLogWithFile(saveLogRQ, fileObj) {
|
|
735
|
+
const url = 'log';
|
|
736
|
+
// eslint-disable-next-line no-param-reassign
|
|
737
|
+
saveLogRQ.file = { name: fileObj.name };
|
|
738
|
+
this.logDebug(`Save log with file: ${fileObj.name}`, saveLogRQ);
|
|
739
|
+
return this.restClient
|
|
740
|
+
.create(url, this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY), {
|
|
741
|
+
headers: {
|
|
742
|
+
...this.headers,
|
|
743
|
+
'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`,
|
|
744
|
+
},
|
|
745
|
+
})
|
|
746
|
+
.then((response) => {
|
|
747
|
+
this.logDebug(`Success save log with file: ${fileObj.name}`, response);
|
|
748
|
+
return response;
|
|
749
|
+
})
|
|
750
|
+
.catch((error) => {
|
|
751
|
+
this.logDebug(`Error save log with file: ${fileObj.name}`, error);
|
|
752
|
+
console.dir(error);
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// eslint-disable-next-line valid-jsdoc
|
|
757
|
+
/**
|
|
667
758
|
*
|
|
668
759
|
* @Private
|
|
669
760
|
*/
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
761
|
+
buildMultiPartStream(jsonPart, filePart, boundary) {
|
|
762
|
+
const eol = '\r\n';
|
|
763
|
+
const bx = `--${boundary}`;
|
|
764
|
+
const buffers = [
|
|
765
|
+
// eslint-disable-next-line function-paren-newline
|
|
766
|
+
Buffer.from(
|
|
767
|
+
// eslint-disable-next-line prefer-template
|
|
768
|
+
bx +
|
|
769
|
+
eol +
|
|
770
|
+
'Content-Disposition: form-data; name="json_request_part"' +
|
|
771
|
+
eol +
|
|
772
|
+
'Content-Type: application/json' +
|
|
773
|
+
eol +
|
|
774
|
+
eol +
|
|
775
|
+
eol +
|
|
776
|
+
JSON.stringify(jsonPart) +
|
|
777
|
+
eol,
|
|
778
|
+
),
|
|
779
|
+
// eslint-disable-next-line function-paren-newline
|
|
780
|
+
Buffer.from(
|
|
781
|
+
// eslint-disable-next-line prefer-template
|
|
782
|
+
bx +
|
|
783
|
+
eol +
|
|
784
|
+
'Content-Disposition: form-data; name="file"; filename="' +
|
|
785
|
+
filePart.name +
|
|
786
|
+
'"' +
|
|
787
|
+
eol +
|
|
788
|
+
'Content-Type: ' +
|
|
789
|
+
filePart.type +
|
|
790
|
+
eol +
|
|
791
|
+
eol,
|
|
792
|
+
),
|
|
793
|
+
Buffer.from(filePart.content, 'base64'),
|
|
794
|
+
Buffer.from(`${eol + bx}--${eol}`),
|
|
795
|
+
];
|
|
796
|
+
return Buffer.concat(buffers);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
finishTestItemPromiseStart(itemObj, itemTempId, finishTestItemData) {
|
|
800
|
+
itemObj.promiseStart.then(
|
|
801
|
+
() => {
|
|
802
|
+
const url = ['item', itemObj.realId].join('/');
|
|
803
|
+
this.logDebug(`Finish test item with tempId ${itemTempId}`, itemObj);
|
|
804
|
+
this.restClient
|
|
805
|
+
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }), {
|
|
806
|
+
headers: this.headers,
|
|
807
|
+
})
|
|
808
|
+
.then(
|
|
809
|
+
(response) => {
|
|
810
|
+
this.logDebug(`Success finish item with tempId ${itemTempId}`, response);
|
|
811
|
+
itemObj.resolveFinish(response);
|
|
812
|
+
},
|
|
813
|
+
(error) => {
|
|
814
|
+
this.logDebug(`Error finish test item with tempId ${itemTempId}`, error);
|
|
815
|
+
console.dir(error);
|
|
816
|
+
itemObj.rejectFinish(error);
|
|
817
|
+
},
|
|
818
|
+
);
|
|
819
|
+
},
|
|
820
|
+
(error) => {
|
|
821
|
+
itemObj.rejectFinish(error);
|
|
822
|
+
},
|
|
823
|
+
);
|
|
824
|
+
}
|
|
712
825
|
}
|
|
713
826
|
|
|
714
827
|
module.exports = RPClient;
|