koel/cypress/integration/authentication.spec.ts

41 lines
943 B
TypeScript
Raw Normal View History

2020-12-30 00:30:32 +00:00
context('Authentication', () => {
const submitLoginForm = () => {
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', {
fixture: 'data.json'
})
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
})
cy.visit('/')
2020-12-30 00:30:32 +00:00
submitLoginForm()
cy.findByTestId('login-form')
.should('be.visible')
.and('have.class', 'error')
})
it('logs out', () => {
cy.intercept('DELETE', '/api/me', {})
2020-12-30 18:44:47 +00:00
cy.$login()
cy.findByTestId('btn-logout').click()
cy.findByTestId('login-form').should('be.visible')
})
2020-12-30 00:30:32 +00:00
})