Skip to content
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

Merged
merged 1 commit into from
May 1, 2023

Conversation

Mohammer5
Copy link
Contributor

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's upgrade_cypress_to_v12 branch, it then ran capturing & stubbing successfully consistently.

Copy link
Contributor

@ismay ismay left a 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)
                })
            },
        }
    )

See: https://github.com/dhis2/scheduler-app/blob/fd8b877fbb735605495603557127f44397e3ef49/cypress/support/e2e.js

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>
@Mohammer5
Copy link
Contributor Author

I've implemented your suggestions but created commands for those particular tasks (logging in by api and validating a user session)

@Mohammer5 Mohammer5 requested a review from ismay May 1, 2023 11:40
@@ -0,0 +1,6 @@
Cypress.Commands.add('validateUserIsLoggedIn', ({ baseUrl, username }) => {
Copy link
Contributor

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.

@Mohammer5 Mohammer5 merged commit 8b22e7b into master May 1, 2023
@Mohammer5 Mohammer5 deleted the fix_auto_login branch May 1, 2023 13:59
dhis2-bot added a commit that referenced this pull request May 1, 2023
## [10.0.1](v10.0.0...v10.0.1) (2023-05-01)

### Bug Fixes

* **auto login:** use api to login ([#394](#394)) ([8b22e7b](8b22e7b))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 10.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants