Skip to content

Commit

Permalink
chore: cypress login issue v42 (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoakimSM authored Apr 29, 2024
1 parent 1041107 commit 794e903
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cypress/e2e/SmokeTests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Feature: Smoke tests
Given you open the App without auth cookie
Then you should see the login prompt

@skip-login
# login form is not working for v42 currently
@skip-login @v<42
Scenario: Show app main selections and header bar: without auth cookie
Given you open the App without auth cookie
When you fill in credentials
Expand Down
33 changes: 33 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,36 @@ Cypress.Commands.add('forceVisit', (url) => {
cy.visit(url);
cy.window().then((win) => { win.location.href = url; });
});

// overrides loginByApi from @dhis2/cypress-commands
// temporary solution: should use solution from @dhis2/cypres-commands when available
Cypress.Commands.add('loginByApi', ({ username, password, baseUrl }) => {
const currentInstanceVersion = Number(/[.](\d+)/.exec(Cypress.env('dhis2InstanceVersion'))[1]);

if (currentInstanceVersion >= 42) {
cy.request({
url: `${baseUrl}/api/auth/login`,
method: 'POST',
followRedirect: true,
body: {
username,
password,
},
});
} else {
cy.request({
url: `${baseUrl}/dhis-web-commons-security/login.action`,
method: 'POST',
form: true,
followRedirect: true,
body: {
j_username: username,
j_password: password,
'2fa_code': '',
},
});
}

// Set base url for the app platform
window.localStorage.setItem('DHIS2_BASE_URL', baseUrl);
});

0 comments on commit 794e903

Please sign in to comment.