diff --git a/e2e/tests/keycloak-odoo-flows.spec.ts b/e2e/tests/keycloak-odoo-flows.spec.ts index f8524e4..c9e09df 100644 --- a/e2e/tests/keycloak-odoo-flows.spec.ts +++ b/e2e/tests/keycloak-odoo-flows.spec.ts @@ -42,6 +42,19 @@ test('Logging out from Odoo ends the session in Keycloak and logs out the user.' await expect(page).toHaveURL(/.*login/); }); +test('Odoo role assigned to a user in KC is correctly applied upon login in OpenMRS.', async ({ page }) => { + // setup + await keycloak.open(); + await keycloak.navigateToUsers(); + await keycloak.searchUser(); + await keycloak.searchRole(); + await keycloak.assinOdooRole(); + + // verify + await odoo.open(); + await openmrs.enterLoginCredentials(); +}); + test('Coded Odoo groups create corresponding Keycloak roles.', async ({ page }) => { // setup await page.goto(`${ODOO_URL}`); diff --git a/e2e/tests/keycloak-openmrs-flows.spec.ts b/e2e/tests/keycloak-openmrs-flows.spec.ts index f304d15..4d3acfe 100644 --- a/e2e/tests/keycloak-openmrs-flows.spec.ts +++ b/e2e/tests/keycloak-openmrs-flows.spec.ts @@ -36,6 +36,19 @@ test('Logging out from OpenMRS ends the session in Keycloak and logs out the use await expect(page).toHaveURL(/.*login/); }); +test('OpenMRS role assigned to a user in KC is correctly applied upon login in OpenMRS.', async ({ page }) => { + // setup + await keycloak.open(); + await keycloak.navigateToUsers(); + await keycloak.searchUser(); + await keycloak.searchRole(); + await keycloak.assinOpenMRSRole(); + + // verify + await page.goto(`${O3_URL}/openmrs/admin/users/users.list`); + await expect(page.locator('tr td:nth-child(5) span')).toContainText('Inventory Reporting'); +}); + test('Creating an OpenMRS role creates the corresponding Keycloak role.', async ({ page }) => { // setup await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); diff --git a/e2e/tests/keycloak-superset-flows.spec.ts b/e2e/tests/keycloak-superset-flows.spec.ts index 7409f45..5358f23 100644 --- a/e2e/tests/keycloak-superset-flows.spec.ts +++ b/e2e/tests/keycloak-superset-flows.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test'; -import { KEYCLOAK_URL, SUPERSET_URL } from '../utils/configs/globalSetup'; +import { KEYCLOAK_URL, O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup'; import { Keycloak } from '../utils/functions/keycloak'; import { OpenMRS, delay } from '../utils/functions/openmrs'; import { Superset, randomSupersetRoleName} from '../utils/functions/superset'; @@ -42,6 +42,19 @@ test('Logging out from Superset ends the session in Keycloak and logs out the us await expect(page).toHaveURL(/.*login/); }); +test('Superset role assigned to a user in KC is correctly applied upon login in Superset.', async ({ page }) => { + // setup + await keycloak.open(); + await keycloak.navigateToUsers(); + await keycloak.searchUser(); + await keycloak.searchRole(); + await keycloak.assinSupersetRole(); + + // verify + await page.goto(`${SUPERSET_URL}/users/list/`); + await expect(page.locator('tr td:nth-child(5) span')).toContainText('Inventory Reporting'); +}); + test('Creating a Superset role creates the corresponding Keycloak role.', async ({ page }) => { // setup await openmrs.login(); diff --git a/e2e/utils/functions/keycloak.ts b/e2e/utils/functions/keycloak.ts index 9fe78e8..1a59265 100644 --- a/e2e/utils/functions/keycloak.ts +++ b/e2e/utils/functions/keycloak.ts @@ -37,6 +37,51 @@ export class Keycloak { await delay(2000); } + async navigateToUsers() { + await this.page.getByTestId('realmSelectorToggle').click(); + await expect(this.page.getByRole('menuitem', { name: 'ozone' })).toBeVisible(); + await this.page.getByRole('menuitem', { name: 'ozone' }).click(); + await this.page.getByRole('link', { name: 'Users' }).click(); + await delay(2000);// + } + + async searchUser() { + await expect(this.page.getByPlaceholder('Search user')).toBeVisible(); + await this.page.getByPlaceholder('Search user').fill('jdoe'); + await this.page.getByPlaceholder('Search user').press('Enter'); + await this.page.locator('tr td:nth-child(2) a').click(); + await this.page.getByTestId('role-mapping-tab').click(); + } + + async searchRole() { + await this.page.getByTestId('assignRole').click(); + await this.page.getByRole('button', { name: 'Filter by realm roles' }).click(); + await this.page.getByTestId('roles').click(); + await expect(this.page.getByPlaceholder('Search by role name')).toBeVisible(); + } + + async assinOdooRole() { + await this.page.getByPlaceholder('Search by role name').fill('Inventory Reporting');//Application: Enters Vitals'); + await this.page.getByRole('checkbox', { name: 'Select row' }).check(); + await this.page.getByTestId('assign').click(); + await expect(this.page.getByText('User role mapping successfully updated')).toBeVisible(); + } + + async assinOpenMRSRole() { + await this.page.getByPlaceholder('Search by role name').fill('Inventory Reporting'); + await delay(3000); + await this.page.getByRole('checkbox', { name: 'Select row' }).check(); + await this.page.getByTestId('assign').click(); + await expect(this.page.getByText('User role mapping successfully updated')).toBeVisible(); + } + + async assinSupersetRole() { + await this.page.getByPlaceholder('Search by role name').fill('Inventory Reporting');//Application: Enters Vitals'); + await this.page.getByRole('checkbox', { name: 'Select row' }).check(); + await this.page.getByTestId('assign').click(); + await expect(this.page.getByText('User role mapping successfully updated')).toBeVisible(); + } + async selectOpenMRSId() { await expect(this.page.getByPlaceholder('Search for client')).toBeVisible(); await this.page.getByPlaceholder('Search for client').fill('openmrs');