test: Add Cypress command for deleting files

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/50677/head
Ferdinand Thiessen 2025-01-31 00:00:30 +07:00
parent 6d1211c434
commit 4fd8440493
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
2 changed files with 87 additions and 0 deletions

@ -175,6 +175,29 @@ Cypress.Commands.add('mkdir', (user: User, target: string) => {
})
})
Cypress.Commands.add('rm', (user: User, target: string) => {
// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.clearCookies()
.then(async () => {
try {
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
const filePath = target.split('/').map(encodeURIComponent).join('/')
const response = await axios({
url: `${rootPath}${filePath}`,
method: 'DELETE',
auth: {
username: user.userId,
password: user.password,
},
})
cy.log(`delete file or directory ${target}`, response)
} catch (error) {
cy.log('error', error)
throw new Error('Unable to delete file or directory')
}
})
})
/**
* cy.uploadedContent - uploads a raw content
* TODO: standardise in @nextcloud/cypress

@ -0,0 +1,64 @@
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// eslint-disable-next-line n/no-extraneous-import
import type { AxiosResponse } from 'axios'
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
interface Chainable<Subject = any> {
/**
* Enable or disable a given user
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
enableUser(user: User, enable?: boolean): Cypress.Chainable<Cypress.Response<any>>,
/**
* Upload a file from the fixtures folder to a given user storage.
* **Warning**: Using this function will reset the previous session
*/
uploadFile(user: User, fixture?: string, mimeType?: string, target?: string): Cypress.Chainable<void>,
/**
* Upload a raw content to a given user storage.
* **Warning**: Using this function will reset the previous session
*/
uploadContent(user: User, content: Blob, mimeType: string, target: string, mtime?: number): Cypress.Chainable<AxiosResponse>,
/**
* Delete a file or directory
*/
rm(user: User, target: string): Cypress.Chainable<AxiosResponse>,
/**
* Create a new directory
* **Warning**: Using this function will reset the previous session
*/
mkdir(user: User, target: string): Cypress.Chainable<void>,
/**
* Set a file as favorite (or remove from favorite)
*/
setFileAsFavorite(user: User, target: string, favorite?: boolean): Cypress.Chainable<void>,
/**
* Reset the admin theming entirely.
* **Warning**: Using this function will reset the previous session
*/
resetAdminTheming(): Cypress.Chainable<void>,
/**
* Reset the user theming settings.
* If provided, will clear session and login as the given user.
* **Warning**: Providing a user will reset the previous session.
*/
resetUserTheming(user?: User): Cypress.Chainable<void>,
userFileExists(user: string, path: string): Cypress.Chainable<number>
}
}
}