Skip to content

Commit

Permalink
PMM-7 huge file names refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Yarosh committed Aug 18, 2023
1 parent 07fcb4b commit b15c5bf
Show file tree
Hide file tree
Showing 79 changed files with 670 additions and 636 deletions.
2 changes: 1 addition & 1 deletion codeceptConfigHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
agentsPage: './tests/configuration/pages/agentsPage.js',
pmmServerAdminSettingsPage: './tests/configuration/pages/pmmServerAdminSettingsPage.js',
pmmSettingsPage: './tests/configuration/pages/pmmSettingsPage.js',
portalAPI: './tests/pages/api/portalAPI.js',
portalAPI: './tests/pages/api/portalApi.js',
profileAPI: './tests/configuration/api/profileApi.js',
qanDetails: './tests/QAN/pages/qanDetailsFragment.js',
qanFilters: './tests/QAN/pages/qanFiltersFragment.js',
Expand Down
26 changes: 13 additions & 13 deletions playwright-tests/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { server } from '@api/server';
import { settings } from '@tests/tests/configuration/api/settings';
import { oktaApi } from '@api/oktaApi';
import { portalAPI } from '@api/portalApi';
import { serviceNowAPI } from '@api/serviceNowApi';
import { inventory } from '@api/inventory';
import { management } from '@api/management';
import {apiHelper} from "@api/helpers/apiHelper";
import { server } from '@api/server.api';
import { settingsApi } from '@tests/configuration/api/settings.api';
import { oktaApi } from '@api/okta.api';
import { portalApi } from '@api/portal.api';
import { serviceNowApi } from '@api/service-now.api';
import { inventoryApi } from '@api/inventory.api';
import { managementApi } from '@api/management.api';
import { apiHelper } from '@api/helpers/api-helper';

/**
* User facing api collection. Accessible on Frontend via /swagger path.
Expand All @@ -22,12 +22,12 @@ export const api = {
},
},
pmm: {
inventoryV1: inventory,
settingsV1: settings,
inventoryV1: inventoryApi,
settingsV1: settingsApi,
serverV1: server,
managementV1: management,
managementV1: managementApi,
},
okta: oktaApi,
portal: portalAPI,
serviceNow: serviceNowAPI,
portal: portalApi,
serviceNow: serviceNowApi,
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {
APIRequestContext, Page, expect, request,
} from '@playwright/test';
import config from '@tests/playwright.config';
import grafanaHelper from '@helpers/grafanaHelper';
import config from '@root/playwright.config';
import grafanaHelper from '@helpers/grafana-helper';
import { APIResponse } from 'playwright-core';
import { ReadStream } from 'fs';

export interface Settings {
pmm_public_address: string;
}

const getConfiguredRestApi = async (): Promise<APIRequestContext> => {
return request.newContext({
baseURL: config.use?.baseURL,
Expand All @@ -20,7 +16,7 @@ const getConfiguredRestApi = async (): Promise<APIRequestContext> => {
});
};

export const apiHelper = {
const apiHelper = {
// TODO: move it from the helper to proper file API? It's not actually API call.
confirmTour: async (page: Page) => {
await page.route('**/v1/user', (route) => {
Expand Down Expand Up @@ -91,3 +87,4 @@ export const apiHelper = {
return response;
},
};
export default apiHelper;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIRequestContext, APIResponse, expect, request } from '@playwright/test';
import { Constants } from '@helpers/Constants';
import constants from '@helpers/constants';

const checkAndReturnResponse = async (r: APIResponse) => {
await expect(r, `Expected to be OK: ${r.status()} ${r.statusText()}`).toBeOK();
Expand All @@ -25,7 +25,7 @@ interface ContextOptions {
const getRequestContext = async (
{ accessToken, timeout }: { accessToken?: string; timeout?: number; },
): Promise<APIRequestContext> => {
const options: ContextOptions = { baseURL: Constants.portal.url, timeout };
const options: ContextOptions = { baseURL: constants.portal.url, timeout };
if (accessToken) {
options.extraHTTPHeaders = {
Authorization: `Bearer ${accessToken}`,
Expand All @@ -34,26 +34,26 @@ const getRequestContext = async (
return request.newContext(options);
};

export const portalAPIHelper = {
export const portalApiHelper = {
async post(params: RequestParams) {
console.log(`POST: ${Constants.portal.url}${params.path}\nPayload: ${JSON.stringify(params.data)}`);
console.log(`POST: ${constants.portal.url}${params.path}\nPayload: ${JSON.stringify(params.data)}`);
return (await getRequestContext(params))
.post(params.path, { data: params.data }).then(checkAndReturnResponse);
},

async put(params: RequestParams) {
console.log(`PUT: ${Constants.portal.url}${params.path}\nPayload: ${JSON.stringify(params.data)}`);
console.log(`PUT: ${constants.portal.url}${params.path}\nPayload: ${JSON.stringify(params.data)}`);
return (await getRequestContext(params))
.put(params.path, { data: params.data }).then(checkAndReturnResponse);
},

async get(params: RequestParams) {
console.log(`GET: ${Constants.portal.url}${params.path}`);
console.log(`GET: ${constants.portal.url}${params.path}`);
return (await getRequestContext(params)).get(params.path).then(checkAndReturnResponse);
},

async delete(params: RequestParams) {
console.log(`GET: ${Constants.portal.url}${params.path}`);
console.log(`DELETE: ${constants.portal.url}${params.path}`);
return (await getRequestContext(params)).delete(params.path).then(checkAndReturnResponse);
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiHelper } from './helpers/apiHelper';
import { apiHelper } from './helpers/api-helper';

interface ListNodes {
generic?: NodeDetails[],
Expand All @@ -12,7 +12,7 @@ interface NodeDetails {
machine_id?: string,
}

export const inventory = {
export const inventoryApi = {
async listNodes(): Promise<ListNodes> {
return await (await apiHelper.post('v1/inventory/Nodes/List', {})).json() as ListNodes;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiHelper } from '@api/helpers/apiHelper';
import { apiHelper } from '@api/helpers/api-helper';

export interface ListRoles {
roles: Role[]
Expand All @@ -9,7 +9,7 @@ interface Role {
title: string,
}

export const management = {
export const managementApi = {
listRoles: async (): Promise<ListRoles | undefined> => {
const response = await apiHelper.post('/v1/management/Role/List', {});
return await response.json() as ListRoles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { expect, Page } from '@playwright/test';
import config from '@tests/playwright.config';
import { PortalUser } from '@helpers/types/PortalUser';
import * as dotenv from 'dotenv';
import { Constants } from '@helpers/Constants';
import { expect } from '@playwright/test';
import PortalUser from '@helpers/types/portal-user.class';
import constants from '@helpers/constants';
import axios, { AxiosResponse, Method } from 'axios';
import https from 'https';

dotenv.config();
const portalUrl = config.use!.baseURL!;

/**
* Implemented HTTP request to OKTA API using provided configuration.
*
Expand All @@ -17,10 +12,10 @@ const portalUrl = config.use!.baseURL!;
* @param payload JSON {@code object}; an empty object for get or delete requests
*/
const oktaRequest = async (method: Method, apiPath: string, payload = {}): Promise<AxiosResponse> => {
console.log(`${method.toUpperCase()}: ${Constants.okta.url}/api/v1${apiPath}\nPayload: ${JSON.stringify(payload)}`);
console.log(`${method.toUpperCase()}: ${constants.okta.url}/api/v1${apiPath}\nPayload: ${JSON.stringify(payload)}`);
const response = await axios({
url: `${Constants.okta.url}/api/v1${apiPath}`,
headers: { 'X-Requested-With': 'XMLHttpRequest', Authorization: Constants.okta.token },
url: `${constants.okta.url}/api/v1${apiPath}`,
headers: { 'X-Requested-With': 'XMLHttpRequest', Authorization: constants.okta.token },
method,
data: payload,
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PortalUserRoles } from '@helpers/enums/portalUserRoles';
import { portalAPIHelper } from './helpers/portalApiHelper';
import { PortalUserRoles } from '@helpers/enums/portal-user-roles';
import { portalApiHelper } from './helpers/portal-api-helper';

export const portalAPI = {
export const portalApi = {
async getUserAccessToken(username: string, password: string) {
const response = await portalAPIHelper.post({
const response = await portalApiHelper.post({
path: '/v1/auth/SignIn',
data: {
email: username,
Expand All @@ -14,38 +14,38 @@ export const portalAPI = {
},

async createOrg(accessToken: string, orgName = 'Test Organization') {
return await portalAPIHelper.post({
return await portalApiHelper.post({
path: '/v1/orgs',
accessToken,
timeout: 60_000,
timeout: 120_000,
data: {
name: orgName,
},
}) as { org: { id: string } };
},

async deleteOrg(accessToken: string, orgId: string) {
return portalAPIHelper.delete({
return portalApiHelper.delete({
path: `/v1/orgs/${orgId}`,
accessToken,
data: {},
});
},

async getOrg(accessToken: string) {
return await portalAPIHelper.post({
return await portalApiHelper.post({
accessToken, path: '/v1/orgs:search',
}) as { orgs: { id: string }[] };
},

async getOrgDetails(accessToken: string, orgId: string) {
return portalAPIHelper.get({
return portalApiHelper.get({
accessToken, path: `/v1/orgs/${orgId}`,
});
},

async inviteUserToOrg(accessToken: string, orgId: string, username: string, role: PortalUserRoles) {
return portalAPIHelper.post({
return portalApiHelper.post({
path: `/v1/orgs/${orgId}/members`,
accessToken,
data: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { apiHelper } from '@api/helpers/apiHelper';
import Duration from '@helpers/enums/Duration';
import { PmmVersion } from '@helpers/types/PmmVersion';
import apiHelper from '@api/helpers/api-helper';
import Duration from '@helpers/enums/duration';
import PmmVersion from '@helpers/types/pmm-version.class';
import { expect } from '@playwright/test';

export const server = {

/**
* @returns Promise<PmmVersion>
* @returns Promise<PmmVersionClass>
*/
getPmmVersion: async (): Promise<PmmVersion> => {
const response = await apiHelper.get('/v1/version', { timeout: Duration.ThreeMinutes });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { ServiceNowResponse, ServiceNowUser } from '@helpers/types/serviceNowResponse.interface';
import { ServiceNowResponse, ServiceNowUser } from '@helpers/types/service-now-response.interface';
import https from 'https';
import * as dotenv from 'dotenv';
import axios, { AxiosRequestConfig } from 'axios';
import { Constants } from '@helpers/Constants';
import constants from '@helpers/constants';
import { expect } from '@playwright/test';

dotenv.config();

const apiConfig: AxiosRequestConfig = {
auth: {
username: Constants.serviceNow.username, password: Constants.serviceNow.password,
username: constants.serviceNow.username, password: constants.serviceNow.password,
},
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
};

export const serviceNowAPI = {
export const serviceNowApi = {
async getServiceNowCredentials(): Promise<ServiceNowResponse> {
console.log(`POST: ${Constants.serviceNow.devUrl}\nPayload: ${JSON.stringify({})}`);
const response = await axios.post(Constants.serviceNow.devUrl, {}, apiConfig);
console.log(`POST: ${constants.serviceNow.devUrl}\nPayload: ${JSON.stringify({})}`);
const response = await axios.post(constants.serviceNow.devUrl, {}, apiConfig);
expect(response.status, `Expected to be 200: ${response.status} ${response.statusText}`).toEqual(200);
console.log(`Status: ${response.status} ${response.statusText}`);
return {
Expand Down

This file was deleted.

Loading

0 comments on commit b15c5bf

Please sign in to comment.