Skip to content

Commit

Permalink
PMM-7 fixed more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Yarosh committed Aug 16, 2023
1 parent 32bbac9 commit 041a9e5
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/portal-ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:

jobs:
tests:
name: '"${{ inputs.version_string_from || inputs.pmm_server_version }}"'
name: '"${{ inputs.version_string_from || inputs.pmm_server_version || "dev-latest" }}"'
runs-on: ubuntu-latest
timeout-minutes: 60
env:
Expand Down
10 changes: 6 additions & 4 deletions playwright-tests/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { server } from '@api/server';
import { settings } from '@tests/tests/configuration/api/settings';
import { okta } from '@api/okta';
import { oktaApi } from '@api/oktaApi';
import { portalAPI } from '@api/portalApi';
import { inventory } from './inventory';
import { management } from './management';
import { serviceNowAPI } from '@api/serviceNowApi';
import { inventory } from '@api/inventory';
import { management } from '@api/management';

/**
* User facing api collection. Accessible on Frontend via /swagger path.
Expand All @@ -18,6 +19,7 @@ export const api = {
serverV1: server,
managementV1: management,
},
okta: okta,
okta: oktaApi,
portal: portalAPI,
serviceNow: serviceNowAPI,
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const oktaRequest = async (method: Method, apiPath: string, payload = {}): Promi
return response;
};

export const okta = {
export const oktaApi = {
async loginByOktaApi(user: PortalUser, page: Page) {
const credentials = {
username: user.email,
Expand Down
55 changes: 43 additions & 12 deletions playwright-tests/helpers/portalHelper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { serviceNowAPI } from '@api/serviceNowApi';
import { portalAPI } from '@api/portalApi';
import { PortalUserRoles } from '@helpers/enums/portalUserRoles';
import { fileHelper } from '@helpers/fileHelper';
import { PortalUser } from '@helpers/types/PortalUser';
import { Constants } from '@helpers/Constants';
import * as dotenv from 'dotenv';
import { ServiceNowResponse} from '@helpers/types/serviceNowResponse.interface';
import { okta } from '@api/okta';
import { ServiceNowResponse } from '@helpers/types/serviceNowResponse.interface';
import { api } from '@api/api';

dotenv.config();

Expand All @@ -26,6 +24,14 @@ export const portalHelper = {
if (fileHelper.fileExists(Constants.portal.credentialsFile)) {
console.log(`Using existing users from file: ${Constants.portal.credentialsFile}`);
[firstAdmin, secondAdmin, technicalUser] = JSON.parse(fileHelper.readFile(Constants.portal.credentialsFile));
if (!Object.hasOwn(firstAdmin, 'org')) {
const adminToken = await api.portal.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const orgId = Object.hasOwn(firstAdmin, 'org') ? firstAdmin.org!.id
: (await api.portal.getOrg(adminToken)).orgs[0].id;
firstAdmin.org = { id: orgId, role: PortalUserRoles.admin };
secondAdmin.org = { id: orgId, role: PortalUserRoles.admin };
technicalUser.org = { id: orgId, role: PortalUserRoles.technical };
}
} else {
[firstAdmin, secondAdmin, technicalUser] = await portalHelper.createNewUsers();
fileHelper.writeToFile(Constants.portal.credentialsFile, JSON.stringify([firstAdmin, secondAdmin, technicalUser]));
Expand All @@ -37,16 +43,41 @@ export const portalHelper = {
* Encapsulates all actions required to create Portal user for tests.
*/
createNewUsers: async () => {
const credentials: ServiceNowResponse = await serviceNowAPI.getServiceNowCredentials();
const firstAdmin = await okta.createTestUser(credentials.contacts.admin1.email);
const secondAdmin = await okta.createTestUser(credentials.contacts.admin2.email);
const technicalUser = await okta.createTestUser(credentials.contacts.technical.email);
const credentials: ServiceNowResponse = await api.serviceNow.getServiceNowCredentials();
const firstAdmin: PortalUser = await api.okta.createTestUser(credentials.contacts.admin1.email);
const secondAdmin: PortalUser = await api.okta.createTestUser(credentials.contacts.admin2.email);
const technicalUser: PortalUser = await api.okta.createTestUser(credentials.contacts.technical.email);

const adminToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const { org } = await portalAPI.createOrg(adminToken);
const adminToken = await api.portal.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const { org } = await api.portal.createOrg(adminToken);

await api.portal.inviteUserToOrg(adminToken, org.id, secondAdmin.email, PortalUserRoles.admin);
await api.portal.inviteUserToOrg(adminToken, org.id, technicalUser.email, PortalUserRoles.technical);

firstAdmin.org = { id: org.id, role: PortalUserRoles.admin };
secondAdmin.org = { id: org.id, role: PortalUserRoles.admin };
technicalUser.org = { id: org.id, role: PortalUserRoles.technical };

await portalAPI.inviteUserToOrg(adminToken, org.id, secondAdmin.email, PortalUserRoles.admin);
await portalAPI.inviteUserToOrg(adminToken, org.id, technicalUser.email, PortalUserRoles.technical);
return [firstAdmin, secondAdmin, technicalUser];
},

/**
* Encapsulates generating random Portal user(email could be specified)
* and adding it to the admin organization with specified role.
*
* @param adminUser admin user to provide credentials and target organization for new user
* @param role target {@link PortalUserRoles} role for new user to be added as
* @param email optional email for user, all the rest details will be generated
*/
addRandomUserToOrg: async (adminUser: PortalUser, role: PortalUserRoles.admin, email?: string) => {
const randomUser: PortalUser = await api.okta.createTestUser(email || '');
const adminToken = await api.portal.getUserAccessToken(adminUser.email, adminUser.password);
const orgId = Object.hasOwn(adminUser, 'org') ? adminUser.org!.id
: (await api.portal.getOrg(adminToken)).orgs[0].id;

await api.portal.inviteUserToOrg(adminToken, orgId, randomUser.email, role);
randomUser.org = { id: orgId, role: PortalUserRoles.admin };

return randomUser;
},
};
2 changes: 2 additions & 0 deletions playwright-tests/helpers/types/PortalUser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from '@faker-js/faker';
import { PortalUserRoles } from '@helpers/enums/portalUserRoles';

/**
* Type holder and generators collection for Portal Users used for tests.
Expand All @@ -9,6 +10,7 @@ export class PortalUser {
public password: string;
public firstName: string;
public lastName: string;
public org?: { id: string, role: PortalUserRoles };

public constructor(email = '') {
const firstName = faker.person.firstName();
Expand Down
7 changes: 6 additions & 1 deletion playwright-tests/tests/configuration/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { apiHelper, Settings } from '@api/helpers/apiHelper';
import { APIResponse } from 'playwright-core';
import {string} from "yaml/dist/schema/common/string";

const PATH_GET = 'v1/Settings/Get';
const PATH_CHANGE = 'v1/Settings/Change';
Expand All @@ -8,6 +9,10 @@ export enum SettingProperty {
bm = 'backup_management_enabled',
}

type SettingObject = {
settings: { [key: string]: never },
};

export const settings = {
/**
* Looks up a single Settings Property from returned.
Expand All @@ -20,7 +25,7 @@ export const settings = {
* @returns if property found - property value; {@code undefined} otherwise
*/
async getSettingsProperty(name: SettingProperty): Promise<string | undefined> {
const responseBody = await (await apiHelper.post(PATH_GET, {})).json();
const responseBody: SettingObject = await (await apiHelper.post(PATH_GET, {})).json();
console.log(`Response:\n${JSON.stringify(responseBody)}`);
return Object.hasOwn(responseBody.settings, name) ? responseBody.settings[name] as string : undefined;
},
Expand Down
17 changes: 0 additions & 17 deletions playwright-tests/tests/portal/pmmPortalUpgrade.spec.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
import { test } from '@playwright/test';
import { PortalUser } from '@helpers/types/PortalUser';
import { apiHelper } from '@api/helpers/apiHelper';
import { fileHelper } from '@helpers/fileHelper';
import { portalAPI } from '@api/portalApi';
import { serviceNowAPI } from '@api/serviceNowApi';
import { PortalUserRoles } from '@helpers/enums/portalUserRoles';
import Duration from '@helpers/enums/Duration';
import HomeDashboard from '@pages/HomeDashboard.page';
import grafanaHelper from '@helpers/grafanaHelper';
import { okta } from '@api/okta';
import { api } from '@api/api';
import {portalHelper} from "@helpers/portalHelper";

test.describe('Spec file for PMM connected the portal', async () => {
test.describe.configure({
retries: 0,
});
let firstAdmin: PortalUser;
let secondAdmin: PortalUser;
let technicalUser: PortalUser;
let freeUser: PortalUser;
let pmmVersion: number;
const fileName = 'portalCredentials';
let orgId: string;

test.beforeAll(async () => {
if (!pmmVersion) {
pmmVersion = (await api.pmm.serverV1.getPmmVersion()).minor;
}
[firstAdmin, secondAdmin, technicalUser] = await portalHelper.loadTestUsers();

freeUser = await okta.createTestUser();
// await portalAPI.inviteUserToOrg(adminToken, orgId, freeUser.email, PortalUserRoles.admin);
});

test.beforeEach(async ({ page }) => {
Expand Down
39 changes: 10 additions & 29 deletions playwright-tests/tests/portal/postPmmConnect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { expect, test } from '@playwright/test';
import { apiHelper } from '@api/helpers/apiHelper';
import { PortalUser } from '@helpers/types/PortalUser';
import { fileHelper } from '@helpers/fileHelper';
import { portalAPI } from '@api/portalApi';
import { okta } from '@api/okta';
import { SignInPage } from '@pages/SignIn.page';
import HomeDashboard from '@pages/HomeDashboard.page';
import TicketsPage from '@pages/platformPages/Tickets.page';
Expand All @@ -14,39 +12,22 @@ import grafanaHelper from '@helpers/grafanaHelper';
import PerconaPlatform from '@pages/pmmSettings/PerconaPlatform.page';
import { api } from '@api/api';
import { portalHelper } from '@helpers/portalHelper';
import { PortalUserRoles } from '@helpers/enums/portalUserRoles';

test.describe('Spec file for PMM connected the portal', async () => {
let firstAdmin: PortalUser;
let secondAdmin: PortalUser;
let technicalUser: PortalUser;
let freeUser: PortalUser;
let pmmVersion: number;
let orgId: string;
// let orgId: string;

test.beforeAll(async () => {
if (!pmmVersion) {
pmmVersion = (await api.pmm.serverV1.getPmmVersion()).minor;
}
[firstAdmin, secondAdmin, technicalUser] = await portalHelper.loadTestUsers();
// let adminToken;
//
// if (userCredentials) {
// [firstAdmin, secondAdmin, technicalUser] = JSON.parse(userCredentials);
// adminToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
// orgId = (await portalAPI.getOrg(adminToken)).orgs[0].id;
// } else {
// [firstAdmin, secondAdmin, technicalUser] = await serviceNowAPI.createServiceNowUsers();
// adminToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
// const { org } = await portalAPI.createOrg(adminToken);
//
// orgId = org.id;
// await portalAPI.inviteUserToOrg(adminToken, org.id, secondAdmin.email, PortalUserRoles.admin);
// await portalAPI.inviteUserToOrg(adminToken, org.id, technicalUser.email, PortalUserRoles.technical);
// await fileHelper.writeToFile(fileName, JSON.stringify([firstAdmin, secondAdmin, technicalUser]));
// }

freeUser = await okta.createTestUser();
// await portalAPI.inviteUserToOrg(adminToken, orgId, freeUser.email, PortalUserRoles.admin);
freeUser = await portalHelper.addRandomUserToOrg(firstAdmin, PortalUserRoles.admin);
});

test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -168,8 +149,8 @@ test.describe('Spec file for PMM connected the portal', async () => {
const homeDashboard = new HomeDashboard(page);
const signInPage = new SignInPage(page);
const environmentOverviewPage = new EnvironmentOverview(page);
const userToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const contactsEmail = (await portalAPI.getOrgDetails(userToken, orgId)).contacts.customer_success.email;
const userToken = await api.portal.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const contactsEmail = (await api.portal.getOrgDetails(userToken, firstAdmin.org!.id)).contacts.customer_success.email;

if (pmmVersion >= 29) {
await signInPage.oktaLogin(firstAdmin.email, firstAdmin.password);
Expand Down Expand Up @@ -383,7 +364,7 @@ test.describe('Spec file for PMM connected the portal', async () => {
state: 'visible', timeout: Duration.ThreeMinutes,
});
await page.goto(platformPage.perconaPlatformURL);
const adminToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const adminToken = await api.portal.getUserAccessToken(firstAdmin.email, firstAdmin.password);

await platformPage.connectToPortal(adminToken, `Test Server ${Date.now()}`, true);
} else {
Expand Down Expand Up @@ -440,14 +421,14 @@ test.describe('Spec file for PMM connected the portal', async () => {
});

test('After tests cleanup.', async () => {
const adminToken = await portalAPI.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const org = await portalAPI.getOrg(adminToken);
const adminToken = await api.portal.getUserAccessToken(firstAdmin.email, firstAdmin.password);
const org = await api.portal.getOrg(adminToken);

if (org.orgs.length) {
await portalAPI.deleteOrg(adminToken, org.orgs[0].id);
await api.portal.deleteOrg(adminToken, org.orgs[0].id);
}

await okta.deleteUsers([firstAdmin, secondAdmin, technicalUser]);
await api.okta.deleteUsers([firstAdmin, secondAdmin, technicalUser]);
await fileHelper.removeFile('portalCredentials');
});
});
2 changes: 1 addition & 1 deletion playwright-tests/tests/rbac/rbac.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import apiHelper from '@api/helpers/apiHelper';
import { apiHelper } from '@api/helpers/apiHelper';
import HomeDashboard from '@tests/pages/HomeDashboard.page';
import grafanaHelper from '@helpers/grafanaHelper';
import { RbacPage } from '@tests/tests/configuration/pages/Rbac.page';
Expand Down
12 changes: 6 additions & 6 deletions playwright-tests/tests/upgrade/upgradePmmViaUi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {expect, test} from '@playwright/test';
import apiHelper from "@api/helpers/apiHelper";
import { test } from '@playwright/test';
import { apiHelper } from '@api/helpers/apiHelper';
import grafanaHelper from '@helpers/grafanaHelper';
import HomeDashboard from '@pages/HomeDashboard.page';

test.describe('Common Upgrade PMM tests', async () => {
test.describe.configure({ retries: 0 });
test.describe.configure({
retries: 0,
});

test.beforeEach(async ({ page }) => {
await grafanaHelper.authorize(page);
await apiHelper.confirmTour(page);
await page.goto('');
});

test('PMM-T288 Verify user can see Update widget before upgrade [critical] @pmm-upgrade', async ({
page,
}) => {
test('PMM-T288 Verify user can see Update widget before upgrade [critical] @pmm-upgrade', async ({ page }) => {
const homeDashboard = new HomeDashboard(page);
await homeDashboard.pmmUpgrade.verifyUpgradeWidget();
});
Expand Down

0 comments on commit 041a9e5

Please sign in to comment.