@reportportal/client-javascript 5.0.2 → 5.0.6
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 +44 -18
- package/LICENSE.txt +200 -200
- package/README.md +310 -297
- package/VERSION +1 -1
- package/analytics/analytics.js +15 -15
- package/analytics/constants.js +7 -7
- package/analytics/events.js +16 -16
- package/lib/constants/events.js +7 -7
- package/lib/constants/statuses.js +12 -12
- package/lib/helpers.js +85 -85
- package/lib/publicReportingAPI.js +92 -92
- package/lib/report-portal-client.js +719 -711
- package/lib/rest.js +98 -60
- package/package.json +65 -60
- package/.eslintrc +0 -17
- package/.idea/client-javascript.iml +0 -12
- package/.idea/codeStyles/Project.xml +0 -22
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/copyright/APACHE_2_0.xml +0 -6
- package/.idea/copyright/profiles_settings.xml +0 -3
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -571
- 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 -730
- package/spec/rest.spec.js +0 -287
- package/spec/support/jasmine.json +0 -11
- package/version_fragment +0 -1
|
@@ -1,730 +0,0 @@
|
|
|
1
|
-
const RPClient = require('../lib/report-portal-client.js');
|
|
2
|
-
const RestClient = require('../lib/rest');
|
|
3
|
-
const helpers = require('../lib/helpers');
|
|
4
|
-
const events = require('../analytics/events');
|
|
5
|
-
|
|
6
|
-
describe('ReportPortal javascript client', () => {
|
|
7
|
-
describe('constructor', () => {
|
|
8
|
-
it('executes without error', () => {
|
|
9
|
-
const client = new RPClient({ token: 'test' });
|
|
10
|
-
|
|
11
|
-
expect(client.config.token).toBe('test');
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('logDebug', () => {
|
|
16
|
-
it('should call console.log with message if debug is true', () => {
|
|
17
|
-
const client = new RPClient({ debug: true });
|
|
18
|
-
spyOn(console, 'log');
|
|
19
|
-
|
|
20
|
-
client.logDebug('message');
|
|
21
|
-
|
|
22
|
-
expect(console.log).toHaveBeenCalledWith('message');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
it('should not call console.log if debug is false', () => {
|
|
27
|
-
const client = new RPClient({ debug: false });
|
|
28
|
-
spyOn(console, 'log');
|
|
29
|
-
|
|
30
|
-
client.logDebug('message');
|
|
31
|
-
|
|
32
|
-
expect(console.log).not.toHaveBeenCalled();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('calculateNonRetriedItemMapKey', () => {
|
|
37
|
-
it('should return correct parameter\'s string', () => {
|
|
38
|
-
const client = new RPClient({});
|
|
39
|
-
|
|
40
|
-
const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name', 'itemId');
|
|
41
|
-
|
|
42
|
-
expect(str).toEqual('lId__pId__name__itemId');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should return correct parameter\'s string with default value if itemId doesn\'t pass', () => {
|
|
46
|
-
const client = new RPClient({});
|
|
47
|
-
|
|
48
|
-
const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name');
|
|
49
|
-
|
|
50
|
-
expect(str).toEqual('lId__pId__name__');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('getRejectAnswer', () => {
|
|
55
|
-
it('should return object with tempId and promise.reject with error', () => {
|
|
56
|
-
const client = new RPClient({});
|
|
57
|
-
|
|
58
|
-
const rejectAnswer = client.getRejectAnswer('tempId', 'error');
|
|
59
|
-
|
|
60
|
-
expect(rejectAnswer.tempId).toEqual('tempId');
|
|
61
|
-
return expectAsync(rejectAnswer.promise).toBeRejected();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('cleanMap', () => {
|
|
66
|
-
it('should delete element with id', () => {
|
|
67
|
-
const client = new RPClient({});
|
|
68
|
-
client.map = {
|
|
69
|
-
id1: 'firstElement',
|
|
70
|
-
id2: 'secondElement',
|
|
71
|
-
id3: 'thirdElement',
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
client.cleanMap(['id1', 'id2']);
|
|
75
|
-
|
|
76
|
-
expect(client.map).toEqual({ id3: 'thirdElement' });
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('checkConnect', () => {
|
|
81
|
-
it('should return promise', () => {
|
|
82
|
-
const client = new RPClient({ endpoint: 'endpoint' });
|
|
83
|
-
spyOn(RestClient, 'request').and.returnValue(Promise.resolve('ok'));
|
|
84
|
-
|
|
85
|
-
const request = client.checkConnect();
|
|
86
|
-
|
|
87
|
-
return expectAsync(request).toBeResolved();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('triggerAnalyticsEvent', () => {
|
|
92
|
-
it('should not call analytics.trackEvent if disableGA is true', () => {
|
|
93
|
-
const client = new RPClient({
|
|
94
|
-
token: 'startLaunchTest',
|
|
95
|
-
endpoint: 'https://rp.us/api/v1',
|
|
96
|
-
project: 'tst',
|
|
97
|
-
disableGA: true,
|
|
98
|
-
});
|
|
99
|
-
spyOn(events, 'getAgentEventLabel').and.returnValue('name|version');
|
|
100
|
-
spyOn(client.analytics, 'trackEvent');
|
|
101
|
-
|
|
102
|
-
client.triggerAnalyticsEvent();
|
|
103
|
-
|
|
104
|
-
expect(client.analytics.trackEvent).not.toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should call analytics.trackEvent with label if agentParams is not empty', () => {
|
|
108
|
-
const client = new RPClient({
|
|
109
|
-
token: 'startLaunchTest',
|
|
110
|
-
endpoint: 'https://rp.us/api/v1',
|
|
111
|
-
project: 'tst',
|
|
112
|
-
});
|
|
113
|
-
client.analytics.agentParams = { name: 'name', version: 'version' };
|
|
114
|
-
spyOn(events, 'getAgentEventLabel').and.returnValue('name|version');
|
|
115
|
-
spyOn(client.analytics, 'trackEvent');
|
|
116
|
-
|
|
117
|
-
client.triggerAnalyticsEvent();
|
|
118
|
-
|
|
119
|
-
expect(client.analytics.trackEvent).toHaveBeenCalledWith(
|
|
120
|
-
Object.assign(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label: 'name|version' }),
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should call analytics.trackEvent without label if agentParams is empty', () => {
|
|
125
|
-
const client = new RPClient({
|
|
126
|
-
token: 'startLaunchTest',
|
|
127
|
-
endpoint: 'https://rp.us/api/v1',
|
|
128
|
-
project: 'tst',
|
|
129
|
-
});
|
|
130
|
-
spyOn(client.analytics, 'trackEvent');
|
|
131
|
-
|
|
132
|
-
client.triggerAnalyticsEvent();
|
|
133
|
-
|
|
134
|
-
expect(client.analytics.trackEvent).toHaveBeenCalledWith(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('startLaunch', () => {
|
|
139
|
-
it('should call restClient with suitable parameters', () => {
|
|
140
|
-
const fakeSystemAttr = [{
|
|
141
|
-
key: 'client',
|
|
142
|
-
value: 'client-name|1.0',
|
|
143
|
-
system: true,
|
|
144
|
-
}, {
|
|
145
|
-
key: 'os',
|
|
146
|
-
value: 'osType|osArchitecture',
|
|
147
|
-
system: true,
|
|
148
|
-
}];
|
|
149
|
-
const client = new RPClient({ token: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', project: 'tst' });
|
|
150
|
-
const myPromise = Promise.resolve({ id: 'testidlaunch' });
|
|
151
|
-
const time = 12345734;
|
|
152
|
-
spyOn(client.restClient, 'create').and.returnValue(myPromise);
|
|
153
|
-
spyOn(helpers, 'getSystemAttribute').and.returnValue(fakeSystemAttr);
|
|
154
|
-
|
|
155
|
-
client.startLaunch({
|
|
156
|
-
startTime: time,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(client.restClient.create).toHaveBeenCalledWith('launch', {
|
|
160
|
-
name: 'Test launch name',
|
|
161
|
-
startTime: time,
|
|
162
|
-
attributes: fakeSystemAttr,
|
|
163
|
-
}, { headers: client.headers });
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should call restClient with suitable parameters, attributes is concatenated', () => {
|
|
167
|
-
const fakeSystemAttr = [{
|
|
168
|
-
key: 'client',
|
|
169
|
-
value: 'client-name|1.0',
|
|
170
|
-
system: true,
|
|
171
|
-
}];
|
|
172
|
-
const client = new RPClient({
|
|
173
|
-
token: 'startLaunchTest',
|
|
174
|
-
endpoint: 'https://rp.us/api/v1',
|
|
175
|
-
project: 'tst',
|
|
176
|
-
});
|
|
177
|
-
client.isLaunchMergeRequired = true;
|
|
178
|
-
const myPromise = Promise.resolve({ id: 'testidlaunch' });
|
|
179
|
-
const time = 12345734;
|
|
180
|
-
spyOn(client.restClient, 'create').and.returnValue(myPromise);
|
|
181
|
-
spyOn(helpers, 'getSystemAttribute').and.returnValue(fakeSystemAttr);
|
|
182
|
-
|
|
183
|
-
client.startLaunch({
|
|
184
|
-
startTime: time,
|
|
185
|
-
attributes: [{ value: 'value' }],
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
expect(client.restClient.create).toHaveBeenCalledWith('launch', {
|
|
189
|
-
name: 'Test launch name',
|
|
190
|
-
startTime: time,
|
|
191
|
-
attributes: [
|
|
192
|
-
{ value: 'value' },
|
|
193
|
-
{
|
|
194
|
-
key: 'client',
|
|
195
|
-
value: 'client-name|1.0',
|
|
196
|
-
system: true,
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
}, { headers: client.headers });
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('dont start new launch if launchDataRQ.id is not empty', () => {
|
|
203
|
-
const client = new RPClient({ token: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', project: 'tst' });
|
|
204
|
-
const myPromise = Promise.resolve({ id: 'testidlaunch' });
|
|
205
|
-
const startTime = 12345734;
|
|
206
|
-
const id = 12345734;
|
|
207
|
-
spyOn(client.restClient, 'create').and.returnValue(myPromise);
|
|
208
|
-
|
|
209
|
-
client.startLaunch({
|
|
210
|
-
startTime,
|
|
211
|
-
id,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
expect(client.restClient.create).not.toHaveBeenCalled();
|
|
215
|
-
expect(client.launchUuid).toEqual(id);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('finishLaunch', () => {
|
|
220
|
-
it('should call getRejectAnswer if there is no launchTempId with suitable launchTempId', () => {
|
|
221
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
222
|
-
client.map = {
|
|
223
|
-
id1: {
|
|
224
|
-
children: ['child1'],
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
spyOn(client, 'getRejectAnswer');
|
|
228
|
-
|
|
229
|
-
client.finishLaunch('id2', { some: 'data' });
|
|
230
|
-
|
|
231
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id2', new Error('Launch "id2" not found'));
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should trigger promiseFinish', (done) => {
|
|
235
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
236
|
-
client.map = {
|
|
237
|
-
id1: {
|
|
238
|
-
children: ['child1'],
|
|
239
|
-
promiseStart: Promise.resolve(),
|
|
240
|
-
},
|
|
241
|
-
child1: {
|
|
242
|
-
promiseFinish: Promise.resolve(),
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
spyOn(client.map.child1, 'promiseFinish').and.resolveTo();
|
|
246
|
-
|
|
247
|
-
client.finishLaunch('id1', { some: 'data' });
|
|
248
|
-
|
|
249
|
-
expect(client.map.child1.promiseFinish().then).toBeDefined();
|
|
250
|
-
done();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe('getMergeLaunchesRequest', () => {
|
|
255
|
-
it('should return object which contains a data for merge launches with default launch name', () => {
|
|
256
|
-
const expectedMergeLaunches = {
|
|
257
|
-
description: 'Merged launch',
|
|
258
|
-
endTime: 12345734,
|
|
259
|
-
extendSuitesDescription: true,
|
|
260
|
-
launches: ['12345', '12346'],
|
|
261
|
-
mergeType: 'BASIC',
|
|
262
|
-
mode: 'DEFAULT',
|
|
263
|
-
name: 'Test launch name',
|
|
264
|
-
attributes: [{ value: 'value' }],
|
|
265
|
-
};
|
|
266
|
-
const client = new RPClient({ attributes: [{ value: 'value' }] });
|
|
267
|
-
spyOn(client.helpers, 'now').and.returnValue(12345734);
|
|
268
|
-
|
|
269
|
-
const mergeLaunches = client.getMergeLaunchesRequest(['12345', '12346']);
|
|
270
|
-
|
|
271
|
-
expect(mergeLaunches).toEqual(expectedMergeLaunches);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should return object which contains a data for merge launches', () => {
|
|
275
|
-
const expectedMergeLaunches = {
|
|
276
|
-
description: 'Merged launch',
|
|
277
|
-
endTime: 12345734,
|
|
278
|
-
extendSuitesDescription: true,
|
|
279
|
-
launches: ['12345', '12346'],
|
|
280
|
-
mergeType: 'BASIC',
|
|
281
|
-
mode: 'DEFAULT',
|
|
282
|
-
name: 'launch',
|
|
283
|
-
attributes: [{ value: 'value' }],
|
|
284
|
-
};
|
|
285
|
-
const client = new RPClient({ launch: 'launch', attributes: [{ value: 'value' }] });
|
|
286
|
-
spyOn(client.helpers, 'now').and.returnValue(12345734);
|
|
287
|
-
|
|
288
|
-
const mergeLaunches = client.getMergeLaunchesRequest(['12345', '12346']);
|
|
289
|
-
|
|
290
|
-
expect(mergeLaunches).toEqual(expectedMergeLaunches);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe('mergeLaunches', () => {
|
|
295
|
-
const fakeLaunchIds = ['12345-gfdgfdg-gfdgdf-fdfd45', '12345-gfdgfdg-gfdgdf-fdfd45', ''];
|
|
296
|
-
const fakeEndTime = 12345734;
|
|
297
|
-
const fakeMergeDataRQ = {
|
|
298
|
-
description: 'Merged launch',
|
|
299
|
-
endTime: fakeEndTime,
|
|
300
|
-
extendSuitesDescription: true,
|
|
301
|
-
launches: fakeLaunchIds,
|
|
302
|
-
mergeType: 'BASIC',
|
|
303
|
-
mode: 'DEFAULT',
|
|
304
|
-
name: 'Test launch name',
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
it('should calls client', (done) => {
|
|
308
|
-
const client = new RPClient({
|
|
309
|
-
token: 'startLaunchTest',
|
|
310
|
-
endpoint: 'https://rp.us/api/v1',
|
|
311
|
-
project: 'tst',
|
|
312
|
-
isLaunchMergeRequired: true,
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const myPromise = Promise.resolve({ id: 'testidlaunch' });
|
|
316
|
-
spyOn(client.restClient, 'create').and.returnValue(myPromise);
|
|
317
|
-
spyOn(helpers, 'readLaunchesFromFile').and.returnValue(fakeLaunchIds);
|
|
318
|
-
spyOn(client, 'getMergeLaunchesRequest').and.returnValue(fakeMergeDataRQ);
|
|
319
|
-
spyOn(client.restClient, 'retrieveSyncAPI').and.returnValue(Promise.resolve({
|
|
320
|
-
content: [{ id: 'id1' }],
|
|
321
|
-
}));
|
|
322
|
-
|
|
323
|
-
const promise = client.mergeLaunches();
|
|
324
|
-
|
|
325
|
-
expect(promise.then).toBeDefined();
|
|
326
|
-
promise.then(() => {
|
|
327
|
-
expect(client.restClient.create)
|
|
328
|
-
.toHaveBeenCalledWith('launch/merge', fakeMergeDataRQ, { headers: client.headers });
|
|
329
|
-
|
|
330
|
-
done();
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it('should not call client if something went wrong', (done) => {
|
|
335
|
-
const client = new RPClient({
|
|
336
|
-
isLaunchMergeRequired: true,
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
spyOn(client.helpers, 'readLaunchesFromFile').and.returnValue('launchUUid');
|
|
340
|
-
spyOn(client.restClient, 'retrieveSyncAPI').and.resolveTo();
|
|
341
|
-
spyOn(client.restClient, 'create').and.rejectWith();
|
|
342
|
-
|
|
343
|
-
const promise = client.mergeLaunches();
|
|
344
|
-
|
|
345
|
-
promise.then(() => {
|
|
346
|
-
expect(client.restClient.create).not.toHaveBeenCalled();
|
|
347
|
-
|
|
348
|
-
done();
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it('should return undefined if isLaunchMergeRequired is false', () => {
|
|
353
|
-
const client = new RPClient({
|
|
354
|
-
token: 'startLaunchTest',
|
|
355
|
-
endpoint: 'https://rp.us/api/v1',
|
|
356
|
-
project: 'tst',
|
|
357
|
-
isLaunchMergeRequired: false,
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
const result = client.mergeLaunches();
|
|
361
|
-
|
|
362
|
-
expect(result).toEqual(undefined);
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
describe('getPromiseFinishAllItems', () => {
|
|
367
|
-
it('should return promise', (done) => {
|
|
368
|
-
const client = new RPClient({});
|
|
369
|
-
client.map = {
|
|
370
|
-
id1: {
|
|
371
|
-
children: ['child1'],
|
|
372
|
-
},
|
|
373
|
-
child1: {
|
|
374
|
-
promiseFinish: Promise.resolve(),
|
|
375
|
-
},
|
|
376
|
-
};
|
|
377
|
-
spyOn(client.map.child1, 'promiseFinish');
|
|
378
|
-
|
|
379
|
-
const promise = client.getPromiseFinishAllItems('id1');
|
|
380
|
-
|
|
381
|
-
expect(promise.then).toBeDefined();
|
|
382
|
-
done();
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
describe('updateLaunch', () => {
|
|
387
|
-
it('should call getRejectAnswer if there is no launchTempId with suitable launchTempId', () => {
|
|
388
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
389
|
-
client.map = {
|
|
390
|
-
id1: {
|
|
391
|
-
children: ['child1'],
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
spyOn(client, 'getRejectAnswer');
|
|
395
|
-
|
|
396
|
-
client.updateLaunch('id2', { some: 'data' });
|
|
397
|
-
|
|
398
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id2', new Error('Launch "id2" not found'));
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
it('should return object with tempId and promise', () => {
|
|
402
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
403
|
-
client.map = {
|
|
404
|
-
id1: {
|
|
405
|
-
children: ['child1'],
|
|
406
|
-
promiseFinish: Promise.resolve(),
|
|
407
|
-
},
|
|
408
|
-
};
|
|
409
|
-
spyOn(client.restClient, 'update').and.resolveTo();
|
|
410
|
-
|
|
411
|
-
const result = client.updateLaunch('id1', { some: 'data' });
|
|
412
|
-
|
|
413
|
-
expect(result.tempId).toEqual('id1');
|
|
414
|
-
return expectAsync(result.promise).toBeResolved();
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
describe('startTestItem', () => {
|
|
419
|
-
it('should call getRejectAnswer if there is no launchTempId with suitable launchTempId', () => {
|
|
420
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
421
|
-
client.map = {
|
|
422
|
-
id1: {
|
|
423
|
-
children: ['child1'],
|
|
424
|
-
},
|
|
425
|
-
};
|
|
426
|
-
spyOn(client, 'getRejectAnswer');
|
|
427
|
-
|
|
428
|
-
client.startTestItem({}, 'id2');
|
|
429
|
-
|
|
430
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id2', new Error('Launch "id2" not found'));
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('should call getRejectAnswer if launchObj.finishSend is true', () => {
|
|
434
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
435
|
-
client.map = {
|
|
436
|
-
id1: {
|
|
437
|
-
children: ['child1'],
|
|
438
|
-
finishSend: true,
|
|
439
|
-
},
|
|
440
|
-
};
|
|
441
|
-
spyOn(client, 'getRejectAnswer');
|
|
442
|
-
const error = new Error('Launch "id1" is already finished, you can not add an item to it');
|
|
443
|
-
|
|
444
|
-
client.startTestItem({}, 'id1');
|
|
445
|
-
|
|
446
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id1', error);
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
it('should call getRejectAnswer if there is no parentObj with suitable parentTempId', () => {
|
|
450
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
451
|
-
client.map = {
|
|
452
|
-
id: {
|
|
453
|
-
children: ['id1'],
|
|
454
|
-
},
|
|
455
|
-
id1: {
|
|
456
|
-
children: ['child1'],
|
|
457
|
-
},
|
|
458
|
-
};
|
|
459
|
-
spyOn(client, 'getRejectAnswer');
|
|
460
|
-
const error = new Error('Item "id3" not found');
|
|
461
|
-
|
|
462
|
-
client.startTestItem({ testCaseId: 'testCaseId' }, 'id1', 'id3');
|
|
463
|
-
|
|
464
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id1', error);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('should return object with tempId and promise', () => {
|
|
468
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
469
|
-
client.map = {
|
|
470
|
-
id: {
|
|
471
|
-
children: ['id1', '4n5pxq24kpiob12og9'],
|
|
472
|
-
promiseStart: Promise.resolve(),
|
|
473
|
-
},
|
|
474
|
-
id1: {
|
|
475
|
-
children: ['child1'],
|
|
476
|
-
promiseStart: Promise.resolve(),
|
|
477
|
-
},
|
|
478
|
-
'4n5pxq24kpiob12og9': {
|
|
479
|
-
promiseStart: Promise.resolve(),
|
|
480
|
-
},
|
|
481
|
-
};
|
|
482
|
-
spyOn(client.nonRetriedItemMap, 'get').and.resolveTo();
|
|
483
|
-
spyOn(client.restClient, 'create').and.resolveTo({});
|
|
484
|
-
spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9');
|
|
485
|
-
|
|
486
|
-
const result = client.startTestItem({ retry: true }, 'id1', 'id');
|
|
487
|
-
|
|
488
|
-
expect(result.tempId).toEqual('4n5pxq24kpiob12og9');
|
|
489
|
-
return expectAsync(result.promise).toBeResolved();
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('should call nonRetriedItemMap if retry is false', () => {
|
|
493
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
494
|
-
client.map = {
|
|
495
|
-
id: {
|
|
496
|
-
children: ['id1', '4n5pxq24kpiob12og9'],
|
|
497
|
-
promiseStart: Promise.resolve(),
|
|
498
|
-
},
|
|
499
|
-
id1: {
|
|
500
|
-
children: ['child1'],
|
|
501
|
-
promiseStart: Promise.resolve(),
|
|
502
|
-
},
|
|
503
|
-
'4n5pxq24kpiob12og9': {
|
|
504
|
-
promiseStart: Promise.resolve(),
|
|
505
|
-
},
|
|
506
|
-
};
|
|
507
|
-
spyOn(client, 'calculateNonRetriedItemMapKey').and.returnValue('id1__name__');
|
|
508
|
-
spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9');
|
|
509
|
-
spyOn(client.map['4n5pxq24kpiob12og9'], 'promiseStart').and.resolveTo();
|
|
510
|
-
spyOn(client.nonRetriedItemMap, 'set');
|
|
511
|
-
|
|
512
|
-
client.startTestItem({ retry: false }, 'id1');
|
|
513
|
-
|
|
514
|
-
expect(client.nonRetriedItemMap.set).toHaveBeenCalledWith(
|
|
515
|
-
'id1__name__',
|
|
516
|
-
client.map['4n5pxq24kpiob12og9'].promiseStart,
|
|
517
|
-
);
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
describe('finishTestItem', () => {
|
|
522
|
-
it('should call getRejectAnswer if there is no itemObj with suitable itemTempId', () => {
|
|
523
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
524
|
-
client.map = {
|
|
525
|
-
id1: {
|
|
526
|
-
children: ['child1'],
|
|
527
|
-
},
|
|
528
|
-
};
|
|
529
|
-
spyOn(client, 'getRejectAnswer');
|
|
530
|
-
|
|
531
|
-
client.finishTestItem('id2', {});
|
|
532
|
-
|
|
533
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('id2', new Error('Item "id2" not found'));
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
it('should call finishTestItemPromiseStart with correct parameters', (done) => {
|
|
537
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
538
|
-
client.map = {
|
|
539
|
-
id: {
|
|
540
|
-
children: ['id1'],
|
|
541
|
-
promiseFinish: Promise.resolve(),
|
|
542
|
-
},
|
|
543
|
-
id1: {
|
|
544
|
-
children: ['child1'],
|
|
545
|
-
promiseFinish: Promise.resolve(),
|
|
546
|
-
},
|
|
547
|
-
};
|
|
548
|
-
client.launchUuid = 'launchUuid';
|
|
549
|
-
spyOn(client, 'cleanMap');
|
|
550
|
-
spyOn(client, 'finishTestItemPromiseStart');
|
|
551
|
-
spyOn(client.helpers, 'now').and.returnValue(1234567);
|
|
552
|
-
|
|
553
|
-
client.finishTestItem('id', {});
|
|
554
|
-
|
|
555
|
-
setTimeout(() => {
|
|
556
|
-
expect(client.cleanMap).toHaveBeenCalledWith(['id1']);
|
|
557
|
-
expect(client.finishTestItemPromiseStart).toHaveBeenCalledWith(
|
|
558
|
-
Object.assign(client.map.id, { finishSend: true }),
|
|
559
|
-
'id',
|
|
560
|
-
{ endTime: 1234567, launchUuid: 'launchUuid' },
|
|
561
|
-
);
|
|
562
|
-
done();
|
|
563
|
-
}, 100);
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
it('should call finishTestItemPromiseStart with correct parameters if smt went wrong', (done) => {
|
|
567
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
568
|
-
client.map = {
|
|
569
|
-
id: {
|
|
570
|
-
children: ['id1'],
|
|
571
|
-
promiseFinish: Promise.resolve(),
|
|
572
|
-
},
|
|
573
|
-
id1: {
|
|
574
|
-
children: ['child1'],
|
|
575
|
-
promiseFinish: Promise.reject(),
|
|
576
|
-
},
|
|
577
|
-
};
|
|
578
|
-
client.launchUuid = 'launchUuid';
|
|
579
|
-
spyOn(client, 'cleanMap');
|
|
580
|
-
spyOn(client, 'finishTestItemPromiseStart');
|
|
581
|
-
spyOn(client.helpers, 'now').and.returnValue(1234567);
|
|
582
|
-
|
|
583
|
-
client.finishTestItem('id', {});
|
|
584
|
-
|
|
585
|
-
setTimeout(() => {
|
|
586
|
-
expect(client.cleanMap).toHaveBeenCalledWith(['id1']);
|
|
587
|
-
expect(client.finishTestItemPromiseStart).toHaveBeenCalledWith(
|
|
588
|
-
Object.assign(client.map.id, { finishSend: true }),
|
|
589
|
-
'id',
|
|
590
|
-
{ endTime: 1234567, launchUuid: 'launchUuid' },
|
|
591
|
-
);
|
|
592
|
-
done();
|
|
593
|
-
}, 100);
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
describe('saveLog', () => {
|
|
598
|
-
it('should return object with tempId and promise', () => {
|
|
599
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
600
|
-
client.map = {
|
|
601
|
-
id1: {
|
|
602
|
-
children: ['child1'],
|
|
603
|
-
},
|
|
604
|
-
};
|
|
605
|
-
spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9');
|
|
606
|
-
spyOn(client.restClient, 'create').and.resolveTo();
|
|
607
|
-
|
|
608
|
-
const result = client.saveLog({
|
|
609
|
-
promiseStart: Promise.resolve(),
|
|
610
|
-
realId: 'realId',
|
|
611
|
-
children: [],
|
|
612
|
-
}, client.restClient.create);
|
|
613
|
-
|
|
614
|
-
expect(result.tempId).toEqual('4n5pxq24kpiob12og9');
|
|
615
|
-
return expectAsync(result.promise).toBeResolved();
|
|
616
|
-
});
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
describe('sendLog', () => {
|
|
620
|
-
it('should return sendLogWithFile if fileObj is not empty', () => {
|
|
621
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
622
|
-
spyOn(client, 'sendLogWithFile').and.returnValue('sendLogWithFile');
|
|
623
|
-
|
|
624
|
-
const result = client.sendLog('itemTempId', { message: 'message' }, { name: 'name' });
|
|
625
|
-
|
|
626
|
-
expect(result).toEqual('sendLogWithFile');
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it('should return sendLogWithoutFile if fileObj is empty', () => {
|
|
630
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
631
|
-
spyOn(client, 'sendLogWithoutFile').and.returnValue('sendLogWithoutFile');
|
|
632
|
-
|
|
633
|
-
const result = client.sendLog('itemTempId', { message: 'message' });
|
|
634
|
-
|
|
635
|
-
expect(result).toEqual('sendLogWithoutFile');
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
describe('sendLogWithoutFile', () => {
|
|
640
|
-
it('should call getRejectAnswer if there is no itemObj with suitable itemTempId', () => {
|
|
641
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
642
|
-
client.map = {
|
|
643
|
-
id1: {
|
|
644
|
-
children: ['child1'],
|
|
645
|
-
},
|
|
646
|
-
};
|
|
647
|
-
spyOn(client, 'getRejectAnswer');
|
|
648
|
-
|
|
649
|
-
client.sendLogWithoutFile('itemTempId', {});
|
|
650
|
-
|
|
651
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('itemTempId', new Error('Item "itemTempId" not found'));
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it('should return saveLog function', () => {
|
|
655
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
656
|
-
client.map = {
|
|
657
|
-
itemTempId: {
|
|
658
|
-
children: ['child1'],
|
|
659
|
-
},
|
|
660
|
-
};
|
|
661
|
-
spyOn(client, 'saveLog').and.returnValue('saveLog');
|
|
662
|
-
|
|
663
|
-
const result = client.sendLogWithoutFile('itemTempId', {});
|
|
664
|
-
|
|
665
|
-
expect(result).toEqual('saveLog');
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
describe('sendLogWithFile', () => {
|
|
670
|
-
it('should call getRejectAnswer if there is no itemObj with suitable itemTempId', () => {
|
|
671
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
672
|
-
client.map = {
|
|
673
|
-
id1: {
|
|
674
|
-
children: ['child1'],
|
|
675
|
-
},
|
|
676
|
-
};
|
|
677
|
-
spyOn(client, 'getRejectAnswer');
|
|
678
|
-
|
|
679
|
-
client.sendLogWithFile('itemTempId', {});
|
|
680
|
-
|
|
681
|
-
expect(client.getRejectAnswer).toHaveBeenCalledWith('itemTempId', new Error('Item "itemTempId" not found'));
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
it('should return saveLog function', () => {
|
|
685
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
686
|
-
client.map = {
|
|
687
|
-
itemTempId: {
|
|
688
|
-
children: ['child1'],
|
|
689
|
-
},
|
|
690
|
-
};
|
|
691
|
-
spyOn(client, 'saveLog').and.returnValue('saveLog');
|
|
692
|
-
|
|
693
|
-
const result = client.sendLogWithFile('itemTempId', {});
|
|
694
|
-
|
|
695
|
-
expect(result).toEqual('saveLog');
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
describe('getRequestLogWithFile', () => {
|
|
700
|
-
it('should return restClient.create', () => {
|
|
701
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
702
|
-
client.map = {
|
|
703
|
-
id1: {
|
|
704
|
-
children: ['child1'],
|
|
705
|
-
},
|
|
706
|
-
};
|
|
707
|
-
spyOn(client, 'buildMultiPartStream').and.returnValue();
|
|
708
|
-
spyOn(client.restClient, 'create').and.resolveTo();
|
|
709
|
-
|
|
710
|
-
const result = client.getRequestLogWithFile({}, { name: 'name' });
|
|
711
|
-
|
|
712
|
-
return expectAsync(result).toBeResolved();
|
|
713
|
-
});
|
|
714
|
-
|
|
715
|
-
it('should return restClient.create with error', () => {
|
|
716
|
-
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' });
|
|
717
|
-
client.map = {
|
|
718
|
-
id1: {
|
|
719
|
-
children: ['child1'],
|
|
720
|
-
},
|
|
721
|
-
};
|
|
722
|
-
spyOn(client, 'buildMultiPartStream').and.returnValue();
|
|
723
|
-
spyOn(client.restClient, 'create').and.rejectWith();
|
|
724
|
-
|
|
725
|
-
const result = client.getRequestLogWithFile({}, { name: 'name' });
|
|
726
|
-
|
|
727
|
-
expect(result.catch).toBeDefined();
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
});
|