nextcloud/cypress/e2e/files_external/StorageUtils.ts
Ferdinand Thiessen 1082dee5a4
chore: migrate Cypress to @nextcloud/e2e-test-server
- chore: use vite preprocessor for Cypress

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-10-22 11:57:17 +02:00

74 lines
2 KiB
TypeScript

/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { User } from '@nextcloud/e2e-test-server/cypress'
export type StorageConfig = {
[key: string]: string
}
export type StorageMountOption = {
readonly: boolean
}
export enum StorageBackend {
DAV = 'dav',
SMB = 'smb',
SFTP = 'sftp',
LOCAL = 'local',
}
export enum AuthBackend {
GlobalAuth = 'password::global',
LoginCredentials = 'password::logincredentials',
Password = 'password::password',
SessionCredentials = 'password::sessioncredentials',
UserGlobalAuth = 'password::global::user',
UserProvided = 'password::userprovided',
Null = 'null::null',
}
/**
* Create a storage via occ
*
* @param mountPoint
* @param storageBackend
* @param authBackend
* @param configs
* @param user
*/
export function createStorageWithConfig(mountPoint: string, storageBackend: StorageBackend, authBackend: AuthBackend, configs: StorageConfig, user?: User): Cypress.Chainable {
const configsFlag = Object.keys(configs).map((key) => `--config "${key}=${configs[key]}"`).join(' ')
const userFlag = user ? `--user ${user.userId}` : ''
const command = `files_external:create "${mountPoint}" "${storageBackend}" "${authBackend}" ${configsFlag} ${userFlag}`
cy.log(`Creating storage with command: ${command}`)
return cy.runOccCommand(command)
.then(({ stdout }) => {
return stdout.replace('Storage created with id ', '')
})
}
/**
*
* @param mountId
* @param options
*/
export function setStorageMountOptions(mountId: string, options: StorageMountOption) {
for (const [key, value] of Object.entries(options)) {
cy.runOccCommand(`files_external:option ${mountId} ${key} ${value}`)
}
}
/**
*
*/
export function deleteAllExternalStorages() {
cy.runOccCommand('files_external:list --all --output=json').then(({ stdout }) => {
const list = JSON.parse(stdout)
list.forEach((storage) => cy.runOccCommand(`files_external:delete --yes ${storage.mount_id}`), { failOnNonZeroExit: false })
})
}