From 05fe2b5b212e59a1b78bdbeb654c9af07954a002 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 26 Feb 2025 12:37:57 +0100 Subject: [PATCH] refactor: refs #8484 streamline login command and remove commented code --- test/cypress/support/commands.js | 56 ++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 9896e322e..83a4fbbde 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -35,33 +35,53 @@ Cypress.Commands.add('resetDB', () => { }); Cypress.Commands.add('login', (user = 'developer') => { - cy.session(['user-session', user], () => { + //cy.visit('/#/login'); + cy.request({ + method: 'POST', + url: '/api/accounts/login', + body: { + user: user, + password: 'nightmare', + }, + }).then((response) => { + window.localStorage.setItem('token', response.body.token); cy.request({ - method: 'POST', - url: '/api/accounts/login', - body: { - user: user, - password: 'nightmare', + method: 'GET', + url: '/api/VnUsers/ShareToken', + headers: { + Authorization: window.localStorage.getItem('token'), }, - }).then((response) => { - window.localStorage.setItem('token', response.body.token); - cy.request({ - method: 'GET', - url: '/api/VnUsers/ShareToken', - headers: { - Authorization: window.localStorage.getItem('token'), - }, - }).then(({ body }) => { - window.localStorage.setItem('tokenMultimedia', body.multimediaToken.id); - }); + }).then(({ body }) => { + window.localStorage.setItem('tokenMultimedia', body.multimediaToken.id); }); }); + // cy.session(['user-session', user], () => { + // cy.request({ + // method: 'POST', + // url: '/api/accounts/login', + // body: { + // user: user, + // password: 'nightmare', + // }, + // }).then((response) => { + // window.localStorage.setItem('token', response.body.token); + // cy.request({ + // method: 'GET', + // url: '/api/VnUsers/ShareToken', + // headers: { + // Authorization: window.localStorage.getItem('token'), + // }, + // }).then(({ body }) => { + // window.localStorage.setItem('tokenMultimedia', body.multimediaToken.id); + // }); + // }); + // }); }); Cypress.Commands.overwrite('visit', (originalFn, url, options) => { originalFn(url, options); cy.waitUntil(() => cy.document().then((doc) => doc.readyState === 'complete')); - cy.waitUntil(() => cy.get('main', { timeout: 10000 }).should('exist')); + cy.waitUntil(() => cy.get('main').should('exist')); }); Cypress.Commands.add('waitForElement', (element, timeout = 10000) => {