test login error contract
This commit is contained in:
parent
299efe0839
commit
d52a8bf3b5
1 changed files with 12 additions and 31 deletions
|
|
@ -80,10 +80,10 @@ describe('password login', () => {
|
||||||
cy.location('pathname').should('equal', '/login')
|
cy.location('pathname').should('equal', '/login')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows a generic invalid-credentials error', () => {
|
it('shows the backend invalid-credentials error', () => {
|
||||||
cy.intercept('POST', '**/api/login', {
|
cy.intercept('POST', '**/api/login', {
|
||||||
statusCode: 401,
|
statusCode: 401,
|
||||||
body: { error: 'invalid_credentials' },
|
body: { error: 'invalid credentials' },
|
||||||
}).as('login')
|
}).as('login')
|
||||||
|
|
||||||
cy.visit('/login')
|
cy.visit('/login')
|
||||||
|
|
@ -92,20 +92,15 @@ describe('password login', () => {
|
||||||
cy.wait('@login')
|
cy.wait('@login')
|
||||||
|
|
||||||
cy.get('[role="alert"]')
|
cy.get('[role="alert"]')
|
||||||
.should('have.text', 'Email or password is incorrect.')
|
.should('have.text', 'invalid credentials')
|
||||||
.and('be.visible')
|
.and('be.visible')
|
||||||
cy.location('pathname').should('equal', '/login')
|
cy.location('pathname').should('equal', '/login')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows backend field validation errors', () => {
|
it('shows backend request errors', () => {
|
||||||
cy.intercept('POST', '**/api/login', {
|
cy.intercept('POST', '**/api/login', {
|
||||||
statusCode: 422,
|
statusCode: 400,
|
||||||
body: {
|
body: { error: 'email is required' },
|
||||||
message: 'The email field must be a valid email address.',
|
|
||||||
errors: {
|
|
||||||
email: ['The email field must be a valid email address.'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}).as('login')
|
}).as('login')
|
||||||
|
|
||||||
cy.visit('/login')
|
cy.visit('/login')
|
||||||
|
|
@ -113,34 +108,20 @@ describe('password login', () => {
|
||||||
cy.get('form').submit()
|
cy.get('form').submit()
|
||||||
cy.wait('@login')
|
cy.wait('@login')
|
||||||
|
|
||||||
cy.get('#login-email-error')
|
cy.get('[role="alert"]')
|
||||||
.should(
|
.should('have.text', 'email is required')
|
||||||
'have.text',
|
|
||||||
'The email field must be a valid email address.',
|
|
||||||
)
|
|
||||||
.and('be.visible')
|
.and('be.visible')
|
||||||
|
cy.get('#login-email-error').should('not.exist')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows throttling and malformed-response errors', () => {
|
it('shows a malformed-response error', () => {
|
||||||
cy.intercept('POST', '**/api/login', {
|
|
||||||
statusCode: 429,
|
|
||||||
body: { message: 'Too Many Attempts.' },
|
|
||||||
}).as('throttledLogin')
|
|
||||||
|
|
||||||
cy.visit('/login')
|
|
||||||
fillLoginForm()
|
|
||||||
cy.get('form').submit()
|
|
||||||
cy.wait('@throttledLogin')
|
|
||||||
cy.get('[role="alert"]').should(
|
|
||||||
'have.text',
|
|
||||||
'Too many login attempts. Try again in a minute.',
|
|
||||||
)
|
|
||||||
|
|
||||||
cy.intercept('POST', '**/api/login', {
|
cy.intercept('POST', '**/api/login', {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: { user: { id: 7 } },
|
body: { user: { id: 7 } },
|
||||||
}).as('malformedLogin')
|
}).as('malformedLogin')
|
||||||
|
|
||||||
|
cy.visit('/login')
|
||||||
|
fillLoginForm()
|
||||||
cy.get('form').submit()
|
cy.get('form').submit()
|
||||||
cy.wait('@malformedLogin')
|
cy.wait('@malformedLogin')
|
||||||
cy.get('[role="alert"]').should(
|
cy.get('[role="alert"]').should(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue