Skip to content

Commit

Permalink
store invitation code
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Oct 17, 2024
1 parent eb23a98 commit 5df9f2d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 27 deletions.
11 changes: 6 additions & 5 deletions tests/e2e/cucumber/features/ocm/ocm.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: federation management

Scenario: user create federated share
Given using "LOCAL" server
Given "Admin" creates following user using API
And "Admin" creates following user using API
| id |
| Alice |
And "Alice" creates the following files into personal space using API
Expand All @@ -19,11 +19,12 @@ Feature: federation management
| Brian |
And "Brian" logs in
And "Brian" opens the "open-cloud-mesh" app
When "Brian" accept federation share invitation
When "Brian" accepts federated share invitation by "Alice"
# Then "Brian" should see the following federated connections:
# | connections |
# | user | email | institution |
# | Alice | [email protected] | ocis:9200 |
# And "Alice" shares the following resource using the sidebar panel
# | resource | recipient | type | role | resourceType | share-type |
# | test.odt | Carol | user | Can view | file | external |
# | resource | recipient | type | role | resourceType | userType |
# | test.odt | Brian | user | Can view | file | external |
And "Brian" logs out

12 changes: 7 additions & 5 deletions tests/e2e/cucumber/steps/ui/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { objects } from '../../../support'

Given(
'{string} generates the federation share invitation token',
async function (this: World, stepUser: any): Promise<void> {
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.scienceMesh.Federation({ page })
await pageObject.generateInvitation()
const user = await this.usersEnvironment.getUser({ key: stepUser })
await pageObject.generateInvitation(user.id)
}
)

When(
'{string} accept federation share invitation',
async function (this: World, stepUser: any): Promise<void> {
'{string} accepts federated share invitation by {string}',
async function (this: World, stepUser: string, sharee: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.scienceMesh.Federation({ page })
await pageObject.generateInvitation()
const user = this.usersEnvironment.getUser({ key: sharee })
await pageObject.acceptInvitation(user.id)
}
)

Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/cucumber/steps/ui/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const parseShareTable = function (
usersEnvironment: environment.UsersEnvironment
) {
return stepTable.hashes().reduce<Record<string, ICollaborator[]>>((acc, stepRow) => {
const { resource, recipient, type, role, resourceType, expirationDate } = stepRow
const { resource, recipient, type, role, resourceType, expirationDate, userType } = stepRow

if (!acc[resource]) {
acc[resource] = []
Expand All @@ -27,7 +27,8 @@ const parseShareTable = function (
role,
type: type as CollaboratorType,
resourceType,
expirationDate
expirationDate,
userType
})

return acc
Expand Down
68 changes: 57 additions & 11 deletions tests/e2e/support/objects/federation/actions.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,73 @@
import { expect, Page } from '@playwright/test'
import { federatedInvitationCode } from '../../store'

const generateInvitationButton =
'//button[contains(@aria-label,"Generate invitation link that can be shared with one or more invitees")]'
const descriptionInput = '#invite_token_description'
const emailInput = '#invite_token_recipient'
const generateInvitationActionConfirmButton = '.oc-modal-body-actions-confirm'
const emptyInvitationToken = '#invite-tokens-empty'
const acceptFederatedInvitation = '//input[starts-with(@id, "oc-textinput-")]'
const institutionOptionDropdown = '.vs__open-indicator'

export const generateInvitation = async (args: { page: Page }): Promise<void> => {
const { page } = args
export const generateInvitation = async (args: { page: Page; user: string }): Promise<void> => {
const { page, user } = args
await page.locator(generateInvitationButton).click()
await page.locator(descriptionInput).fill('hello')
await page.locator(emailInput).fill('[email protected]')
await page.locator(generateInvitationActionConfirmButton).click()
let inviteCode = ''
await Promise.all([
page.waitForResponse(async (resp) => {
if (
resp.url().endsWith('generate-invite') &&
resp.status() === 200 &&
resp.request().method() === 'POST'
) {
const responseBody = await resp.json()
inviteCode = responseBody.token
return true
}
return false
}),
page.locator(generateInvitationActionConfirmButton).click()
])
await expect(page.locator(emptyInvitationToken)).not.toBeVisible()
federatedInvitationCode.set(user, { code: inviteCode })
console.log(federatedInvitationCode)
}

export const acceptInvitation = async (args: { page: Page }): Promise<void> => {
const { page } = args
// todo: store federation invitation token and use that token
// await page.locator(generateInvitationButton).click()
// await page.locator(descriptionInput).fill('hello')
// await page.locator(emailInput).fill('[email protected]')
// await page.locator(generateInvitationActionConfirmButton).click()
// await expect(page.locator(emptyInvitationToken)).not.toBeVisible()
export const acceptInvitation = async (args: { page: Page; user: string }): Promise<Response> => {
const { page, user } = args
const invitation = federatedInvitationCode.get(user)
await page.locator(acceptFederatedInvitation).fill(invitation.code)
await page.locator(institutionOptionDropdown).click()
await page.getByRole('option', { name: 'first-ocis-instance ocis-server:' }).click()
await Promise.all([
page.waitForResponse(
(resp) =>
resp.url().endsWith('accept-invite') &&
resp.status() === 200 &&
resp.request().method() === 'POST'
),
// async (resp) => {
// if (
// resp.url().endsWith('find-accepted-users') &&
// resp.status() === 200 &&
// resp.request().method() === 'GET'
// ) {
// // Extract and store the API response value
// return await resp.json()
// }
// return false
// },
page.locator('button:has(span:has-text("Accept invitation"))').click()
])
}

// export const isConnectionVisible = async (args: {
// page: Page
// connectionInfo: Response
// }): Promise<void> => {
// const { page, connectionInfo } = args
// }
// first-ocis-instance ocis-server:9200
9 changes: 5 additions & 4 deletions tests/e2e/support/objects/federation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export class Federation {
constructor({ page }: { page: Page }) {
this.#page = page
}
async generateInvitation(): Promise<void> {
await po.generateInvitation({ page: this.#page })
async generateInvitation(user): Promise<void> {
await po.generateInvitation({ page: this.#page, user })
}

async acceptInvitation(): Promise<void> {
await po.acceptInvitation({ page: this.#page })
async acceptInvitation(user): Promise<void> {
await po.acceptInvitation({ page: this.#page, user })
// await po.isConnectionVisible({ page: this.#page, connectionInfo })
}
}
1 change: 1 addition & 0 deletions tests/e2e/support/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { dummyUserStore, createdUserStore } from './user'
export { dummyGroupStore, createdGroupStore } from './group'
export { userRoleStore } from './role'
export { keycloakRealmRoles, keycloakCreatedUser } from './keycloak'
export { federatedInvitationCode } from './invitation'
3 changes: 3 additions & 0 deletions tests/e2e/support/store/invitation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FederatedShareInvitation } from '../types'

export const federatedInvitationCode = new Map<string, FederatedShareInvitation>()
5 changes: 5 additions & 0 deletions tests/e2e/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ export interface AppRole {
displayName: string
id: string
}

export interface FederatedShareInvitation {
code: string
description?: string
}

0 comments on commit 5df9f2d

Please sign in to comment.