diff --git a/mpwo_client/e2e/admin.test.js b/mpwo_client/e2e/admin.test.js new file mode 100644 index 00000000..d1cd02ca --- /dev/null +++ b/mpwo_client/e2e/admin.test.js @@ -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() + +}) diff --git a/mpwo_client/e2e/profile.text.js b/mpwo_client/e2e/profile.test.js similarity index 100% rename from mpwo_client/e2e/profile.text.js rename to mpwo_client/e2e/profile.test.js diff --git a/test.sh b/test.sh index b6368991..5d885e4f 100644 --- a/test.sh +++ b/test.sh @@ -12,6 +12,7 @@ docker-compose -f docker-compose-ci.yml run mpwo-api py.test mpwo_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 init_data testcafe chrome mpwo_client/e2e inspect $? e2e