diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-11-16 02:39:40 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-11-16 14:25:43 +0100 |
commit | 205801adc6911e0fe368f6cc3a10a559c6aa0ebf (patch) | |
tree | b6b541c844b8fdeca7dab61ca1543d48a23cc7df /cypress/support/commands.ts | |
parent | e250a561701ce010188a3c3a84b522dc51aed878 (diff) | |
download | nextcloud-server-205801adc6911e0fe368f6cc3a10a559c6aa0ebf.tar.gz nextcloud-server-205801adc6911e0fe368f6cc3a10a559c6aa0ebf.zip |
fix(files): Add cypress e2e tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'cypress/support/commands.ts')
-rw-r--r-- | cypress/support/commands.ts | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index b2ec7f1e745..477a366a421 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -49,7 +49,18 @@ declare global { * 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): Cypress.Chainable<void>, + uploadContent(user: User, content: Blob, mimeType: string, target: string, mtime?: number): Cypress.Chainable<void>, + + /** + * 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. @@ -121,6 +132,63 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima }) }) +Cypress.Commands.add('setFileAsFavorite', (user: User, target: string, favorite = true) => { + // eslint-disable-next-line cypress/unsafe-to-chain-command + cy.clearAllCookies() + .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: 'PROPPATCH', + auth: { + username: user.userId, + password: user.password, + }, + headers: { + 'Content-Type': 'application/xml', + }, + data: `<?xml version="1.0"?> + <d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"> + <d:set> + <d:prop> + <oc:favorite>${favorite ? 1 : 0}</oc:favorite> + </d:prop> + </d:set> + </d:propertyupdate>` + }) + cy.log(`Created directory ${target}`, response) + } catch (error) { + cy.log('error', error) + throw new Error('Unable to process fixture') + } + }) +}) + +Cypress.Commands.add('mkdir', (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: 'MKCOL', + auth: { + username: user.userId, + password: user.password, + }, + }) + cy.log(`Created directory ${target}`, response) + } catch (error) { + cy.log('error', error) + throw new Error('Unable to process fixture') + } + }) +}) + /** * cy.uploadedContent - uploads a raw content * TODO: standardise in @nextcloud/cypress @@ -130,7 +198,7 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima * @param {string} mimeType e.g. image/png * @param {string} target the target of the file relative to the user root */ -Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => { +Cypress.Commands.add('uploadContent', (user, blob, mimeType, target, mtime = undefined) => { // eslint-disable-next-line cypress/unsafe-to-chain-command cy.clearCookies() .then(async () => { @@ -147,6 +215,7 @@ Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => { data: file, headers: { 'Content-Type': mimeType, + 'X-OC-MTime': mtime ? `${mtime}` : undefined, }, auth: { username: user.userId, |