2020-12-30 01:30:32 +01:00
|
|
|
context('Authentication', () => {
|
2020-12-30 20:28:39 +01:00
|
|
|
function submitLoginForm () {
|
2020-12-30 01:30:32 +01:00
|
|
|
cy.get('[type=email]').type('admin@koel.test')
|
|
|
|
cy.get('[type=password]').type('super-secret')
|
|
|
|
cy.get('[type=submit]').click()
|
|
|
|
}
|
|
|
|
|
|
|
|
it('logs in with valid credentials', () => {
|
|
|
|
cy.intercept('POST', '/api/me', {
|
|
|
|
token: 'mock-token'
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.intercept('/api/data', {
|
2020-12-30 23:37:22 +01:00
|
|
|
fixture: 'data.get.200.json'
|
2020-12-30 01:30:32 +01:00
|
|
|
})
|
|
|
|
|
2020-12-30 11:11:59 +01:00
|
|
|
cy.visit('/')
|
2020-12-30 01:30:32 +01:00
|
|
|
submitLoginForm()
|
|
|
|
cy.get('[id=main]').should('be.visible')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('fails to log in with invalid credentials', () => {
|
|
|
|
cy.intercept('POST', '/api/me', {
|
|
|
|
statusCode: 401
|
|
|
|
})
|
|
|
|
|
2020-12-30 11:11:59 +01:00
|
|
|
cy.visit('/')
|
2020-12-30 01:30:32 +01:00
|
|
|
submitLoginForm()
|
2022-04-26 15:54:03 +03:00
|
|
|
cy.findByTestId('login-form').should('be.visible').and('have.class', 'error')
|
2020-12-30 01:30:32 +01:00
|
|
|
})
|
2020-12-30 11:11:59 +01:00
|
|
|
|
|
|
|
it('logs out', () => {
|
|
|
|
cy.intercept('DELETE', '/api/me', {})
|
2020-12-30 19:44:47 +01:00
|
|
|
cy.$login()
|
2020-12-30 11:11:59 +01:00
|
|
|
cy.findByTestId('btn-logout').click()
|
|
|
|
cy.findByTestId('login-form').should('be.visible')
|
|
|
|
})
|
2020-12-30 01:30:32 +01:00
|
|
|
})
|