From 30764fddfd5b99ae568e11e6ec99fc7b3565ccf1 Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Fri, 3 Jan 2025 17:39:34 +0100 Subject: [PATCH] ci: Hotfix to make login work as long as we are on older cypress version Signed-off-by: Kostiantyn Miakshyn --- cypress/support/commands.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index b667d6192..6e65676c0 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { login, logout } from '@nextcloud/cypress/commands' +import { logout } from '@nextcloud/cypress/commands' import { User } from '@nextcloud/cypress' import * as api from '../../src/apis/collectives/index.js' @@ -29,6 +29,34 @@ Cypress.on('uncaught:exception', (err) => { } }) +// Copy of the new login command as long as we are blocked to upgrade @nextcloud/cypress by cypress crashes +const login = function(user) { + cy.session(user, function() { + cy.request('/csrftoken').then(({ body }) => { + const requestToken = body.token + cy.request({ + method: 'POST', + url: '/login', + body: { + user: user.userId, + password: user.password, + requesttoken: requestToken, + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + // Add the Origin header so that the request is not blocked by the browser. + Origin: (Cypress.config('baseUrl') ?? '').replace('index.php/', ''), + }, + followRedirect: false, + }) + }) + }, { + validate() { + cy.request('/apps/files').its('status').should('eq', 200) + }, + }) +} + // Authentication commands from @nextcloud/cypress Cypress.Commands.add('login', login) Cypress.Commands.add('logout', logout)