Skip to content

Commit

Permalink
opsBOModules : Add logout to actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Oct 14, 2024
1 parent f8e894a commit a953c62
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/interfaces/BO/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface {
clickOnNotificationsLink(page: Page): Promise<boolean>;
clickOnNotificationsTab(page: Page, tabName: string): Promise<void>;
clickSubMenu(page: Page, parentSelector: string): Promise<void>;
closeGrowlMessage(page: Page): Promise<void>;
closeHelpSideBar(page: Page): Promise<boolean>;
closeSfToolBar(page: Frame | Page): Promise<void>;
getAlertDangerBlockParagraphContent(page: Page): Promise<string>;
Expand Down
28 changes: 28 additions & 0 deletions src/ops/BO/modules/moduleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},

/**
Expand Down Expand Up @@ -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);
});
},

/**
Expand Down Expand Up @@ -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);
});
},
};
46 changes: 37 additions & 9 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import http from 'http';
import https from 'https';
import XLSX from 'xlsx';

Expand Down Expand Up @@ -179,6 +180,7 @@ export default {

return imageNumber;
},

/**
* Generate report filename
* @return {Promise<string>}
Expand All @@ -192,6 +194,7 @@ export default {
curDate.getMinutes()}-${
curDate.getSeconds()}`;
},

/**
* Create directory if not exist
* @param path {string} Path of the directory to create
Expand All @@ -200,6 +203,7 @@ export default {
async createDirectory(path: string): Promise<void> {
if (!fs.existsSync(path)) await fs.mkdirSync(path);
},

/**
* Create file with content
* @param path {string} Path of the directory where to create
Expand All @@ -214,6 +218,7 @@ export default {
}
});
},

/**
* Check text in file
* @param filePath {string|null} Filepath to check
Expand Down Expand Up @@ -358,16 +363,38 @@ export default {
*/
async downloadFile(url: string, path: string): Promise<void> {
await new Promise((resolve, reject): void => {
const httpsAgent: https.Agent = new https.Agent({
rejectUnauthorized: false,
});
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;
}

https.get(
url,
{
agent: httpsAgent,
},
(response): void => {
// 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);
});
} 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) {
Expand All @@ -393,6 +420,7 @@ export default {

response.pipe(fileWriter);
});
}
});
},

Expand Down

0 comments on commit a953c62

Please sign in to comment.