diff --git a/tests/e2e/cucumber/environment/index.ts b/tests/e2e/cucumber/environment/index.ts index ea075e86006..62fc11021db 100644 --- a/tests/e2e/cucumber/environment/index.ts +++ b/tests/e2e/cucumber/environment/index.ts @@ -15,7 +15,12 @@ import { config } from '../../config' import { api, environment } from '../../support' import { World } from './world' import { state } from './shared' -import { createdSpaceStore, createdLinkStore } from '../../support/store' +import { + createdSpaceStore, + createdLinkStore, + createdGroupStore, + createdUserStore +} from '../../support/store' import { User } from '../../support/types' export { World } @@ -108,7 +113,9 @@ After(async function (this: World, { result }: ITestCaseHookParameter) { await this.actorsEnvironment.close() } + await cleanUpUser(this.usersEnvironment.getUser({ key: 'admin' })) await cleanUpSpaces(this.usersEnvironment.getUser({ key: 'admin' })) + await cleanUpGroup(this.usersEnvironment.getUser({ key: 'admin' })) createdLinkStore.clear() }) @@ -117,6 +124,19 @@ AfterAll(() => state.browser && state.browser.close()) setWorldConstructor(World) +const cleanUpUser = async (adminUser: User) => { + const requests = [] + createdUserStore.forEach((user) => { + if (config.ocis) { + requests.push(api.graph.deleteUser({ user, admin: adminUser })) + } else { + requests.push(api.user.deleteUser({ user, admin: adminUser })) + } + }) + await Promise.all(requests) + createdUserStore.clear() +} + const cleanUpSpaces = async (adminUser: User) => { const requests = [] createdSpaceStore.forEach((space) => { @@ -139,3 +159,17 @@ const cleanUpSpaces = async (adminUser: User) => { await Promise.all(requests) createdSpaceStore.clear() } + +const cleanUpGroup = async (adminUser: User) => { + const requests = [] + createdGroupStore.forEach((group) => { + if (config.ocis) { + requests.push(api.graph.deleteGroup({ group, admin: adminUser })) + } else { + requests.push(api.user.deleteGroup({ group, admin: adminUser })) + } + }) + + await Promise.all(requests) + createdGroupStore.clear() +} diff --git a/tests/e2e/cucumber/steps/api.ts b/tests/e2e/cucumber/steps/api.ts index 0e58677dd53..a3ed5a2eaec 100644 --- a/tests/e2e/cucumber/steps/api.ts +++ b/tests/e2e/cucumber/steps/api.ts @@ -12,10 +12,8 @@ Given( for (const info of stepTable.hashes()) { const user = this.usersEnvironment.getUser({ key: info.id }) if (config.ocis) { - await api.graph.deleteUser({ user, admin }) await api.graph.createUser({ user, admin }) } else { - await api.user.deleteUser({ user, admin }) await api.user.createUser({ user, admin }) } } @@ -69,10 +67,8 @@ Given( for (const info of stepTable.hashes()) { const group = this.usersEnvironment.getGroup({ key: info.id }) if (config.ocis) { - await api.graph.deleteGroup({ group, admin }) await api.graph.createGroup({ group, admin }) } else { - await api.user.deleteGroup({ group, admin }) await api.user.createGroup({ group, admin }) } } diff --git a/tests/e2e/cucumber/steps/ui/adminSettings.ts b/tests/e2e/cucumber/steps/ui/adminSettings.ts index d5c9cb852ca..bb887fac513 100644 --- a/tests/e2e/cucumber/steps/ui/adminSettings.ts +++ b/tests/e2e/cucumber/steps/ui/adminSettings.ts @@ -1,6 +1,6 @@ import { DataTable, Then, When } from '@cucumber/cucumber' import { World } from '../../environment' -import { api, objects } from '../../../support' +import { objects } from '../../../support' import { expect } from '@playwright/test' Then( @@ -300,22 +300,6 @@ When( const { page } = this.actorsEnvironment.getActor({ key: stepUser }) const usersObject = new objects.applicationAdminSettings.Users({ page }) - // deleting a user with a same userName before testing - if (attribute === 'userName') { - const newUser = this.usersEnvironment.createUser({ - key: value, - user: { - id: value, - displayName: '', - password: 'password', - email: '' - } - }) - await api.graph.deleteUser({ - user: newUser, - admin: this.usersEnvironment.getUser({ key: stepUser }) - }) - } await usersObject.changeUser({ key: user, attribute: attribute, @@ -405,16 +389,7 @@ When( const groupsObject = new objects.applicationAdminSettings.Groups({ page }) for (const info of stepTable.hashes()) { - const group = this.usersEnvironment.getGroup({ key: info.id }) - await api.graph.deleteGroup({ - group: group, - admin: this.usersEnvironment.getUser({ key: stepUser }) - }) - } - await page.reload() - for (const info of stepTable.hashes()) { - const group = this.usersEnvironment.getGroup({ key: info.id }) - group.uuid = await groupsObject.createGroup({ key: group.displayName }) + await groupsObject.createGroup({ key: info.id }) } } ) @@ -473,11 +448,6 @@ When( const { page } = this.actorsEnvironment.getActor({ key: stepUser }) const usersObject = new objects.applicationAdminSettings.Users({ page }) for (const info of stepTable.hashes()) { - const user = this.usersEnvironment.getUser({ key: info.name }) - await api.graph.deleteUser({ - user: user, - admin: this.usersEnvironment.getUser({ key: stepUser }) - }) await usersObject.createUser({ name: info.name, displayname: info.displayname, diff --git a/tests/e2e/cucumber/steps/ui/session.ts b/tests/e2e/cucumber/steps/ui/session.ts index 095a36a6a85..f9fb8647be0 100644 --- a/tests/e2e/cucumber/steps/ui/session.ts +++ b/tests/e2e/cucumber/steps/ui/session.ts @@ -18,7 +18,12 @@ async function createNewSession(world: World, stepUser: string) { async function LogInUser(this: World, stepUser: string): Promise { const sessionObject = await createNewSession(this, stepUser) const { page } = this.actorsEnvironment.getActor({ key: stepUser }) - const user = this.usersEnvironment.getUser({ key: stepUser }) + + const user = + stepUser === 'Admin' + ? this.usersEnvironment.getUser({ key: stepUser }) + : this.usersEnvironment.getCreatedUser({ key: stepUser }) + await page.goto(config.frontendUrl) await sessionObject.login({ user }) await page.waitForSelector('#web') diff --git a/tests/e2e/support/api/graph/userManagement.ts b/tests/e2e/support/api/graph/userManagement.ts index 863321dfc7f..3ef80eb834e 100644 --- a/tests/e2e/support/api/graph/userManagement.ts +++ b/tests/e2e/support/api/graph/userManagement.ts @@ -84,8 +84,8 @@ export const createGroup = async ({ checkResponseStatus(response, 'Failed while creating group') - const responseData = await response.json() - group.uuid = responseData.id + const usersEnvironment = new UsersEnvironment() + usersEnvironment.storeCreatedGroup({ group: { ...group, uuid: (await response.json()).id } }) return group } @@ -109,7 +109,9 @@ export const deleteGroup = async ({ group: Group admin: User }): Promise => { - const groupId = await getGroupId({ group, admin }) + const usersEnvironment = new UsersEnvironment() + const groupId = usersEnvironment.getCreatedGroup({ key: group.id }).uuid + await request({ method: 'DELETE', path: join('graph', 'v1.0', 'groups', groupId), diff --git a/tests/e2e/support/environment/userManagement.ts b/tests/e2e/support/environment/userManagement.ts index 48c93e1c78f..484b45fea0c 100644 --- a/tests/e2e/support/environment/userManagement.ts +++ b/tests/e2e/support/environment/userManagement.ts @@ -1,6 +1,5 @@ import { Group, User } from '../types' -import { dummyUserStore, dummyGroupStore } from '../store' -import { createdUserStore } from '../store/user' +import { dummyUserStore, dummyGroupStore, createdUserStore, createdGroupStore } from '../store' export class UsersEnvironment { getUser({ key }: { key: string }): User { @@ -65,23 +64,30 @@ export class UsersEnvironment { } getGroup({ key }: { key: string }): Group { - const uniqueKey = key.toLowerCase() + const groupKey = key.toLowerCase() - if (!dummyGroupStore.has(uniqueKey)) { - throw new Error(`group with key '${uniqueKey}' not found`) + if (!dummyGroupStore.has(groupKey)) { + throw new Error(`group with key '${groupKey}' not found`) } - return dummyGroupStore.get(uniqueKey) + return dummyGroupStore.get(groupKey) } - createGroup({ key, group }: { key: string; group: Group }): Group { - const uniqueKey = key.toLowerCase() + getCreatedGroup({ key }: { key: string }): Group { + const groupKey = key.toLowerCase() - if (dummyUserStore.has(uniqueKey)) { - throw new Error(`group with key '${uniqueKey}' already exists`) + if (!createdGroupStore.has(groupKey)) { + throw new Error(`group with key '${groupKey}' not found`) } - dummyGroupStore.set(uniqueKey, group) + return createdGroupStore.get(groupKey) + } + + storeCreatedGroup({ group }: { group: Group }): Group { + if (createdGroupStore.has(group.id)) { + throw new Error(`user with key '${group.id}' already exists`) + } + createdGroupStore.set(group.id, group) return group } diff --git a/tests/e2e/support/objects/app-admin-settings/groups/actions.ts b/tests/e2e/support/objects/app-admin-settings/groups/actions.ts index eb7804c5421..072d4a9b81c 100644 --- a/tests/e2e/support/objects/app-admin-settings/groups/actions.ts +++ b/tests/e2e/support/objects/app-admin-settings/groups/actions.ts @@ -18,7 +18,7 @@ const closeEditPanel = '.sidebar-panel__header .header__close' const userInput = '#%s-input' const compareDialogConfirm = '.compare-save-dialog-confirm-btn' -export const createGroup = async (args: { page: Page; key: string }): Promise => { +export const createGroup = async (args: { page: Page; key: string }): Promise => { const { page, key } = args await page.locator(newGroupBtn).click() await page.locator(createGroupInput).fill(key) @@ -30,8 +30,8 @@ export const createGroup = async (args: { page: Page; key: string }): Promise => { diff --git a/tests/e2e/support/objects/app-admin-settings/groups/index.ts b/tests/e2e/support/objects/app-admin-settings/groups/index.ts index 152962c39f2..06aef42ffd7 100644 --- a/tests/e2e/support/objects/app-admin-settings/groups/index.ts +++ b/tests/e2e/support/objects/app-admin-settings/groups/index.ts @@ -17,21 +17,35 @@ export class Groups { this.#usersEnvironment = new UsersEnvironment() this.#page = page } + getUUID({ key }: { key: string }): string { - return this.#usersEnvironment.getGroup({ key }).uuid + return this.#usersEnvironment.getCreatedGroup({ key }).uuid } - async createGroup({ key }: { key: string }): Promise { - return await createGroup({ page: this.#page, key: key }) + + async createGroup({ key }: { key: string }): Promise { + const group = this.#usersEnvironment.getGroup({ key }) + const response = await createGroup({ page: this.#page, key: group.displayName }) + this.#usersEnvironment.storeCreatedGroup({ + group: { + id: key, + uuid: response['id'], + displayName: response['displayName'] + } + }) } + getDisplayedGroups(): Promise { return getDisplayedGroups({ page: this.#page }) } + async selectGroup({ key }: { key: string }): Promise { await selectGroup({ page: this.#page, uuid: this.getUUID({ key }) }) } + async deleteGroupUsingBatchAction({ groupIds }: { groupIds: string[] }): Promise { await deleteGrouprUsingBatchAction({ page: this.#page, groupIds }) } + async deleteGroupUsingContextMenu({ key }: { key: string }): Promise { await deleteGroupUsingContextMenu({ page: this.#page, uuid: this.getUUID({ key }) }) } diff --git a/tests/e2e/support/objects/app-admin-settings/users/actions.ts b/tests/e2e/support/objects/app-admin-settings/users/actions.ts index 245d2ac9d16..8571846b0d7 100644 --- a/tests/e2e/support/objects/app-admin-settings/users/actions.ts +++ b/tests/e2e/support/objects/app-admin-settings/users/actions.ts @@ -429,5 +429,5 @@ export const waitForEditPanelToBeVisible = async (args: { page: Page }): Promise const getGroupId = (group: string): string => { const usersEnvironment = new UsersEnvironment() - return usersEnvironment.getGroup({ key: group }).uuid + return usersEnvironment.getCreatedGroup({ key: group }).uuid } diff --git a/tests/e2e/support/store/index.ts b/tests/e2e/support/store/index.ts index bcb029f0883..bef99b9b139 100644 --- a/tests/e2e/support/store/index.ts +++ b/tests/e2e/support/store/index.ts @@ -1,6 +1,6 @@ export { actorStore } from './actor' export { createdLinkStore } from './link' export { createdSpaceStore } from './space' -export { dummyUserStore } from './user' -export { dummyGroupStore } from './group' +export { dummyUserStore, createdUserStore } from './user' +export { dummyGroupStore, createdGroupStore } from './group' export { userRoleStore } from './role'