Skip to content

Commit

Permalink
test(e2e): improve stability for login tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent c82d68d commit 43df22b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
24 changes: 14 additions & 10 deletions test/e2e/cypress/integration/profiles/email/login/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ describe('Basic email profile with failing login flows', () => {
})

it('fails when CSRF cookies are missing', () => {
cy.clearCookies()
cy.get('input[name="password_identifier"]').type('i-do-not-exist')
cy.get('input[name="password"]').type('invalid-password')

let initial
cy.location().should((location) => {
initial = location.search
})
cy.get('button[type="submit"]').click()

cy.clearAllCookies()
cy.submitPasswordForm()

// We end up at a new flow
cy.location('search').should('not.eq', initial)
if (app === 'express') {
cy.location().should((location) => {
expect(initial).to.not.be.empty
expect(location.search).to.not.eq(initial)
})

cy.location('pathname').should('include', '/error')
cy.get('code').should('contain.text', 'csrf_token')
} else {
Expand All @@ -63,8 +68,8 @@ describe('Basic email profile with failing login flows', () => {
})

it('should show an error when the identifier is missing', () => {
cy.get('button[type="submit"]').click()
cy.get('*[data-testid="ui.node.message.4000001"]').should(
cy.submitPasswordForm()
cy.get('*[data-testid="ui/message/4000001"]').should(
'contain.text',
'length must be >= 1, but got 0'
)
Expand All @@ -76,9 +81,8 @@ describe('Basic email profile with failing login flows', () => {
.type(identity)
.should('have.value', identity)

cy.get('button[type="submit"]').click()

cy.get('*[data-testid^="ui.node.message."]').invoke('text').then((text) => {
cy.submitPasswordForm()
cy.get('*[data-testid^="ui/message/"]').invoke('text').then((text) => {
expect(text).to.be.oneOf(['length must be >= 1, but got 0', 'Property password is missing.'])
})
})
Expand All @@ -87,8 +91,8 @@ describe('Basic email profile with failing login flows', () => {
cy.get('input[name="password_identifier"]').type('i-do-not-exist')
cy.get('input[name="password"]').type('invalid-password')

cy.get('button[type="submit"]').click()
cy.get('*[data-testid="ui.node.message.4000006"]').should(
cy.submitPasswordForm()
cy.get('*[data-testid="ui/message/4000006"]').should(
'contain.text',
'credentials are invalid'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Basic email profile with succeeding login flows', () => {
it('should sign in and be logged in', () => {
cy.get('input[name="password_identifier"]').type(email)
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

cy.getSession().should((session) => {
const {identity} = session
Expand All @@ -42,7 +42,7 @@ describe('Basic email profile with succeeding login flows', () => {
it('should sign in with case insensitive identifier', () => {
cy.get('input[name="password_identifier"]').type(email.toUpperCase())
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

cy.getSession().should((session) => {
const {identity} = session
Expand All @@ -62,7 +62,7 @@ describe('Basic email profile with succeeding login flows', () => {

cy.get('input[name="password_identifier"]').type(email.toUpperCase())
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

cy.url().should('eq', 'https://www.ory.sh/')
})
Expand All @@ -85,7 +85,7 @@ describe('Basic email profile with succeeding login flows', () => {
cy.get('input[name="password"]').type(password)

cy.longLoginLifespan()
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()
cy.get('.messages .message').should(
'contain.text',
'The login flow expired'
Expand All @@ -94,7 +94,7 @@ describe('Basic email profile with succeeding login flows', () => {
// try again with long lifespan set
cy.get('input[name="password_identifier"]').type(email.toUpperCase())
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

// check that redirection has happened
cy.url().should('eq', 'https://www.ory.sh/')
Expand Down

0 comments on commit 43df22b

Please sign in to comment.