Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: Add Cypress command for deleting files
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 5, 2025
commit 8fd6d8025ffbf1c0b798babc08d79718afdc25db
23 changes: 23 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/cypress-e2e.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down