added intercept for error 500

master
helenanull 4 years ago
parent 95be0423df
commit 00912cbec5

@ -0,0 +1,7 @@
{
"errors": {
"Error 500 -": [
"Internal server error"
]
}
}

@ -1,24 +1,56 @@
import login from '../selectors/login.sel' import login from '../selectors/login.sel'
import header from '../selectors/header.sel'
describe('Login', () => { describe('Login', () => {
beforeEach(() => { // context is the same as describe
// visit ('/login') -> will visit baseUrl + /login context('unsuccessful', () => {
// baseUrl is set in config - cypress.json file beforeEach(() => {
cy.visit('/login') // visit ('/login') -> will visit baseUrl + /login
}) // baseUrl is set in config - cypress.json file
cy.visit('/login')
})
it('can see error message when username/password incorrect', () => {
cy.get(login.emailField).type('random@test.com')
cy.get(login.passwordField).type('random_pass')
cy.get(login.signInButton).should('have.text', 'Sign in').click()
cy.get(login.errorMessages).should('be.visible')
.and('contain', 'email or password is invalid')
})
it('can see error message when username/password incorrect', () => { it('can see error message when username and password fields are empty', () => {
cy.get(login.emailField).type('random@test.com') cy.get(login.signInButton).click()
cy.get(login.passwordField).type('random_pass') cy.get(login.errorMessages).should('be.visible')
cy.get(login.signInButton).should('have.text', 'Sign in').click() .and('contain', 'email or password is invalid')
cy.get(login.errorMessages).should('be.visible') })
.and('contain', 'email or password is invalid')
it('can see error message when API responds with 500', () => {
cy.intercept('POST', 'https://conduit.productionready.io/api/users/login', {
method: 'POST',
statusCode: 500,
fixture: 'login_error'
})
cy.get(login.emailField).type('random2@test.com')
cy.get(login.passwordField).type('random_pass{enter}')
cy.get(login.errorMessages).should('be.visible')
.and('contain', 'Error 500 - Internal server error')
})
}) })
it('can press enter to log in', () => { context('successful', () => {
cy.get(login.emailField).type('random2@test.com') beforeEach(() => {
cy.get(login.passwordField).type('random_pass{enter}') // we need a new user
cy.get(login.errorMessages).should('be.visible') cy.register().then((email) => {
.and('contain', 'email or password is invalid') cy.wrap(email).as('email')
})
cy.visit('/login')
})
it('can log in', function () {
cy.get(login.emailField).type(this.email)
cy.get(login.passwordField).type('Testtest1')
cy.get(login.signInButton).click()
cy.get(header.settingsLink).should('be.visible')
})
}) })
}) })

Loading…
Cancel
Save