e2e tests: admin

This commit is contained in:
Sam 2018-04-29 18:56:41 +02:00
parent 52c889218a
commit abb4a3840d
3 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import { Selector } from 'testcafe'
import { TEST_URL } from './utils'
const randomstring = require('randomstring')
const username = randomstring.generate(8)
const email = `${username}@test.com`
const password = 'lentghOk'
const adminEmail = 'admin@example.com'
const adminPassword = 'mpwoadmin'
// eslint-disable-next-line no-undef
fixture('/admin').page(`${TEST_URL}/admin`)
test('standard user should not be able to access admin page', async t => {
// register user
await t
.navigateTo(`${TEST_URL}/register`)
.typeText('input[name="username"]', username)
.typeText('input[name="email"]', email)
.typeText('input[name="password"]', password)
.typeText('input[name="passwordConf"]', password)
.click(Selector('input[type="submit"]'))
await t
.navigateTo(`${TEST_URL}/admin`)
.expect(Selector('H1').withText('Access denied').exists).ok()
.expect(Selector('H1').withText('Dashboard').exists).notOk()
})
test('admin should be able to access admin page', async t => {
// admin login
await t
.navigateTo(`${TEST_URL}/login`)
.typeText('input[name="email"]', adminEmail)
.typeText('input[name="password"]', adminPassword)
.click(Selector('input[type="submit"]'))
await t
.navigateTo(`${TEST_URL}/admin`)
.expect(Selector('H1').withText('Access denied').exists).notOk()
.expect(Selector('H1').withText('Administration').exists).ok()
})

View File

@ -12,6 +12,7 @@ docker-compose -f docker-compose-ci.yml run mpwo-api py.test mpwo_api
inspect $? api inspect $? api
docker-compose -f docker-compose-ci.yml run mpwo-api flask db upgrade docker-compose -f docker-compose-ci.yml run mpwo-api flask db upgrade
docker-compose -f docker-compose-ci.yml run mpwo-api flask init_data
testcafe chrome mpwo_client/e2e testcafe chrome mpwo_client/e2e
inspect $? e2e inspect $? e2e