2020-12-30 00:30:32 +00:00
|
|
|
context('Authentication', () => {
|
2020-12-30 19:28:39 +00:00
|
|
|
function submitLoginForm () {
|
2020-12-30 00:30:32 +00: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 22:37:22 +00:00
|
|
|
fixture: 'data.get.200.json'
|
2020-12-30 00:30:32 +00:00
|
|
|
})
|
|
|
|
|
2020-12-30 10:11:59 +00:00
|
|
|
cy.visit('/')
|
2020-12-30 00:30:32 +00: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 10:11:59 +00:00
|
|
|
cy.visit('/')
|
2020-12-30 00:30:32 +00:00
|
|
|
submitLoginForm()
|
2022-04-26 12:54:03 +00:00
|
|
|
cy.findByTestId('login-form').should('be.visible').and('have.class', 'error')
|
2020-12-30 00:30:32 +00:00
|
|
|
})
|
2020-12-30 10:11:59 +00:00
|
|
|
|
|
|
|
it('logs out', () => {
|
|
|
|
cy.intercept('DELETE', '/api/me', {})
|
2020-12-30 18:44:47 +00:00
|
|
|
cy.$login()
|
2020-12-30 10:11:59 +00:00
|
|
|
cy.findByTestId('btn-logout').click()
|
|
|
|
cy.findByTestId('login-form').should('be.visible')
|
|
|
|
})
|
2020-12-30 00:30:32 +00:00
|
|
|
})
|