-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(console): add rbac ui tests for organization
- Loading branch information
Showing
4 changed files
with
374 additions
and
3 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
packages/integration-tests/src/tests/console/rbac/organization-rbac.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import ExpectApiResources from '#src/ui-helpers/expect-api-resources.js'; | ||
import ExpectConsole from '#src/ui-helpers/expect-console.js'; | ||
import ExpectOrganizations from '#src/ui-helpers/expect-organizations.js'; | ||
import { | ||
generateResourceIndicator, | ||
generateResourceName, | ||
generateRoleName, | ||
generateScopeName, | ||
} from '#src/utils.js'; | ||
|
||
const testPage = await browser.newPage(); | ||
|
||
const expectConsole = new ExpectConsole(testPage); | ||
const expectApiResources = new ExpectApiResources(testPage); | ||
const expectOrganizations = new ExpectOrganizations(testPage); | ||
|
||
const apiResourceName = generateResourceName(); | ||
const apiResourceIndicator = generateResourceIndicator(); | ||
const apiPermissionName = generateScopeName(); | ||
|
||
const organizationPermissionName = generateScopeName(); | ||
const organizationRoleName = generateRoleName(); | ||
|
||
const dummyPermissionDescription = 'Dummy permission description'; | ||
|
||
describe('Organization RBAC', () => { | ||
beforeAll(async () => { | ||
await expectConsole.start(); | ||
}); | ||
|
||
it('navigates to API resources page', async () => { | ||
await expectApiResources.gotoPage('/api-resources', 'API resources'); | ||
await expectApiResources.toExpectTableHeaders('API name', 'API Identifier'); | ||
}); | ||
|
||
it('creates an API resource', async () => { | ||
await expectApiResources.toCreateApiResource({ | ||
name: apiResourceName, | ||
indicator: apiResourceIndicator, | ||
}); | ||
}); | ||
|
||
it('creates an API permission for organization role', async () => { | ||
await expectApiResources.toCreateApiResourcePermission( | ||
{ name: apiPermissionName, description: dummyPermissionDescription }, | ||
apiResourceName | ||
); | ||
}); | ||
|
||
it('navigates to the organization template', async () => { | ||
await expectConsole.gotoPage('/organization-template', 'Organization template'); | ||
await expectConsole.toExpectTabs('Organization roles', 'Organization permissions'); | ||
await expectConsole.toExpectTableHeaders('Organization Role', 'Permissions'); | ||
}); | ||
|
||
it('creates an organization permission', async () => { | ||
await expectOrganizations.toCreateOrganizationPermission({ | ||
name: organizationPermissionName, | ||
description: dummyPermissionDescription, | ||
}); | ||
}); | ||
|
||
it('creates an organization role', async () => { | ||
await expectOrganizations.toCreateOrganizationRole({ | ||
name: organizationRoleName, | ||
description: dummyPermissionDescription, | ||
}); | ||
}); | ||
|
||
it('assigns organization permissions and API permissions for organization role', async () => { | ||
await expectOrganizations.toAssignPermissionsForOrganizationRole({ | ||
organizationPermission: organizationPermissionName, | ||
apiPermission: { | ||
resource: apiResourceName, | ||
permission: apiPermissionName, | ||
}, | ||
forOrganizationRole: organizationRoleName, | ||
}); | ||
}); | ||
|
||
// Clean up | ||
it('deletes created resources', async () => { | ||
// Delete created organization role | ||
await expectOrganizations.toDeleteOrganizationRole(organizationRoleName); | ||
|
||
// Delete created organization permissions | ||
await expectOrganizations.toDeleteOrganizationPermission(organizationPermissionName); | ||
|
||
// Delete created API resource | ||
await expectApiResources.toDeleteApiResource(apiResourceName); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
packages/integration-tests/src/ui-helpers/expect-api-resources.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { cls } from '#src/utils.js'; | ||
|
||
import ExpectConsole from './expect-console.js'; | ||
import { expectToClickDetailsPageOption, expectToClickModalAction } from './index.js'; | ||
|
||
export default class ExpectApiResources extends ExpectConsole { | ||
/** | ||
* Go to the api resources page and create a new API resource, then assert that the URL matches | ||
* the API resource detail page. | ||
* | ||
* @param {Object} params The parameters for creating the API resource. | ||
* @param {string} params.name The name of the API resource to create. | ||
* @param {string} params.indicator The indicator of the API resource to create. | ||
*/ | ||
async toCreateApiResource({ name, indicator }: { name: string; indicator: string }) { | ||
await this.gotoPage('/api-resources', 'API resources'); | ||
await this.toClickButton('Create API resource'); | ||
|
||
await this.toExpectModal('Start with tutorials'); | ||
|
||
// Click bottom button to skip tutorials | ||
await this.toClickButton('Continue without tutorial', false); | ||
|
||
await this.toExpectModal('Create API resource'); | ||
|
||
await this.toFillForm({ | ||
name, | ||
indicator, | ||
}); | ||
|
||
await this.toClick( | ||
['.ReactModalPortal', `button${cls('primary')}`].join(' '), | ||
'Create API resource', | ||
false | ||
); | ||
|
||
this.toMatchUrl(/\/api-resources\/.+$/); | ||
} | ||
|
||
/** | ||
* Go to the api resource details page by given resource name and create a new API permission, then assert the permission is created. | ||
* | ||
* @param {Object} params The parameters for creating the API permission. | ||
* @param {string} params.name The name of the API permission to create. | ||
* @param {string} params.description The description of the API permission to create. | ||
* @param {string} forResourceName The name of the API resource for which the permission is created. | ||
*/ | ||
async toCreateApiResourcePermission( | ||
{ | ||
name, | ||
description, | ||
}: { | ||
name: string; | ||
description: string; | ||
}, | ||
forResourceName: string | ||
) { | ||
await this.gotoPage('/api-resources', 'API resources'); | ||
await this.toExpectTableCell(forResourceName); | ||
|
||
await this.toClickTableCell(forResourceName); | ||
|
||
// Expect the API resource details page | ||
await expect(this.page).toMatchElement([cls('header'), cls('metadata'), 'div'].join(' '), { | ||
text: forResourceName, | ||
}); | ||
|
||
await this.toClickButton('Create permission', false); | ||
|
||
await this.toExpectModal('Create permission'); | ||
|
||
await this.toFillForm({ name, description }); | ||
|
||
await this.toClick( | ||
['.ReactModalPortal', `button${cls('primary')}`].join(' '), | ||
'Create permission', | ||
false | ||
); | ||
|
||
await this.waitForToast(`The permission ${name} has been successfully created`); | ||
|
||
await this.toExpectTableCell(name); | ||
} | ||
|
||
/** | ||
* Go to the api resource details page by given resource name and delete the API resource. | ||
* | ||
* @param {string} name The name of the API resource to delete. | ||
*/ | ||
async toDeleteApiResource(name: string) { | ||
await this.gotoPage('/api-resources', 'API resources'); | ||
await this.toExpectTableCell(name); | ||
await this.toClickTableCell(name); | ||
|
||
await expectToClickDetailsPageOption(this.page, 'Delete'); | ||
|
||
await this.toExpectModal('Reminder'); | ||
await this.toFill('.ReactModalPortal input', name); | ||
|
||
await expectToClickModalAction(this.page, 'Delete'); | ||
await this.waitForToast(`The API resource ${name} has been successfully deleted`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.