test: Add Cypress command for deleting files

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-01-31 00:00:30 +01:00
parent d600791805
commit 8fd6d8025f
No known key found for this signature in database
GPG key ID: 45FAE7268762B400
2 changed files with 28 additions and 0 deletions

View file

@ -119,6 +119,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: standardize in @nextcloud/cypress

View file

@ -29,6 +29,11 @@ declare global {
*/
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