test login error contract

This commit is contained in:
Yisroel Baum 2026-08-02 21:01:01 +03:00
parent 299efe0839
commit d52a8bf3b5
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -80,10 +80,10 @@ describe('password 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', {
statusCode: 401,
body: { error: 'invalid_credentials' },
body: { error: 'invalid credentials' },
}).as('login')
cy.visit('/login')
@ -92,20 +92,15 @@ describe('password login', () => {
cy.wait('@login')
cy.get('[role="alert"]')
.should('have.text', 'Email or password is incorrect.')
.should('have.text', 'invalid credentials')
.and('be.visible')
cy.location('pathname').should('equal', '/login')
})
it('shows backend field validation errors', () => {
it('shows backend request errors', () => {
cy.intercept('POST', '**/api/login', {
statusCode: 422,
body: {
message: 'The email field must be a valid email address.',
errors: {
email: ['The email field must be a valid email address.'],
},
},
statusCode: 400,
body: { error: 'email is required' },
}).as('login')
cy.visit('/login')
@ -113,34 +108,20 @@ describe('password login', () => {
cy.get('form').submit()
cy.wait('@login')
cy.get('#login-email-error')
.should(
'have.text',
'The email field must be a valid email address.',
)
cy.get('[role="alert"]')
.should('have.text', 'email is required')
.and('be.visible')
cy.get('#login-email-error').should('not.exist')
})
it('shows throttling and malformed-response errors', () => {
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.',
)
it('shows a malformed-response error', () => {
cy.intercept('POST', '**/api/login', {
statusCode: 200,
body: { user: { id: 7 } },
}).as('malformedLogin')
cy.visit('/login')
fillLoginForm()
cy.get('form').submit()
cy.wait('@malformedLogin')
cy.get('[role="alert"]').should(