Skip to content

Commit

Permalink
test: use local login helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Oct 14, 2024
1 parent 9c83e47 commit 506730e
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
import { enableAutoLogin } from '@dhis2/cypress-commands'
/* global Cypress */

enableAutoLogin()
/**
* Custom login command, can be used to login or switch between sessions.
* Will cache and restore cookies, localStorage, and sessionStorage. See:
* https://docs.cypress.io/api/commands/session
*/
Cypress.Commands.add('login', (user) => {
cy.session(
user,
() => {
// Login via API
cy.request({
url: `${user.server}/dhis-web-commons-security/login.action`,
method: 'POST',
form: true,
followRedirect: true,
body: {
j_username: user.name,
j_password: user.password,
'2fa_code': '',
},
})

// Set base url for the app platform
window.localStorage.setItem('DHIS2_BASE_URL', user.server)
},
{
validate: () => {
cy.request(`${user.server}/api/me`).then((response) => {
expect(response.status).to.eq(200)
expect(response.body.username).to.eq(user.name)
})
},
}
)
})

// Log in before each test, if not already logged in
beforeEach(() => {
cy.login({
name: Cypress.env('LOGIN_NAME'),
password: Cypress.env('LOGIN_PASSWORD'),
server: Cypress.env('LOGIN_SERVER'),
})
})

0 comments on commit 506730e

Please sign in to comment.