Skip to content

Commit

Permalink
ci(cypress): Use more cy.request
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jun 25, 2023
1 parent f3b9ffe commit 1a6ea45
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit 1a6ea45

Please sign in to comment.