@centreon/js-config 24.4.21 → 24.4.22
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/cypress/component/commands.tsx +53 -14
- package/cypress/component/configuration.js +15 -2
- package/cypress/component/excludeNodeModulesFromCoverage.js +36 -0
- package/cypress/e2e/commands.ts +460 -149
- package/cypress/e2e/configuration.ts +14 -7
- package/cypress/e2e/plugins.ts +1 -1
- package/cypress/e2e/tasks.ts +206 -53
- package/jest/index.js +0 -1
- package/package.json +64 -57
- package/tsconfig/lambda/node20.tsconfig.json +12 -0
- package/webpack/base/globalConfig.js +7 -2
- package/webpack/base/index.js +5 -5
package/cypress/e2e/commands.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import 'cypress-wait-until';
|
|
2
4
|
|
|
3
5
|
import './commands/configuration';
|
|
4
6
|
import './commands/monitoring';
|
|
@@ -7,10 +9,53 @@ import installLogsCollector from 'cypress-terminal-report/src/installLogsCollect
|
|
|
7
9
|
|
|
8
10
|
installLogsCollector({ enableExtendedCollector: true });
|
|
9
11
|
|
|
12
|
+
const apiBase = '/centreon/api';
|
|
13
|
+
const apiActionV1 = `${apiBase}/index.php`;
|
|
10
14
|
const apiLoginV2 = '/centreon/authentication/providers/configurations/local';
|
|
11
15
|
|
|
12
16
|
const artifactIllegalCharactersMatcher = /[,\s/|<>*?:"]/g;
|
|
13
17
|
|
|
18
|
+
export enum PatternType {
|
|
19
|
+
contains = '*',
|
|
20
|
+
endsWith = '$',
|
|
21
|
+
equals = '',
|
|
22
|
+
startsWith = '^'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface GetByLabelProps {
|
|
26
|
+
label: string;
|
|
27
|
+
patternType?: PatternType;
|
|
28
|
+
tag?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Cypress.Commands.add(
|
|
32
|
+
'getByLabel',
|
|
33
|
+
({
|
|
34
|
+
tag = '',
|
|
35
|
+
patternType = PatternType.equals,
|
|
36
|
+
label
|
|
37
|
+
}: GetByLabelProps): Cypress.Chainable => {
|
|
38
|
+
return cy.get(`${tag}[aria-label${patternType}="${label}"]`);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
interface GetByTestIdProps {
|
|
43
|
+
patternType?: PatternType;
|
|
44
|
+
tag?: string;
|
|
45
|
+
testId: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Cypress.Commands.add(
|
|
49
|
+
'getByTestId',
|
|
50
|
+
({
|
|
51
|
+
tag = '',
|
|
52
|
+
patternType = PatternType.equals,
|
|
53
|
+
testId
|
|
54
|
+
}: GetByTestIdProps): Cypress.Chainable => {
|
|
55
|
+
return cy.get(`${tag}[data-testid${patternType}="${testId}"]`);
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
14
59
|
Cypress.Commands.add('getWebVersion', (): Cypress.Chainable => {
|
|
15
60
|
return cy
|
|
16
61
|
.exec(
|
|
@@ -59,7 +104,7 @@ interface NavigateToProps {
|
|
|
59
104
|
|
|
60
105
|
Cypress.Commands.add(
|
|
61
106
|
'navigateTo',
|
|
62
|
-
({ rootItemNumber, subMenu, page }): void => {
|
|
107
|
+
({ rootItemNumber, subMenu, page }: NavigateToProps): void => {
|
|
63
108
|
if (subMenu) {
|
|
64
109
|
cy.hoverRootMenuItem(rootItemNumber)
|
|
65
110
|
.contains(subMenu)
|
|
@@ -100,6 +145,24 @@ Cypress.Commands.add(
|
|
|
100
145
|
}
|
|
101
146
|
);
|
|
102
147
|
|
|
148
|
+
Cypress.Commands.add('getContainerId', (containerName: string) => {
|
|
149
|
+
cy.log(`Getting container id of ${containerName}`);
|
|
150
|
+
|
|
151
|
+
return cy.task('getContainerId', containerName);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
Cypress.Commands.add('getContainerIpAddress', (containerName: string) => {
|
|
155
|
+
cy.log(`Getting container ip address of ${containerName}`);
|
|
156
|
+
|
|
157
|
+
return cy.task('getContainerIpAddress', containerName);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
Cypress.Commands.add('getContainersLogs', () => {
|
|
161
|
+
cy.log('Getting containers logs');
|
|
162
|
+
|
|
163
|
+
return cy.task('getContainersLogs');
|
|
164
|
+
});
|
|
165
|
+
|
|
103
166
|
interface CopyFromContainerProps {
|
|
104
167
|
destination: string;
|
|
105
168
|
name?: string;
|
|
@@ -108,38 +171,54 @@ interface CopyFromContainerProps {
|
|
|
108
171
|
|
|
109
172
|
Cypress.Commands.add(
|
|
110
173
|
'copyFromContainer',
|
|
111
|
-
(
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
destination
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return cy.exec(`docker cp ${name}:${source} "${destination}"`, options);
|
|
174
|
+
({ name = 'web', source, destination }: CopyFromContainerProps) => {
|
|
175
|
+
cy.log(`Copy content from ${name}:${source} to ${destination}`);
|
|
176
|
+
|
|
177
|
+
return cy.task('copyFromContainer', {
|
|
178
|
+
destination,
|
|
179
|
+
serviceName: name,
|
|
180
|
+
source
|
|
181
|
+
});
|
|
120
182
|
}
|
|
121
183
|
);
|
|
122
184
|
|
|
185
|
+
export enum CopyToContainerContentType {
|
|
186
|
+
Directory = 'directory',
|
|
187
|
+
File = 'file'
|
|
188
|
+
}
|
|
189
|
+
|
|
123
190
|
interface CopyToContainerProps {
|
|
124
191
|
destination: string;
|
|
125
192
|
name?: string;
|
|
126
193
|
source: string;
|
|
194
|
+
type: CopyToContainerContentType;
|
|
127
195
|
}
|
|
128
196
|
|
|
129
197
|
Cypress.Commands.add(
|
|
130
198
|
'copyToContainer',
|
|
131
|
-
(
|
|
132
|
-
{
|
|
133
|
-
|
|
199
|
+
({ name = 'web', source, destination, type }: CopyToContainerProps) => {
|
|
200
|
+
cy.log(`Copy content from ${source} to ${name}:${destination}`);
|
|
201
|
+
|
|
202
|
+
return cy.task('copyToContainer', {
|
|
203
|
+
destination,
|
|
204
|
+
serviceName: name,
|
|
134
205
|
source,
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
options?: Partial<Cypress.ExecOptions>
|
|
138
|
-
) => {
|
|
139
|
-
return cy.exec(`docker cp ${source} ${name}:${destination}`, options);
|
|
206
|
+
type
|
|
207
|
+
});
|
|
140
208
|
}
|
|
141
209
|
);
|
|
142
210
|
|
|
211
|
+
Cypress.Commands.add('loginAsAdminViaApiV2', (): Cypress.Chainable => {
|
|
212
|
+
return cy.request({
|
|
213
|
+
body: {
|
|
214
|
+
login: 'admin',
|
|
215
|
+
password: 'Centreon!2021'
|
|
216
|
+
},
|
|
217
|
+
method: 'POST',
|
|
218
|
+
url: apiLoginV2
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
143
222
|
interface LoginByTypeOfUserProps {
|
|
144
223
|
jsonName?: string;
|
|
145
224
|
loginViaApi?: boolean;
|
|
@@ -178,16 +257,41 @@ Cypress.Commands.add(
|
|
|
178
257
|
.getByLabel({ label: 'Connect', tag: 'button' })
|
|
179
258
|
.click();
|
|
180
259
|
|
|
181
|
-
return cy
|
|
182
|
-
.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
});
|
|
260
|
+
return cy.get('.MuiAlert-message').then(($snackbar) => {
|
|
261
|
+
if ($snackbar.text().includes('Login succeeded')) {
|
|
262
|
+
cy.wait('@getNavigationList');
|
|
263
|
+
}
|
|
264
|
+
});
|
|
188
265
|
}
|
|
189
266
|
);
|
|
190
267
|
|
|
268
|
+
Cypress.Commands.add('logout', (): void => {
|
|
269
|
+
cy.getByLabel({ label: 'Profile' }).should('exist').click();
|
|
270
|
+
|
|
271
|
+
cy.intercept({
|
|
272
|
+
method: 'GET',
|
|
273
|
+
times: 1,
|
|
274
|
+
url: '/centreon/api/latest/authentication/logout'
|
|
275
|
+
}).as('logout');
|
|
276
|
+
|
|
277
|
+
cy.contains(/^Logout$/).click();
|
|
278
|
+
|
|
279
|
+
cy.wait('@logout').its('response.statusCode').should('eq', 302);
|
|
280
|
+
|
|
281
|
+
// https://github.com/cypress-io/cypress/issues/25841
|
|
282
|
+
cy.clearAllCookies();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
Cypress.Commands.add('logoutViaAPI', (): Cypress.Chainable => {
|
|
286
|
+
return cy
|
|
287
|
+
.request({
|
|
288
|
+
method: 'GET',
|
|
289
|
+
url: '/centreon/authentication/logout'
|
|
290
|
+
})
|
|
291
|
+
.visit('/')
|
|
292
|
+
.getByLabel({ label: 'Alias', tag: 'input' });
|
|
293
|
+
});
|
|
294
|
+
|
|
191
295
|
Cypress.Commands.add(
|
|
192
296
|
'visitEmptyPage',
|
|
193
297
|
(): Cypress.Chainable =>
|
|
@@ -199,32 +303,91 @@ Cypress.Commands.add(
|
|
|
199
303
|
.visit('/waiting-page')
|
|
200
304
|
);
|
|
201
305
|
|
|
202
|
-
Cypress.Commands.add('waitForContainerAndSetToken', (): Cypress.Chainable => {
|
|
203
|
-
return cy.setUserTokenApiV1();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
306
|
interface ExecInContainerProps {
|
|
207
|
-
command: string
|
|
307
|
+
command: string | Array<string>;
|
|
208
308
|
name: string;
|
|
209
309
|
}
|
|
210
310
|
|
|
311
|
+
interface ExecInContainerResult {
|
|
312
|
+
exitCode: number;
|
|
313
|
+
output: string;
|
|
314
|
+
}
|
|
315
|
+
|
|
211
316
|
Cypress.Commands.add(
|
|
212
317
|
'execInContainer',
|
|
213
318
|
({ command, name }: ExecInContainerProps): Cypress.Chainable => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
319
|
+
const commands =
|
|
320
|
+
typeof command === 'string' || command instanceof String
|
|
321
|
+
? [command]
|
|
322
|
+
: command;
|
|
323
|
+
|
|
324
|
+
const results = commands.reduce(
|
|
325
|
+
(acc, runCommand) => {
|
|
326
|
+
cy.task<ExecInContainerResult>(
|
|
327
|
+
'execInContainer',
|
|
328
|
+
{ command: runCommand, name },
|
|
329
|
+
{ timeout: 600000 }
|
|
330
|
+
).then((result) => {
|
|
331
|
+
if (result.exitCode) {
|
|
332
|
+
cy.log(result.output);
|
|
333
|
+
|
|
334
|
+
// output will not be truncated
|
|
335
|
+
throw new Error(`
|
|
336
|
+
Execution of "${runCommand}" failed
|
|
337
|
+
Exit code: ${result.exitCode}
|
|
338
|
+
Output:\n${result.output}`);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
acc.output = `${acc.output}${result.output}`;
|
|
342
|
+
});
|
|
225
343
|
|
|
226
|
-
return
|
|
227
|
-
}
|
|
344
|
+
return acc;
|
|
345
|
+
},
|
|
346
|
+
{ exitCode: 0, output: '' }
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
return cy.wrap(results);
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
interface RequestOnDatabaseProps {
|
|
354
|
+
database: string;
|
|
355
|
+
query: string;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
Cypress.Commands.add(
|
|
359
|
+
'requestOnDatabase',
|
|
360
|
+
({ database, query }: RequestOnDatabaseProps): Cypress.Chainable => {
|
|
361
|
+
return cy.task('requestOnDatabase', { database, query });
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
interface SetUserTokenApiV1Props {
|
|
366
|
+
login?: string;
|
|
367
|
+
password?: string;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
Cypress.Commands.add(
|
|
371
|
+
'setUserTokenApiV1',
|
|
372
|
+
({
|
|
373
|
+
login = 'admin',
|
|
374
|
+
password = 'Centreon!2021'
|
|
375
|
+
}: SetUserTokenApiV1Props = {}): Cypress.Chainable => {
|
|
376
|
+
return cy
|
|
377
|
+
.request({
|
|
378
|
+
body: {
|
|
379
|
+
password,
|
|
380
|
+
username: login
|
|
381
|
+
},
|
|
382
|
+
headers: {
|
|
383
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
384
|
+
},
|
|
385
|
+
method: 'POST',
|
|
386
|
+
url: `${apiActionV1}?action=authenticate`
|
|
387
|
+
})
|
|
388
|
+
.then(({ body }) =>
|
|
389
|
+
window.localStorage.setItem('userTokenApiV1', body.authToken)
|
|
390
|
+
);
|
|
228
391
|
}
|
|
229
392
|
);
|
|
230
393
|
|
|
@@ -234,6 +397,7 @@ interface PortBinding {
|
|
|
234
397
|
}
|
|
235
398
|
|
|
236
399
|
interface StartContainerProps {
|
|
400
|
+
command?: string;
|
|
237
401
|
image: string;
|
|
238
402
|
name: string;
|
|
239
403
|
portBindings: Array<PortBinding>;
|
|
@@ -241,122 +405,88 @@ interface StartContainerProps {
|
|
|
241
405
|
|
|
242
406
|
Cypress.Commands.add(
|
|
243
407
|
'startContainer',
|
|
244
|
-
({
|
|
408
|
+
({
|
|
409
|
+
command,
|
|
410
|
+
name,
|
|
411
|
+
image,
|
|
412
|
+
portBindings
|
|
413
|
+
}: StartContainerProps): Cypress.Chainable => {
|
|
245
414
|
cy.log(`Starting container ${name} from image ${image}`);
|
|
246
415
|
|
|
247
416
|
return cy.task(
|
|
248
417
|
'startContainer',
|
|
249
|
-
{ image, name, portBindings },
|
|
418
|
+
{ command, image, name, portBindings },
|
|
250
419
|
{ timeout: 600000 } // 10 minutes because docker pull can be very slow
|
|
251
420
|
);
|
|
252
421
|
}
|
|
253
422
|
);
|
|
254
423
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
interface StartWebContainerProps {
|
|
263
|
-
name?: string;
|
|
264
|
-
os?: string;
|
|
424
|
+
interface StartContainersProps {
|
|
425
|
+
composeFile?: string;
|
|
426
|
+
databaseImage?: string;
|
|
427
|
+
moduleName?: string;
|
|
428
|
+
openidImage?: string;
|
|
429
|
+
profiles?: Array<string>;
|
|
430
|
+
samlImage?: string;
|
|
265
431
|
useSlim?: boolean;
|
|
266
|
-
|
|
432
|
+
webOs?: string;
|
|
433
|
+
webVersion?: string;
|
|
267
434
|
}
|
|
268
435
|
|
|
269
436
|
Cypress.Commands.add(
|
|
270
|
-
'
|
|
437
|
+
'startContainers',
|
|
271
438
|
({
|
|
272
|
-
|
|
273
|
-
|
|
439
|
+
composeFile,
|
|
440
|
+
databaseImage = Cypress.env('DATABASE_IMAGE'),
|
|
441
|
+
moduleName = 'centreon-web',
|
|
442
|
+
openidImage = `docker.centreon.com/centreon/keycloak:${Cypress.env(
|
|
443
|
+
'OPENID_IMAGE_VERSION'
|
|
444
|
+
)}`,
|
|
445
|
+
profiles = [],
|
|
446
|
+
samlImage = `docker.centreon.com/centreon/keycloak:${Cypress.env(
|
|
447
|
+
'SAML_IMAGE_VERSION'
|
|
448
|
+
)}`,
|
|
274
449
|
useSlim = true,
|
|
275
|
-
|
|
276
|
-
|
|
450
|
+
webOs = Cypress.env('WEB_IMAGE_OS'),
|
|
451
|
+
webVersion = Cypress.env('WEB_IMAGE_VERSION')
|
|
452
|
+
}: StartContainersProps = {}): Cypress.Chainable => {
|
|
453
|
+
cy.log('Starting containers ...');
|
|
454
|
+
|
|
455
|
+
let composeFilePath = composeFile;
|
|
456
|
+
if (!composeFile) {
|
|
457
|
+
const cypressDir = path.dirname(Cypress.config('configFile'));
|
|
458
|
+
composeFilePath = `${cypressDir}/../../../.github/docker/docker-compose.yml`;
|
|
459
|
+
}
|
|
460
|
+
|
|
277
461
|
const slimSuffix = useSlim ? '-slim' : '';
|
|
278
462
|
|
|
279
|
-
const
|
|
463
|
+
const webImage = `docker.centreon.com/centreon/${moduleName}${slimSuffix}-${webOs}:${webVersion}`;
|
|
280
464
|
|
|
281
465
|
return cy
|
|
282
|
-
.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
466
|
+
.task(
|
|
467
|
+
'startContainers',
|
|
468
|
+
{
|
|
469
|
+
composeFile: composeFilePath,
|
|
470
|
+
databaseImage,
|
|
471
|
+
openidImage,
|
|
472
|
+
profiles,
|
|
473
|
+
samlImage,
|
|
474
|
+
webImage
|
|
475
|
+
},
|
|
476
|
+
{ timeout: 600000 } // 10 minutes because docker pull can be very slow
|
|
477
|
+
)
|
|
287
478
|
.then(() => {
|
|
288
479
|
const baseUrl = 'http://127.0.0.1:4000';
|
|
289
480
|
|
|
290
481
|
Cypress.config('baseUrl', baseUrl);
|
|
291
482
|
|
|
292
|
-
return cy.
|
|
293
|
-
'waitOn',
|
|
294
|
-
`${baseUrl}/centreon/api/latest/platform/installation/status`
|
|
295
|
-
);
|
|
483
|
+
return cy.wrap(null);
|
|
296
484
|
})
|
|
297
485
|
.visit('/') // this is necessary to refresh browser cause baseUrl has changed (flash appears in video)
|
|
298
486
|
.setUserTokenApiV1();
|
|
299
487
|
}
|
|
300
488
|
);
|
|
301
489
|
|
|
302
|
-
interface StopWebContainerProps {
|
|
303
|
-
name?: string;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
Cypress.Commands.add(
|
|
307
|
-
'stopWebContainer',
|
|
308
|
-
({
|
|
309
|
-
name = Cypress.env('dockerName')
|
|
310
|
-
}: StopWebContainerProps = {}): Cypress.Chainable => {
|
|
311
|
-
const logDirectory = `results/logs/${Cypress.spec.name.replace(
|
|
312
|
-
artifactIllegalCharactersMatcher,
|
|
313
|
-
'_'
|
|
314
|
-
)}/${Cypress.currentTest.title.replace(
|
|
315
|
-
artifactIllegalCharactersMatcher,
|
|
316
|
-
'_'
|
|
317
|
-
)}`;
|
|
318
|
-
|
|
319
|
-
return cy
|
|
320
|
-
.visitEmptyPage()
|
|
321
|
-
.createDirectory(logDirectory)
|
|
322
|
-
.copyFromContainer({
|
|
323
|
-
destination: `${logDirectory}/broker`,
|
|
324
|
-
name,
|
|
325
|
-
source: '/var/log/centreon-broker'
|
|
326
|
-
})
|
|
327
|
-
.copyFromContainer({
|
|
328
|
-
destination: `${logDirectory}/engine`,
|
|
329
|
-
name,
|
|
330
|
-
source: '/var/log/centreon-engine'
|
|
331
|
-
})
|
|
332
|
-
.copyFromContainer({
|
|
333
|
-
destination: `${logDirectory}/centreon`,
|
|
334
|
-
name,
|
|
335
|
-
source: '/var/log/centreon'
|
|
336
|
-
})
|
|
337
|
-
.then(() => {
|
|
338
|
-
if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
|
|
339
|
-
return cy.copyFromContainer({
|
|
340
|
-
destination: `${logDirectory}/php`,
|
|
341
|
-
name,
|
|
342
|
-
source: '/var/log/php-fpm'
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return cy.copyFromContainer(
|
|
347
|
-
{
|
|
348
|
-
destination: `${logDirectory}/php8.1-fpm-centreon-error.log`,
|
|
349
|
-
name,
|
|
350
|
-
source: '/var/log/php8.1-fpm-centreon-error.log'
|
|
351
|
-
},
|
|
352
|
-
{ failOnNonZeroExit: false }
|
|
353
|
-
);
|
|
354
|
-
})
|
|
355
|
-
.exec(`chmod -R 755 "${logDirectory}"`)
|
|
356
|
-
.stopContainer({ name });
|
|
357
|
-
}
|
|
358
|
-
);
|
|
359
|
-
|
|
360
490
|
interface StopContainerProps {
|
|
361
491
|
name: string;
|
|
362
492
|
}
|
|
@@ -366,20 +496,109 @@ Cypress.Commands.add(
|
|
|
366
496
|
({ name }: StopContainerProps): Cypress.Chainable => {
|
|
367
497
|
cy.log(`Stopping container ${name}`);
|
|
368
498
|
|
|
369
|
-
cy.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
499
|
+
return cy.task('stopContainer', { name });
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
Cypress.Commands.add('stopContainers', (): Cypress.Chainable => {
|
|
504
|
+
cy.log('Stopping containers ...');
|
|
505
|
+
|
|
506
|
+
const logDirectory = `results/logs/${Cypress.spec.name.replace(
|
|
507
|
+
artifactIllegalCharactersMatcher,
|
|
508
|
+
'_'
|
|
509
|
+
)}/${Cypress.currentTest.title.replace(
|
|
510
|
+
artifactIllegalCharactersMatcher,
|
|
511
|
+
'_'
|
|
512
|
+
)}`;
|
|
513
|
+
|
|
514
|
+
const name = 'web';
|
|
515
|
+
|
|
516
|
+
return cy
|
|
517
|
+
.visitEmptyPage()
|
|
518
|
+
.createDirectory(logDirectory)
|
|
519
|
+
.getContainersLogs()
|
|
520
|
+
.then((containersLogs: Array<Array<string>>) => {
|
|
521
|
+
Object.entries(containersLogs).forEach(([containerName, logs]) => {
|
|
522
|
+
cy.writeFile(
|
|
523
|
+
`results/logs/${Cypress.spec.name.replace(
|
|
524
|
+
artifactIllegalCharactersMatcher,
|
|
525
|
+
'_'
|
|
526
|
+
)}/${Cypress.currentTest.title.replace(
|
|
527
|
+
artifactIllegalCharactersMatcher,
|
|
528
|
+
'_'
|
|
529
|
+
)}/container-${containerName}.log`,
|
|
530
|
+
logs
|
|
531
|
+
);
|
|
532
|
+
});
|
|
533
|
+
})
|
|
534
|
+
.copyFromContainer({
|
|
535
|
+
destination: `${logDirectory}/broker`,
|
|
536
|
+
name,
|
|
537
|
+
source: '/var/log/centreon-broker'
|
|
538
|
+
})
|
|
539
|
+
.copyFromContainer({
|
|
540
|
+
destination: `${logDirectory}/engine`,
|
|
541
|
+
name,
|
|
542
|
+
source: '/var/log/centreon-engine'
|
|
543
|
+
})
|
|
544
|
+
.copyFromContainer({
|
|
545
|
+
destination: `${logDirectory}/centreon`,
|
|
546
|
+
name,
|
|
547
|
+
source: '/var/log/centreon'
|
|
548
|
+
})
|
|
549
|
+
.copyFromContainer({
|
|
550
|
+
destination: `${logDirectory}/centreon-gorgone`,
|
|
551
|
+
name,
|
|
552
|
+
source: '/var/log/centreon-gorgone'
|
|
553
|
+
})
|
|
554
|
+
.then(() => {
|
|
555
|
+
if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
|
|
556
|
+
return cy.copyFromContainer({
|
|
557
|
+
destination: `${logDirectory}/php`,
|
|
558
|
+
name,
|
|
559
|
+
source: '/var/log/php-fpm'
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return cy.copyFromContainer(
|
|
564
|
+
{
|
|
565
|
+
destination: `${logDirectory}/php8.1-fpm-centreon-error.log`,
|
|
566
|
+
name,
|
|
567
|
+
source: '/var/log/php8.1-fpm-centreon-error.log'
|
|
568
|
+
},
|
|
569
|
+
{ failOnNonZeroExit: false }
|
|
379
570
|
);
|
|
380
|
-
})
|
|
571
|
+
})
|
|
572
|
+
.then(() => {
|
|
573
|
+
if (Cypress.env('WEB_IMAGE_OS').includes('alma')) {
|
|
574
|
+
return cy.copyFromContainer({
|
|
575
|
+
destination: `${logDirectory}/httpd`,
|
|
576
|
+
name,
|
|
577
|
+
source: '/var/log/httpd'
|
|
578
|
+
});
|
|
579
|
+
}
|
|
381
580
|
|
|
382
|
-
|
|
581
|
+
return cy.copyFromContainer(
|
|
582
|
+
{
|
|
583
|
+
destination: `${logDirectory}/apache2`,
|
|
584
|
+
name,
|
|
585
|
+
source: '/var/log/apache2'
|
|
586
|
+
},
|
|
587
|
+
{ failOnNonZeroExit: false }
|
|
588
|
+
);
|
|
589
|
+
})
|
|
590
|
+
.exec(`chmod -R 755 "${logDirectory}"`)
|
|
591
|
+
.task(
|
|
592
|
+
'stopContainers',
|
|
593
|
+
{},
|
|
594
|
+
{ timeout: 600000 } // 10 minutes because docker pull can be very slow
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
Cypress.Commands.add(
|
|
599
|
+
'createDirectory',
|
|
600
|
+
(directoryPath: string): Cypress.Chainable => {
|
|
601
|
+
return cy.task('createDirectory', directoryPath);
|
|
383
602
|
}
|
|
384
603
|
);
|
|
385
604
|
|
|
@@ -416,6 +635,41 @@ Cypress.Commands.add(
|
|
|
416
635
|
}
|
|
417
636
|
);
|
|
418
637
|
|
|
638
|
+
Cypress.Commands.add(
|
|
639
|
+
'insertDashboardWithWidget',
|
|
640
|
+
(dashboardBody, patchBody) => {
|
|
641
|
+
cy.request({
|
|
642
|
+
body: {
|
|
643
|
+
...dashboardBody
|
|
644
|
+
},
|
|
645
|
+
method: 'POST',
|
|
646
|
+
url: '/centreon/api/latest/configuration/dashboards'
|
|
647
|
+
}).then((response) => {
|
|
648
|
+
const dashboardId = response.body.id;
|
|
649
|
+
cy.waitUntil(
|
|
650
|
+
() => {
|
|
651
|
+
return cy
|
|
652
|
+
.request({
|
|
653
|
+
method: 'GET',
|
|
654
|
+
url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
|
|
655
|
+
})
|
|
656
|
+
.then((getResponse) => {
|
|
657
|
+
return getResponse.body && getResponse.body.id === dashboardId;
|
|
658
|
+
});
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
timeout: 10000
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
cy.request({
|
|
665
|
+
body: patchBody,
|
|
666
|
+
method: 'PATCH',
|
|
667
|
+
url: `/centreon/api/latest/configuration/dashboards/${dashboardId}`
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
);
|
|
672
|
+
|
|
419
673
|
interface ShareDashboardToUserProps {
|
|
420
674
|
dashboardName: string;
|
|
421
675
|
role: string;
|
|
@@ -430,6 +684,30 @@ interface ListingRequestResult {
|
|
|
430
684
|
};
|
|
431
685
|
}
|
|
432
686
|
|
|
687
|
+
interface PatchDashboardBody {
|
|
688
|
+
panels: Array<{
|
|
689
|
+
layout: {
|
|
690
|
+
height: number;
|
|
691
|
+
min_height: number;
|
|
692
|
+
min_width: number;
|
|
693
|
+
width: number;
|
|
694
|
+
x: number;
|
|
695
|
+
y: number;
|
|
696
|
+
};
|
|
697
|
+
name: string;
|
|
698
|
+
widget_settings: {
|
|
699
|
+
options: {
|
|
700
|
+
description: {
|
|
701
|
+
content: string;
|
|
702
|
+
enabled: boolean;
|
|
703
|
+
};
|
|
704
|
+
name: string;
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
widget_type: string;
|
|
708
|
+
}>;
|
|
709
|
+
}
|
|
710
|
+
|
|
433
711
|
Cypress.Commands.add(
|
|
434
712
|
'shareDashboardToUser',
|
|
435
713
|
({ dashboardName, userName, role }: ShareDashboardToUserProps): void => {
|
|
@@ -496,41 +774,74 @@ declare global {
|
|
|
496
774
|
command,
|
|
497
775
|
name
|
|
498
776
|
}: ExecInContainerProps) => Cypress.Chainable;
|
|
777
|
+
getByLabel: ({
|
|
778
|
+
patternType,
|
|
779
|
+
tag,
|
|
780
|
+
label
|
|
781
|
+
}: GetByLabelProps) => Cypress.Chainable;
|
|
782
|
+
getByTestId: ({
|
|
783
|
+
patternType,
|
|
784
|
+
tag,
|
|
785
|
+
testId
|
|
786
|
+
}: GetByTestIdProps) => Cypress.Chainable;
|
|
787
|
+
getContainerId: (containerName: string) => Cypress.Chainable;
|
|
788
|
+
getContainerIpAddress: (containerName: string) => Cypress.Chainable;
|
|
789
|
+
getContainersLogs: () => Cypress.Chainable;
|
|
499
790
|
getIframeBody: () => Cypress.Chainable;
|
|
500
791
|
getTimeFromHeader: () => Cypress.Chainable;
|
|
501
792
|
getWebVersion: () => Cypress.Chainable;
|
|
502
793
|
hoverRootMenuItem: (rootItemNumber: number) => Cypress.Chainable;
|
|
503
794
|
insertDashboard: (dashboard: Dashboard) => Cypress.Chainable;
|
|
504
795
|
insertDashboardList: (fixtureFile: string) => Cypress.Chainable;
|
|
796
|
+
insertDashboardWithWidget: (
|
|
797
|
+
dashboard: Dashboard,
|
|
798
|
+
patch: PatchDashboardBody
|
|
799
|
+
) => Cypress.Chainable;
|
|
800
|
+
loginAsAdminViaApiV2: () => Cypress.Chainable;
|
|
505
801
|
loginByTypeOfUser: ({
|
|
506
802
|
jsonName,
|
|
507
803
|
loginViaApi
|
|
508
804
|
}: LoginByTypeOfUserProps) => Cypress.Chainable;
|
|
805
|
+
logout: () => void;
|
|
806
|
+
logoutViaAPI: () => Cypress.Chainable;
|
|
509
807
|
moveSortableElement: (direction: string) => Cypress.Chainable;
|
|
510
808
|
navigateTo: ({
|
|
511
809
|
page,
|
|
512
810
|
rootItemNumber,
|
|
513
811
|
subMenu
|
|
514
812
|
}: NavigateToProps) => Cypress.Chainable;
|
|
813
|
+
requestOnDatabase: ({
|
|
814
|
+
database,
|
|
815
|
+
query
|
|
816
|
+
}: RequestOnDatabaseProps) => Cypress.Chainable;
|
|
817
|
+
setUserTokenApiV1: ({
|
|
818
|
+
login,
|
|
819
|
+
password
|
|
820
|
+
}?: SetUserTokenApiV1Props) => Cypress.Chainable;
|
|
515
821
|
shareDashboardToUser: ({
|
|
516
822
|
dashboardName,
|
|
517
823
|
userName,
|
|
518
824
|
role
|
|
519
825
|
}: ShareDashboardToUserProps) => Cypress.Chainable;
|
|
520
826
|
startContainer: ({
|
|
827
|
+
command,
|
|
521
828
|
name,
|
|
522
|
-
image
|
|
829
|
+
image,
|
|
830
|
+
portBindings
|
|
523
831
|
}: StartContainerProps) => Cypress.Chainable;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
832
|
+
startContainers: ({
|
|
833
|
+
composeFile,
|
|
834
|
+
databaseImage,
|
|
835
|
+
moduleName,
|
|
836
|
+
openidImage,
|
|
837
|
+
profiles,
|
|
527
838
|
useSlim,
|
|
528
|
-
|
|
529
|
-
|
|
839
|
+
webOs,
|
|
840
|
+
webVersion
|
|
841
|
+
}?: StartContainersProps) => Cypress.Chainable;
|
|
530
842
|
stopContainer: ({ name }: StopContainerProps) => Cypress.Chainable;
|
|
531
|
-
|
|
843
|
+
stopContainers: () => Cypress.Chainable;
|
|
532
844
|
visitEmptyPage: () => Cypress.Chainable;
|
|
533
|
-
waitForContainerAndSetToken: () => Cypress.Chainable;
|
|
534
845
|
}
|
|
535
846
|
}
|
|
536
847
|
}
|