FitTrackee/fittrackee_client/e2e/admin.test.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-01-13 13:13:10 +01:00
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'
// database must be initialiazed
2018-04-29 18:56:41 +02:00
const adminEmail = 'admin@example.com'
const adminPassword = 'mpwoadmin'
2018-01-13 13:13:10 +01:00
// eslint-disable-next-line no-undef
2018-04-29 18:56:41 +02:00
fixture('/admin').page(`${TEST_URL}/admin`)
2018-01-13 13:13:10 +01:00
2018-04-29 18:56:41 +02:00
test('standard user should not be able to access admin page', async t => {
2018-01-13 13:13:10 +01:00
// register user
await t
.navigateTo(`${TEST_URL}/register`)
.typeText('input[name="username"]', username)
.typeText('input[name="email"]', email)
.typeText('input[name="password"]', password)
2018-06-12 11:47:01 +02:00
.typeText('input[name="password_conf"]', password)
2018-01-13 13:13:10 +01:00
.click(Selector('input[type="submit"]'))
await t
2018-04-29 18:56:41 +02:00
.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
2018-01-13 13:13:10 +01:00
.navigateTo(`${TEST_URL}/login`)
2018-04-29 18:56:41 +02:00
.typeText('input[name="email"]', adminEmail)
.typeText('input[name="password"]', adminPassword)
2018-01-13 13:13:10 +01:00
.click(Selector('input[type="submit"]'))
await t
2018-04-29 18:56:41 +02:00
.navigateTo(`${TEST_URL}/admin`)
.expect(Selector('H1').withText('Access denied').exists).notOk()
.expect(Selector('H1').withText('Administration').exists).ok()
.expect(Selector('.admin-items').withText('Sports').exists).ok()
2018-01-13 13:13:10 +01:00
})