Skip to content

Commit

Permalink
RHIDP-2065: [QE] Automate Scenario - Telemetry (#1268)
Browse files Browse the repository at this point in the history
* RHIDP-2065: [QE] Automate Scenario - Telemetry

* Add skip to RBAC test, TODO

* Revert "Add skip to RBAC test, TODO"

This reverts commit 1c1d07c.

* Add guest login for RBAC

* Fix beforeEach

* GithubUser

* Update analytics-disabled-rbac.spec.ts

* Update analytics-disabled-rbac.spec.ts

* Verify plugin disabled RBAC in UI

* Fix before each

* Move to APIHelper
  • Loading branch information
zdrapela authored Jun 6, 2024
1 parent b827983 commit 9fd07aa
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .ibm/pipelines/value_files/values_showcase-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ global:
disabled: false
- package: ./dynamic-plugins/dist/janus-idp-backstage-plugin-rbac
disabled: false
- package: './dynamic-plugins/dist/janus-idp-backstage-plugin-analytics-provider-segment'
disabled: true


# this value will be overriden by 'helm install .... --set global.clusterRouterBase=value'
Expand Down
10 changes: 8 additions & 2 deletions e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ export default defineConfig({
{
name: 'showcase',
use: { ...devices['Desktop Chrome'] },
testIgnore: '**/playwright/e2e/plugins/rbac/**/*.spec.ts',
testIgnore: [
'**/playwright/e2e/plugins/rbac/**/*.spec.ts',
'**/playwright/e2e/plugins/analytics/analytics-disabled-rbac.spec.ts',
],
},
{
name: 'showcase-rbac',
use: { ...devices['Desktop Chrome'] },
testMatch: '**/playwright/e2e/plugins/rbac/**/*.spec.ts',
testMatch: [
'**/playwright/e2e/plugins/rbac/**/*.spec.ts',
'**/playwright/e2e/plugins/analytics/analytics-disabled-rbac.spec.ts',
],
},

// {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test, expect } from '@playwright/test';
import { Common } from '../../../utils/Common';
import { UIhelper } from '../../../utils/UIhelper';
import { UIhelperPO } from '../../../support/pageObjects/global-obj';

test.describe('Check RBAC "analytics-provider-segment" plugin', () => {
let common: Common;
let uiHelper: UIhelper;

test.beforeEach(async ({ page }) => {
uiHelper = new UIhelper(page);
common = new Common(page);
await common.loginAsGithubUser();
await uiHelper.openSidebar('Administration');
await uiHelper.verifyHeading('Administration');
await uiHelper.verifyLink('Plugins');
await uiHelper.clickTab('Plugins');
});

test('is disabled', async ({ page }) => {
await page
.getByPlaceholder('Filter')
.pressSequentially('backstage-plugin-analytics-provider-segment\n', {
delay: 300,
});
const row = await page.locator(
UIhelperPO.rowByText(
'@janus-idp/backstage-plugin-analytics-provider-segment',
),
);
expect(await row.locator('td').nth(2).innerText()).toBe('No'); // not enabled
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test';
import { Analytics } from '../../../utils/analytics/analytics';
import { APIHelper } from '../../../utils/APIHelper';

test('Check "analytics-provider-segment" plugin is enabled', async () => {
const analytics = new Analytics();
const apihelper = new APIHelper();

const authHeader = await apihelper.getGuestAuthHeader();
const pluginsList = await analytics.getDynamicPluginsList(authHeader);
const isPluginListed = analytics.checkPluginListed(
pluginsList,
'@janus-idp/backstage-plugin-analytics-provider-segment',
);

expect(isPluginListed).toBe(true);
});
18 changes: 17 additions & 1 deletion e2e-tests/playwright/utils/APIHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { request, APIResponse } from '@playwright/test';
import { request, APIResponse, expect } from '@playwright/test';

export class APIHelper {
private static githubAPIVersion = '2022-11-28';
Expand Down Expand Up @@ -38,4 +38,20 @@ export class APIHelper {
response = [...response, ...body];
return await this.getGithubPaginatedRequest(url, pageNo + 1, response);
}

async getGuestToken(): Promise<string> {
const context = await request.newContext();
const response = await context.post('/api/auth/guest/refresh');
expect(response.status()).toBe(200);
const data = await response.json();
return data.backstageIdentity.token;
}

async getGuestAuthHeader(): Promise<{ [key: string]: string }> {
const token = await this.getGuestToken();
const headers = {
Authorization: `Bearer ${token}`,
};
return headers;
}
}
18 changes: 18 additions & 0 deletions e2e-tests/playwright/utils/analytics/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, request } from '@playwright/test';

export class Analytics {
async getDynamicPluginsList(authHeader: { [key: string]: string }) {
const context = await request.newContext();
const loadedPluginsEndpoint = '/api/dynamic-plugins-info/loaded-plugins';
const response = await context.get(loadedPluginsEndpoint, {
headers: authHeader,
});
expect(response.status()).toBe(200);
const plugins = await response.json();
return plugins;
}

checkPluginListed(plugins: any, expected: string) {
return plugins.some((plugin: { name: string }) => plugin.name === expected);
}
}

0 comments on commit 9fd07aa

Please sign in to comment.