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

[tests-only][full-ci] Backport users and groups teardown test codes #9011

Merged
merged 4 commits into from
May 11, 2023
Merged
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
36 changes: 35 additions & 1 deletion tests/e2e/cucumber/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
})
Expand All @@ -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) => {
Expand All @@ -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()
}
4 changes: 0 additions & 4 deletions tests/e2e/cucumber/steps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
Expand Down Expand Up @@ -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 })
}
}
Expand Down
34 changes: 2 additions & 32 deletions tests/e2e/cucumber/steps/ui/adminSettings.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 })
}
}
)
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/cucumber/steps/ui/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ async function createNewSession(world: World, stepUser: string) {
async function LogInUser(this: World, stepUser: string): Promise<void> {
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')
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/support/api/graph/userManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -109,7 +109,9 @@ export const deleteGroup = async ({
group: Group
admin: User
}): Promise<Group> => {
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),
Expand Down
28 changes: 17 additions & 11 deletions tests/e2e/support/environment/userManagement.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
export const createGroup = async (args: { page: Page; key: string }): Promise<Response> => {
const { page, key } = args
await page.locator(newGroupBtn).click()
await page.locator(createGroupInput).fill(key)
Expand All @@ -30,8 +30,8 @@ export const createGroup = async (args: { page: Page; key: string }): Promise<st
),
page.locator(actionConfirmButton).click()
])
const group = await response.json()
return group.id

return await response.json()
}

export const getDisplayedGroups = async (args: { page: Page }): Promise<string[]> => {
Expand Down
20 changes: 17 additions & 3 deletions tests/e2e/support/objects/app-admin-settings/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
return await createGroup({ page: this.#page, key: key })

async createGroup({ key }: { key: string }): Promise<void> {
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<string[]> {
return getDisplayedGroups({ page: this.#page })
}

async selectGroup({ key }: { key: string }): Promise<void> {
await selectGroup({ page: this.#page, uuid: this.getUUID({ key }) })
}

async deleteGroupUsingBatchAction({ groupIds }: { groupIds: string[] }): Promise<void> {
await deleteGrouprUsingBatchAction({ page: this.#page, groupIds })
}

async deleteGroupUsingContextMenu({ key }: { key: string }): Promise<void> {
await deleteGroupUsingContextMenu({ page: this.#page, uuid: this.getUUID({ key }) })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions tests/e2e/support/store/index.ts
Original file line number Diff line number Diff line change
@@ -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'