Skip to content

Commit a953c62

Browse files
committed
opsBOModules : Add logout to actions
1 parent f8e894a commit a953c62

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

src/interfaces/BO/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface {
8282
clickOnNotificationsLink(page: Page): Promise<boolean>;
8383
clickOnNotificationsTab(page: Page, tabName: string): Promise<void>;
8484
clickSubMenu(page: Page, parentSelector: string): Promise<void>;
85+
closeGrowlMessage(page: Page): Promise<void>;
8586
closeHelpSideBar(page: Page): Promise<boolean>;
8687
closeSfToolBar(page: Frame | Page): Promise<void>;
8788
getAlertDangerBlockParagraphContent(page: Page): Promise<string>;

src/ops/BO/modules/moduleManager.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export default {
5151
const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'reset');
5252
expect(successMessage).toEqual(boModuleManagerPage.resetModuleSuccessMessage(module.tag));
5353
});
54+
55+
await test.step('Reset module: should logout', async () => {
56+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
57+
58+
await boModuleManagerPage.logoutBO(page);
59+
60+
const pageTitle = await boLoginPage.getPageTitle(page);
61+
expect(pageTitle).toContain(boLoginPage.pageTitle);
62+
});
5463
},
5564

5665
/**
@@ -131,6 +140,15 @@ export default {
131140
const isModuleVisible = await boModuleManagerPage.searchModule(page, module);
132141
expect(isModuleVisible).toBeTruthy();
133142
});
143+
144+
await test.step('Install module: should logout', async () => {
145+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
146+
147+
await boModuleManagerPage.logoutBO(page);
148+
149+
const pageTitle = await boLoginPage.getPageTitle(page);
150+
expect(pageTitle).toContain(boLoginPage.pageTitle);
151+
});
134152
},
135153

136154
/**
@@ -177,5 +195,15 @@ export default {
177195
const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'uninstall', false, true);
178196
expect(successMessage).toEqual(boModuleManagerPage.uninstallModuleSuccessMessage(module.tag));
179197
});
198+
199+
await test.step('Uninstall module: should logout', async () => {
200+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
201+
202+
await boModuleManagerPage.reloadPage(page);
203+
await boModuleManagerPage.logoutBO(page);
204+
205+
const pageTitle = await boLoginPage.getPageTitle(page);
206+
expect(pageTitle).toContain(boLoginPage.pageTitle);
207+
});
180208
},
181209
};

src/utils/file.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import http from 'http';
34
import https from 'https';
45
import XLSX from 'xlsx';
56

@@ -179,6 +180,7 @@ export default {
179180

180181
return imageNumber;
181182
},
183+
182184
/**
183185
* Generate report filename
184186
* @return {Promise<string>}
@@ -192,6 +194,7 @@ export default {
192194
curDate.getMinutes()}-${
193195
curDate.getSeconds()}`;
194196
},
197+
195198
/**
196199
* Create directory if not exist
197200
* @param path {string} Path of the directory to create
@@ -200,6 +203,7 @@ export default {
200203
async createDirectory(path: string): Promise<void> {
201204
if (!fs.existsSync(path)) await fs.mkdirSync(path);
202205
},
206+
203207
/**
204208
* Create file with content
205209
* @param path {string} Path of the directory where to create
@@ -214,6 +218,7 @@ export default {
214218
}
215219
});
216220
},
221+
217222
/**
218223
* Check text in file
219224
* @param filePath {string|null} Filepath to check
@@ -358,16 +363,38 @@ export default {
358363
*/
359364
async downloadFile(url: string, path: string): Promise<void> {
360365
await new Promise((resolve, reject): void => {
361-
const httpsAgent: https.Agent = new https.Agent({
362-
rejectUnauthorized: false,
363-
});
366+
if (url.startsWith('http://')) {
367+
http.get(url, (response: http.IncomingMessage): void => {
368+
const code = response.statusCode ?? 0;
369+
370+
if (code >= 400) {
371+
reject(new Error(response.statusMessage));
372+
return;
373+
}
364374

365-
https.get(
366-
url,
367-
{
368-
agent: httpsAgent,
369-
},
370-
(response): void => {
375+
// Handle redirects
376+
if (code > 300 && code < 400 && !!response.headers.location) {
377+
resolve(
378+
this.downloadFile(response.headers.location, path),
379+
);
380+
return;
381+
}
382+
383+
// Save the file to disk
384+
const fileWriter: fs.WriteStream = fs
385+
.createWriteStream(path)
386+
.on('finish', (): void => {
387+
fileWriter.close();
388+
resolve({});
389+
});
390+
391+
response.pipe(fileWriter);
392+
});
393+
} else {
394+
const agent: https.Agent = new https.Agent({
395+
rejectUnauthorized: false,
396+
});
397+
https.get(url, {agent}, (response: http.IncomingMessage): void => {
371398
const code = response.statusCode ?? 0;
372399

373400
if (code >= 400) {
@@ -393,6 +420,7 @@ export default {
393420

394421
response.pipe(fileWriter);
395422
});
423+
}
396424
});
397425
},
398426

0 commit comments

Comments
 (0)