From 1a6ea45bd744b6e8e4ae1b57feee3f8802c72600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 25 Jun 2023 11:51:42 +0200 Subject: [PATCH] ci(cypress): Use more cy.request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- cypress/support/commands.js | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 66aa756d883..9d1276d7edd 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -44,15 +44,20 @@ Cypress.Commands.overwrite('login', (login, user) => { }) Cypress.Commands.add('ocsRequest', (options) => { - return cy.request({ - form: true, - auth, - headers: { - 'OCS-ApiRequest': 'true', - 'Content-Type': 'application/x-www-form-urlencoded', - }, - ...options, - }) + return cy.request('/csrftoken') + .then(({ body }) => body.token) + .then(requesttoken => { + return cy.request({ + form: true, + auth, + headers: { + 'OCS-ApiRequest': 'true', + 'Content-Type': 'application/x-www-form-urlencoded', + requesttoken, + }, + ...options, + }) + }) }) Cypress.Commands.add('uploadFile', (fileName, mimeType, target) => { @@ -103,26 +108,27 @@ Cypress.Commands.add('downloadFile', (fileName) => { }) Cypress.Commands.add('createFile', (target, content, mimeType = 'text/markdown') => { - const fileName = target.split('/').pop() - const blob = new Blob([content], { type: mimeType }) - const file = new File([blob], fileName, { type: mimeType }) - return cy.window() - .then(async win => { - const response = await axios.put(`${url}/remote.php/webdav/${target}`, file, { + return cy.request('/csrftoken') + .then(({ body }) => body.token) + .then(requesttoken => { + return cy.request({ + url: `${url}/remote.php/webdav/${target}`, + method: 'put', + body: blob.size > 0 ? blob : '', + auth, headers: { - requesttoken: win.OC.requestToken, 'Content-Type': mimeType, + requesttoken, }, + }).then((response) => { + return cy.log(`Uploaded ${target}`, response.status) }) - - return cy.log(`Uploaded ${fileName}`, response.status) }) }) Cypress.Commands.add('shareFileToUser', (path, targetUser, shareData = {}) => { - cy.clearCookies() cy.ocsRequest({ method: 'POST', url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/shares`,