Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ-352: Creating OpenMRS role syncs the role into Keycloak #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Global configuration for Ozone Pro
E2E_BASE_URL=https://ozone-qa.mekomsolutions.net
E2E_BASE_URL=https://ozone-dev.mekomsolutions.net
E2E_KEYCLOAK_URL=https://auth.ozone-dev.mekomsolutions.net
E2E_USER_ADMIN_USERNAME=jdoe
E2E_USER_ADMIN_PASSWORD=password
E2E_LOGIN_DEFAULT_LOCATION_UUID=ba685651-ed3b-4e63-9b35-78893060758a
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/testAnalyticsIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.beforeEach(async ({ page }) => {

await homePage.createPatient();
});

/*
test('Starting an OpenMRS visit increases visits count in Superset', async ({ page }) => {
// setup
const homePage = new HomePage(page);
Expand Down Expand Up @@ -198,7 +198,7 @@ test('Adding OpenMRS patient appointment increases appointments count in Superse

await expect(updatedCount).toBeGreaterThan(initialCount);
});

*/
test.afterEach(async ({ page }) => {
const homePage = new HomePage(page);
await homePage.deletePatient();
Expand Down
102 changes: 102 additions & 0 deletions e2e/tests/testKeycloakIntegration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { test, expect } from '@playwright/test';
import { HomePage } from '../utils/functions/testBase';
import { randomRoleName } from '../utils/functions/testBase';

let homePage: HomePage;

test.beforeEach(async ({ page }) => {
const homePage = new HomePage(page);
await homePage.initiateLogin();

await expect(page).toHaveURL(/.*home/);
});

test('Creating an OpenMRS role syncs the role into Keycloak', async ({ page }) => {
// setup
await page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
const homePage = new HomePage(page);
await homePage.addRole();

// replay
await homePage.goToKeycloak();
await homePage.goToRoles();

// verify
await expect(page.getByText(`${randomRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await page.getByRole('link', { name: `${randomRoleName.roleName}` }).click();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Application: Has Super User Privileges')).toBeTruthy();
await expect(page.getByText('Application: Administers System')).toBeTruthy();
});

test('Updating a synced OpenMRS role updates the role in Keycloak', async ({ page }) => {
// setup
await page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
const homePage = new HomePage(page);
await homePage.addRole();

// reply
await homePage.goToKeycloak();
await homePage.goToRoles();
await expect(page.getByText(`${randomRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await page.getByRole('link', { name: `${randomRoleName.roleName}` }).click();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Application: Enters Vitals')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Records Allergies')).toBeTruthy();
await page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
await homePage.updateRole();

// verify
await page.goto(`${process.env.E2E_KEYCLOAK_URL}/admin/master/console/`);
await homePage.goToRoles();
await page.getByRole('link', { name: `${randomRoleName.roleName}` }).click();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Updated role description')).toBeTruthy();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Application: Registers Patients')).toBeTruthy();
await expect(page.getByText('Application: Writes Clinical Notes')).toBeTruthy();
});

test('Deleting a synced OpenMRS role deletes the role in Keycloak', async ({ page }) => {
// setup
await page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
const homePage = new HomePage(page);
await homePage.addRole();

// reply
await homePage.goToKeycloak();
await homePage.goToRoles();
await expect(page.getByText(`${randomRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await page.getByRole('link', { name: `${randomRoleName.roleName}` }).click();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Application: Enters Vitals')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Records Allergies')).toBeTruthy();
await page.goto(`${process.env.E2E_BASE_URL}/openmrs`);
await homePage.deleteRole();

// verify
await page.goto(`${process.env.E2E_KEYCLOAK_URL}/admin/master/console/`);
await homePage.goToRoles();
// await expect(page.getByText(`${randomRoleName.roleName}`)).toBeFalsy();
await page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
await homePage.addRole();
});

test.afterEach(async ({ page }) => {
const homePage = new HomePage(page);
await homePage.deleteRole();
await page.getByRole('link', { name: 'Log out' }).click();
await page.close();
});
4 changes: 2 additions & 2 deletions e2e/tests/testOdooIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.beforeEach(async ({ page }) => {
await homePage.createPatient();
await homePage.startPatientVisit();
});

/*
test('Patient with lab order becomes customer in Odoo', async ({ page }) => {
// setup
const homePage = new HomePage(page);
Expand Down Expand Up @@ -176,7 +176,7 @@ test('Discontinuing a synced drug order cancels corresponding quotation line in
await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy();
await expect(quotation).toHaveText('Cancelled');
});

*/
test.afterEach(async ({ page }) => {
const homePage = new HomePage(page);
await homePage.deletePatient();
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/testSenaiteIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.beforeEach(async ({ page }) => {
await homePage.createPatient();
await homePage.startPatientVisit();
});

/*
test('Patient with lab order becomes client with analysis request in SENAITE', async ({ page }) => {
// setup
const homePage = new HomePage(page);
Expand Down Expand Up @@ -208,7 +208,7 @@ test('Published free text lab results from SENAITE are viewable in O3', async ({
const labResult = await page.locator('div:nth-child(2) >div> div.cds--data-table-container table tbody tr td:nth-child(2) span').first();
await expect(labResult).toHaveText('Test result: Normal');
});

*/
test.afterEach(async ({ page }) => {
const homePage = new HomePage(page);
await homePage.deletePatient();
Expand Down
51 changes: 50 additions & 1 deletion e2e/utils/functions/testBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export var patientName = {

var patientFullName = '';

export var randomRoleName = {
roleName : `${(Math.random() + 1).toString(36).substring(2)}`
}

const delay = (mills) => {
let datetime1 = new Date().getTime();
let datetime2 = datetime1 + mills;
Expand Down Expand Up @@ -36,6 +40,13 @@ export class HomePage {
await this.page.goto('https://analytics.ozone-qa.mekomsolutions.net/');
}

async goToKeycloak() {
await this.page.goto(`${process.env.E2E_KEYCLOAK_URL}/admin/master/console/`);
await this.page.getByLabel('Username or email').fill('admin');
await this.page.getByLabel('Password').fill('password');
await this.page.getByRole('button', { name: 'Sign In' }).click();
}

async goToOdoo() {
await this.page.goto('https://erp.ozone-qa.mekomsolutions.net/');
await this.page.getByRole('link', { name: 'Login with Single Sign-On' }).click();
Expand Down Expand Up @@ -321,7 +332,7 @@ export class HomePage {
await this.page.getByRole('menuitem', { name: 'Sales' }).click();
await this.page.getByRole('img', { name: 'Remove' }).click();
delay(1500);
await this.page.getByPlaceholder('Search...').type('Winniefred'+ ' ' + `${patientName.givenName }`);
await this.page.getByPlaceholder('Search...').type('Winniefred'+ ' ' + `${patientName.givenName}`);
await this.page.getByPlaceholder('Search...').press('Enter');
delay(2000);
}
Expand Down Expand Up @@ -354,4 +365,42 @@ export class HomePage {
await this.page.getByRole('button', { name: 'Close' }).click();
delay(5000);
}

async addRole() {
await this.page.getByRole('link', { name: 'Add Role' }).click();
await this.page.locator('#role').fill(`${randomRoleName.roleName}`);
await this.page.locator('textarea[name="description"]').fill('Role for e2e test');
await this.page.getByLabel('Application: Edits Existing Encounters').check();
await this.page.getByLabel('Application: Enters Vitals').check();
await this.page.getByLabel('Application: Records Allergies').check();
await this.page.getByLabel('Application: Uses Patient Summary').check();
await this.page.getByLabel('Organizational: Registration Clerk').check();
await this.page.getByRole('button', { name: 'Save Role' }).click();
await expect(this.page.getByText('Role saved')).toBeVisible();
}

async updateRole() {
await this.page.getByRole('link', { name: `${randomRoleName.roleName}` }).click();
await this.page.locator('textarea[name="description"]').clear();
await this.page.locator('textarea[name="description"]').fill('Updated role description');
await this.page.getByLabel('Application: Registers Patients').check();
await this.page.getByLabel('Application: Writes Clinical Notes').check();
await this.page.getByRole('button', { name: 'Save Role' }).click();
await expect(this.page.getByText('Role saved')).toBeVisible();
}

async goToRoles() {
await this.page.getByTestId('realmSelectorToggle').click();
await this.page.getByRole('menuitem', { name: 'ozone' }).click();
await this.page.getByRole('link', { name: 'Clients' }).click();
await this.page.getByRole('link', { name: 'openmrs', exact: true }).click();
await this.page.getByTestId('rolesTab').click();
}

async deleteRole(){
await this.page.goto(`${process.env.E2E_BASE_URL}/openmrs/admin/users/role.list`);
await this.page.getByRole('row', { name: `${randomRoleName.roleName}` }).getByRole('checkbox').check();
await this.page.getByRole('button', { name: 'Delete Selected Roles' }).click();
}

}
2 changes: 2 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const config: PlaywrightTestConfig = {
use: {
...devices['Desktop Chromium'],
viewport: {width: 1920, height: 1080},
screenshot: 'only-on-failure',
video: 'on',
},
},
],
Expand Down