-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(auto login): ensure something has rendered in validation fn #394
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using this to login:
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)
})
},
}
)
It's been a little faster for me than using the ui. Plus you're not dependent on rendering or any other FE parts. Would that be a solution you could use here?
Co-authored-by: Ismay <Ismay@users.noreply.github.com>
I've implemented your suggestions but created commands for those particular tasks (logging in by api and validating a user session) |
@@ -0,0 +1,6 @@ | |||
Cypress.Commands.add('validateUserIsLoggedIn', ({ baseUrl, username }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also call this validateSession maybe. Seems a little terser to me.
## [10.0.1](v10.0.0...v10.0.1) (2023-05-01) ### Bug Fixes * **auto login:** use api to login ([#394](#394)) ([8b22e7b](8b22e7b))
🎉 This PR is included in version 10.0.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Sometimes the
.should('not.exist')
check in the validate function was run before the app rendered anything, causing login issues.By adding the change of this PR to the code inside
node_modules
in the aggregate data entry app'supgrade_cypress_to_v12
branch, it then ran capturing & stubbing successfully consistently.