diff --git a/src/interfaces/BO/index.ts b/src/interfaces/BO/index.ts index 5fd3a18d..b70ca394 100644 --- a/src/interfaces/BO/index.ts +++ b/src/interfaces/BO/index.ts @@ -82,6 +82,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface { clickOnNotificationsLink(page: Page): Promise; clickOnNotificationsTab(page: Page, tabName: string): Promise; clickSubMenu(page: Page, parentSelector: string): Promise; + closeGrowlMessage(page: Page): Promise; closeHelpSideBar(page: Page): Promise; closeSfToolBar(page: Frame | Page): Promise; getAlertDangerBlockParagraphContent(page: Page): Promise; diff --git a/src/ops/BO/modules/moduleManager.ts b/src/ops/BO/modules/moduleManager.ts index 345325cc..7735815c 100644 --- a/src/ops/BO/modules/moduleManager.ts +++ b/src/ops/BO/modules/moduleManager.ts @@ -51,6 +51,15 @@ export default { const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'reset'); expect(successMessage).toEqual(boModuleManagerPage.resetModuleSuccessMessage(module.tag)); }); + + await test.step('Reset module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, /** @@ -131,6 +140,15 @@ export default { const isModuleVisible = await boModuleManagerPage.searchModule(page, module); expect(isModuleVisible).toBeTruthy(); }); + + await test.step('Install module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, /** @@ -177,5 +195,15 @@ export default { const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'uninstall', false, true); expect(successMessage).toEqual(boModuleManagerPage.uninstallModuleSuccessMessage(module.tag)); }); + + await test.step('Uninstall module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.reloadPage(page); + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, }; diff --git a/src/utils/file.ts b/src/utils/file.ts index 82045efe..82e22bc1 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import http from 'http'; import https from 'https'; import XLSX from 'xlsx'; @@ -179,6 +180,7 @@ export default { return imageNumber; }, + /** * Generate report filename * @return {Promise} @@ -192,6 +194,7 @@ export default { curDate.getMinutes()}-${ curDate.getSeconds()}`; }, + /** * Create directory if not exist * @param path {string} Path of the directory to create @@ -200,6 +203,7 @@ export default { async createDirectory(path: string): Promise { if (!fs.existsSync(path)) await fs.mkdirSync(path); }, + /** * Create file with content * @param path {string} Path of the directory where to create @@ -214,6 +218,7 @@ export default { } }); }, + /** * Check text in file * @param filePath {string|null} Filepath to check @@ -358,23 +363,16 @@ export default { */ async downloadFile(url: string, path: string): Promise { await new Promise((resolve, reject): void => { - const httpsAgent: https.Agent = new https.Agent({ - rejectUnauthorized: false, - }); - https.get( - url, - { - agent: httpsAgent, - }, - (response): void => { + if (url.startsWith('http://')) { + http.get(url, (response: http.IncomingMessage): void => { const code = response.statusCode ?? 0; - + if (code >= 400) { reject(new Error(response.statusMessage)); return; } - + // Handle redirects if (code > 300 && code < 400 && !!response.headers.location) { resolve( @@ -382,7 +380,7 @@ export default { ); return; } - + // Save the file to disk const fileWriter: fs.WriteStream = fs .createWriteStream(path) @@ -390,9 +388,40 @@ export default { fileWriter.close(); resolve({}); }); - + + response.pipe(fileWriter); + }); + } else { + const agent: https.Agent = new https.Agent({ + rejectUnauthorized: false, + }); + https.get(url, {agent}, (response: http.IncomingMessage): void => { + const code = response.statusCode ?? 0; + + if (code >= 400) { + reject(new Error(response.statusMessage)); + return; + } + + // Handle redirects + if (code > 300 && code < 400 && !!response.headers.location) { + resolve( + this.downloadFile(response.headers.location, path), + ); + return; + } + + // Save the file to disk + const fileWriter: fs.WriteStream = fs + .createWriteStream(path) + .on('finish', (): void => { + fileWriter.close(); + resolve({}); + }); + response.pipe(fileWriter); }); + } }); },