describe('Login tests', function() {
before(function() {
- this.email = `account_${Math.random()}@example.com`
- this.password = Math.random()
- this.firstName = 'Test'
- this.lastName = 'User'
+ cy.resetDB();
})
beforeEach(function() {
- cy.visit('/')
- cy.contains('Please log in')
- cy.get('button').contains('Log in').click()
- cy.url().should('contain', "/users/sign_in")
- })
-
- it('register a new user', function() {
- cy.get('a[role=button]').contains('Sign up for a new account').click()
- cy.url().should('contain', '/users/sign_up')
- cy.get('input[name="user[first_name]"]').type(this.firstName)
- cy.get('input[name="user[last_name]"]').type(this.lastName)
- cy.get('input[name="user[email]"]').type(this.email)
- cy.get('input[name="user[password]"]').type(this.password)
- cy.get('input[name="user[password_confirmation]"]').type(this.password)
- cy.get('input[type=submit]').contains('Sign up').click()
- cy.url().should('contain', '/projects/')
- cy.get('button[title="Account Management"]').click()
- cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`)
+ cy.arvadosFixture('users').as('users')
+ cy.arvadosFixture('api_client_authorizations').as('client_auth')
+ cy.clearCookies()
+ cy.clearLocalStorage()
})
it('logs in successfully', function() {
- cy.get('input[type=email]').type(this.email)
- cy.get('input[type=password]').type(this.password)
- cy.get('input[type=submit]').contains('Sign in').click()
+ const active_user = this.users['active']
+ const active_token = this.client_auth['active']['api_token']
+ cy.visit('/token/?api_token='+active_token)
cy.url().should('contain', '/projects/')
cy.get('button[title="Account Management"]').click()
- cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`)
+ cy.get('ul[role=menu] > li[role=menuitem]').contains(`${active_user['first_name']} ${active_user['last_name']}`)
})
- it('fails to log in with incorrect password', function() {
- cy.get('input[type=email]').type(this.email)
- cy.get('input[type=password]').type('incorrect')
- cy.get('input[type=submit]').contains('Sign in').click()
- cy.url().should('contain', "/users/sign_in")
- cy.get('div.alert').contains('Invalid email or password')
+ it('fails to log in with expired token', function() {
+ const expired_token = this.client_auth['expired']['api_token']
+ cy.visit('/token/?api_token='+expired_token)
+ cy.contains('Please log in')
+ cy.url().should('not.contain', '/projects/')
})
})
\ No newline at end of file