Skip to content

Commit

Permalink
[tests-only] e2eTest. Api step. create folder in personal space (#8176)
Browse files Browse the repository at this point in the history
* create folder in personal space
  • Loading branch information
ScharfViktor authored Jan 4, 2023
1 parent a4e9e53 commit 207fa58
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 18 deletions.
7 changes: 3 additions & 4 deletions tests/e2e/cucumber/features/smoke/reshare.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ Feature: reshare
And "Admin" adds user to the group
| user | group |
| Carol | sales |
And "Alice" creates the following folder in personal space using API
| name |
| folder_to_shared |

And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" navigates to the personal space page
And "Alice" creates the following resources
| resource | type |
| folder_to_shared | folder |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/cucumber/steps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ Given(
}
}
)

Given(
'{string} creates the following folder(s) in personal space using API',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const user = this.usersEnvironment.getUser({ key: stepUser })
for (const info of stepTable.hashes()) {
await api.dav.createFolder({ user, folder: info.name })
}
}
)
1 change: 1 addition & 0 deletions tests/e2e/support/api/davSpaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createFolder } from './spaces'
39 changes: 39 additions & 0 deletions tests/e2e/support/api/davSpaces/spaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { checkResponseStatus, request } from '../http'
import { User } from '../../types'
import join from 'join-path'
import { getPersonalSpaceId } from '../graph'
import { config } from '../../../config'

export const createFolder = async ({
user,
folder
}: {
user: User
folder: string
}): Promise<void> => {
const paths = folder.split('/')

let subFolder = ''
for (const resource of paths) {
const oc10Path = join('remote.php', 'dav', 'files', user.id, subFolder, resource)

const response = await request({
method: 'MKCOL',
path: config.ocis
? join(
'remote.php',
'dav',
'spaces',
await getPersonalSpaceId({ user }),
subFolder,
resource
)
: oc10Path,
user: user,
formatJson: false
})

checkResponseStatus(response, 'Failed while creating folder')
subFolder += resource
}
}
1 change: 1 addition & 0 deletions tests/e2e/support/api/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export {
deleteGroup,
addUserToGroup
} from './userManagement'
export { getPersonalSpaceId } from './spaces'
17 changes: 17 additions & 0 deletions tests/e2e/support/api/graph/spaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { checkResponseStatus, request } from '../http'
import { User } from '../../types'
import join from 'join-path'

export const getPersonalSpaceId = async ({ user }: { user: User }): Promise<string> => {
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'me', 'drives', "?$filter=driveType eq 'personal'"),
user: user,
formatJson: false
})

checkResponseStatus(response, 'Failed while geting personal space')

const result = await response.json()
return result.value[0].id
}
29 changes: 15 additions & 14 deletions tests/e2e/support/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ export const request = async ({
method,
path,
body,
user
user,
formatJson = true
}: {
method: 'POST' | 'DELETE' | 'PUT' | 'GET'
method: 'POST' | 'DELETE' | 'PUT' | 'GET' | 'MKCOL'
path: string
body?: BodyInit
user?: User
formatJson?: boolean
}): Promise<Response> => {
return await fetch(
join(config.backendUrl, path + (path.includes('?') ? '&' : '?') + 'format=json'),
{
method,
body,
headers: {
'OCS-APIREQUEST': true as any,
...(user && {
Authorization: 'Basic ' + Buffer.from(user.id + ':' + user.password).toString('base64')
})
}
const format = config.ocis || !formatJson ? '' : 'format=json'

return await fetch(join(config.backendUrl, path + (path.includes('?') ? '&' : '?') + format), {
method,
body,
headers: {
'OCS-APIREQUEST': true as any,
...(user && {
Authorization: 'Basic ' + Buffer.from(user.id + ':' + user.password).toString('base64')
})
}
)
})
}

export const checkResponseStatus = (response: Response, message = ''): void => {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/support/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as user from './userManagement'
export * as config from './config'
export * as settings from './settings'
export * as graph from './graph'
export * as dav from './davSpaces'

0 comments on commit 207fa58

Please sign in to comment.