API & Client: refactor (rename mpwo to fittrackee)
This commit is contained in:
43
fittrackee_client/e2e/activities.test.js
Normal file
43
fittrackee_client/e2e/activities.test.js
Normal file
@ -0,0 +1,43 @@
|
||||
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'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/activities').page(`${TEST_URL}/activities`)
|
||||
|
||||
test('standard user should be able to add a workout (w/o gpx)', async t => {
|
||||
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}/activities/add`)
|
||||
.expect(Selector('H1').withText('Dashboard').exists).notOk()
|
||||
.expect(Selector('H2').withText('Add a workout').exists).ok()
|
||||
.click(Selector('input[name="withoutGpx"]'))
|
||||
.click(Selector('select').filter('[name="sport_id"]'))
|
||||
.click(Selector('option').filter('[value="1"]'))
|
||||
.typeText('input[name="activity_date"]', '2018-12-20')
|
||||
.typeText('input[name="activity_time"]', '14:05')
|
||||
.typeText('input[name="duration"]', '01:00:00')
|
||||
.typeText('input[name="distance"]', '10')
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// pb w/ chromium to check
|
||||
// await t
|
||||
// .expect(Selector('H1').withText('Dashboard').exists).notOk()
|
||||
// .expect(Selector('H1').withText('Activity').exists).ok()
|
||||
|
||||
})
|
||||
|
25
fittrackee_client/e2e/admin-sports.test.js
Normal file
25
fittrackee_client/e2e/admin-sports.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { Selector } from 'testcafe'
|
||||
|
||||
import { TEST_URL } from './utils'
|
||||
|
||||
// database must be initialiazed
|
||||
const adminEmail = 'admin@example.com'
|
||||
const adminPassword = 'mpwoadmin'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/admin/sports').page(`${TEST_URL}/admin/sports`)
|
||||
|
||||
test('admin should be able to access sports administration 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/sports`)
|
||||
.expect(Selector('H1').withText('Administration - Sports').exists).ok()
|
||||
.expect(Selector('TD').withText('Hiking').exists).ok()
|
||||
})
|
50
fittrackee_client/e2e/admin.test.js
Normal file
50
fittrackee_client/e2e/admin.test.js
Normal file
@ -0,0 +1,50 @@
|
||||
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
|
||||
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()
|
||||
.expect(Selector('.admin-items').withText('Sports').exists).ok()
|
||||
|
||||
})
|
15
fittrackee_client/e2e/index.test.js
Normal file
15
fittrackee_client/e2e/index.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { Selector } from 'testcafe'
|
||||
|
||||
import { TEST_URL } from './utils'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/').page(`${TEST_URL}/`)
|
||||
|
||||
test('users should be able to view the \'/\' page', async t => {
|
||||
|
||||
await t
|
||||
.navigateTo(TEST_URL)
|
||||
.expect(Selector('A').withText('Dashboard').exists).ok()
|
||||
|
||||
})
|
97
fittrackee_client/e2e/login.test.js
Normal file
97
fittrackee_client/e2e/login.test.js
Normal file
@ -0,0 +1,97 @@
|
||||
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'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/login').page(`${TEST_URL}/login`)
|
||||
|
||||
test('should display the registration form', async t => {
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.expect(Selector('form').exists).ok()
|
||||
.expect(Selector('input[name="username"]').exists).notOk()
|
||||
.expect(Selector('input[name="email"]').exists).ok()
|
||||
.expect(Selector('input[name="password"]').exists).ok()
|
||||
.expect(Selector('input[name="passwordConf"]').exists).notOk()
|
||||
})
|
||||
|
||||
test('should throw an error if the user is not registered', async t => {
|
||||
|
||||
// register user with duplicate user name
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Invalid credentials.').exists).ok()
|
||||
})
|
||||
|
||||
test('should allow a user to login', 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}/logout`)
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user is redirected to '/'
|
||||
await t
|
||||
.expect(Selector('H1').withText('Login').exists).notOk()
|
||||
|
||||
})
|
||||
|
||||
test('should throw an error if the email is invalid', async t => {
|
||||
|
||||
// register user with duplicate user name
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.typeText('input[name="email"]', `${email}2`)
|
||||
.typeText('input[name="password"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Invalid credentials.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if the password is invalid', async t => {
|
||||
|
||||
// register user with duplicate user name
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', `${password}2`)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Invalid credentials.').exists).ok()
|
||||
})
|
40
fittrackee_client/e2e/profile.test.js
Normal file
40
fittrackee_client/e2e/profile.test.js
Normal file
@ -0,0 +1,40 @@
|
||||
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'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/profile').page(`${TEST_URL}/profile`)
|
||||
|
||||
test('should be able to access his profile 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}/logout`)
|
||||
.navigateTo(`${TEST_URL}/login`)
|
||||
.expect(Selector('H1').withText('Login').exists).ok()
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/profile`)
|
||||
.expect(Selector('H1').withText('Login').exists).notOk()
|
||||
.expect(Selector('H1').withText('Dashboard').exists).notOk()
|
||||
.expect(Selector('H1').withText('Profile').exists).ok()
|
||||
.expect(Selector('.userName').withText(username).exists).ok()
|
||||
|
||||
})
|
177
fittrackee_client/e2e/register.test.js
Normal file
177
fittrackee_client/e2e/register.test.js
Normal file
@ -0,0 +1,177 @@
|
||||
import { Selector } from 'testcafe'
|
||||
|
||||
import { TEST_URL } from './utils'
|
||||
|
||||
const randomstring = require('randomstring')
|
||||
|
||||
let username = randomstring.generate(8)
|
||||
const email = `${username}@test.com`
|
||||
const password = 'lentghOk'
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
fixture('/register').page(`${TEST_URL}/register`)
|
||||
|
||||
test('should display the registration form', async t => {
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('form').exists).ok()
|
||||
.expect(Selector('input[name="username"]').exists).ok()
|
||||
.expect(Selector('input[name="email"]').exists).ok()
|
||||
.expect(Selector('input[name="password"]').exists).ok()
|
||||
.expect(Selector('input[name="passwordConf"]').exists).ok()
|
||||
})
|
||||
|
||||
test('should allow a user to register', async t => {
|
||||
|
||||
// register user
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.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"]'))
|
||||
|
||||
// assert user is redirected to '/'
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).notOk()
|
||||
})
|
||||
|
||||
test('should throw an error if the username is taken', async t => {
|
||||
|
||||
// register user with duplicate user name
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', username)
|
||||
.typeText('input[name="email"]', `${email}2`)
|
||||
.typeText('input[name="password"]', password)
|
||||
.typeText('input[name="passwordConf"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Sorry. That user already exists.').exists).ok()
|
||||
})
|
||||
|
||||
username = randomstring.generate(8)
|
||||
|
||||
test('should throw an error if the email is taken', async t => {
|
||||
|
||||
// register user with duplicate email
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', `${username}2`)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.typeText('input[name="passwordConf"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Sorry. That user already exists.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if the username is too short', async t => {
|
||||
|
||||
const shortUsername = 'a'
|
||||
|
||||
// register user with duplicate email
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', `${shortUsername}`)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.typeText('input[name="passwordConf"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Username: 3 to 12 characters required.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if the user is too long', async t => {
|
||||
|
||||
const longUsername = randomstring.generate(20)
|
||||
|
||||
// register user with duplicate email
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', `${longUsername}`)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', password)
|
||||
.typeText('input[name="passwordConf"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Username: 3 to 12 characters required.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if the email is invalid', async t => {
|
||||
|
||||
const invalidEmail = `${username}@test`
|
||||
|
||||
// register user with duplicate email
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', username)
|
||||
.typeText('input[name="email"]', invalidEmail)
|
||||
.typeText('input[name="password"]', password)
|
||||
.typeText('input[name="passwordConf"]', password)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Valid email must be provided.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if passwords don\'t match', async t => {
|
||||
|
||||
// register user with duplicate email
|
||||
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}2`)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Password and password confirmation don\'t match.').exists).ok()
|
||||
})
|
||||
|
||||
test('should throw an error if the password is too short', async t => {
|
||||
|
||||
const invalidPassword = '1234567'
|
||||
|
||||
// register user with duplicate email
|
||||
await t
|
||||
.navigateTo(`${TEST_URL}/register`)
|
||||
.typeText('input[name="username"]', username)
|
||||
.typeText('input[name="email"]', email)
|
||||
.typeText('input[name="password"]', invalidPassword)
|
||||
.typeText('input[name="passwordConf"]', invalidPassword)
|
||||
.click(Selector('input[type="submit"]'))
|
||||
|
||||
// assert user registration failed
|
||||
await t
|
||||
.expect(Selector('H1').withText('Register').exists).ok()
|
||||
.expect(Selector('code').withText(
|
||||
'Password: 8 characters required.').exists).ok()
|
||||
})
|
1
fittrackee_client/e2e/utils.js
Normal file
1
fittrackee_client/e2e/utils.js
Normal file
@ -0,0 +1 @@
|
||||
export const TEST_URL = process.env.TEST_URL
|
Reference in New Issue
Block a user