Skip to content
Permalink
Browse files
Merge pull request reisborw#29 from 5001CEM-1920SEPJAN/cucumber
Cucumber
  • Loading branch information
townse41 committed Nov 28, 2019
2 parents 8e55f94 + 6b99cf0 commit fe017449dab026d5da6f49bf0e393db4fe4df6c1
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 35 deletions.
@@ -33,4 +33,7 @@ website.db

# Images
public/images/questions/*
public/images/user_avatar/*
public/images/user_avatar/*

# Screenshots
screenshots
@@ -29,7 +29,6 @@ router.get('/question/:question_id/answers', async ctx => {
data.avatarName = ctx.session.user.avatar
data.id = ctx.session.user.id
}
console.table(data)
await ctx.render('answer', data)
})

@@ -43,17 +43,19 @@ router.get('/createquestion', async ctx => {
title: 'Create a question',
content: 'Page for creating a new question',
auth: ctx.session.authorised,
username: ctx.session.user.username
username: ctx.session.user.username,
avatarName: ctx.session.user.avatar,
id: ctx.session.user.id
}
await ctx.render('createquestion', data)
}
})

/**
* @name Add Question Page
* @route {POST} /addquestion
* @name Create Question Action
* @route {POST} /createquestion
*/
router.post('/addquestion', koaBody, async ctx => {
router.post('/createquestion', koaBody, async ctx => {
try{
const question = await new Question(process.env.DB_NAME)
const date = await question.currentDate(new Date())
@@ -64,12 +66,13 @@ router.post('/addquestion', koaBody, async ctx => {
try{
data = await question.uploadPicture(data, 'image/png')
await question.convertThumbnail(data)
ctx.redirect('/')
ctx.redirect('/?msg=question added')
} catch(err) {
ctx.redirect('/')
ctx.redirect('/?msg=question added')
}
} catch(err) {
await ctx.render('createquestion', {msg: err.message})
await ctx.render('createquestion', {title: 'Create a question',
content: 'Create a question', msg: err.message})
}
})

@@ -37,7 +37,8 @@ router.post('/register-action', koaBody, async ctx => {
ctx.session.user = await user.getLoggedUser(body.username)
ctx.session.user.avatar = 'images/default-avatar.jpg'
} catch(err) {
await ctx.render('register', {msg: err.message})
await ctx.render('register', {title: 'Create an account',
content: 'Page for creating a new account', msg: err.message})
}
})

@@ -78,7 +79,8 @@ router.post('/login-action', async ctx => {

return ctx.redirect('/?msg=you are now logged in...')
} catch(err) {
await ctx.render('login', {msg: err.message})
await ctx.render('login', {title: 'Login',
content: 'Login', msg: err.message})
}
})

@@ -93,7 +95,7 @@ router.get('/logout', async ctx => {
ctx.session.authorised = null
ctx.session.user = null

ctx.redirect('/login?msg=you are now logged out...')
ctx.redirect('/?msg=you are now logged out...')
})

/**
@@ -6,13 +6,13 @@
{{#if msg}}
<p>{{msg}}</p>
{{/if}}
<form action ="/addquestion" enctype="multipart/form-data" method = "POST">
<form action ="/createquestion" enctype="multipart/form-data" method = "POST">
<label>Question Title:<br></label>
<input id = "qtitle" type="text" placeholder = "Input title..." maxlength="100" name="title"><br>
<input type="text" placeholder = "Input title..." maxlength="100" name="title" id="title"><br>
<label>Question:<br></label>
<textarea id = "question" type="text" placeholder = "Input question..." maxlength="1500" name="body"></textarea>
<p><input type="file" name="image"></p>
<p><input type="submit" value="Create Question"></p>
<textarea type="text" placeholder = "Input question..." maxlength="1500" name="body" id="body"></textarea>
<p><input type="file" name="image" id="image"></p>
<p><input type="submit" value="Create Question" id="submit"></p>
</form>
</section>
</main>
@@ -7,9 +7,9 @@
<p class="msg">{{msg}}</p>
{{/if}}
<form action="/login-action" method="post">
<p>Username:<br /><input type="text" name="username" placeholder="your username" value="" autofocus></p>
<p>Password:<br /><input type="password" name="password" placeholder="your password" value=""></p>
<p><input type="submit" value="Log in"></p>
<p>Username:<br /><input type="text" name="username" placeholder="your username" value="" id="username" autofocus></p>
<p>Password:<br /><input type="password" name="password" placeholder="your password" value="" id="password"></p>
<p><input type="submit" value="Log in" id="submit"></p>
</form>
</section>
</main>
@@ -15,39 +15,39 @@
<body>
<header>
<figure>
<a href="/">
<a href="/" id="logo">
<img src="{{__dirname}}/images/gamehub-v2.png" alt="logo"/>
</a>
</figure>

<nav>
<ul>
<li>
<a href="/">Home</a>
<a href="/" id="home">Home</a>
</li>

{{#if auth}}
<li>
<img class = "avatar" src="{{__dirname}}/{{ avatarName }}" alt="avatar">
<img class = "avatar" id="avatar" src="{{__dirname}}/{{ avatarName }}" alt="avatar">
</li>
<li>
<a href="/profile">{{ username }}</a>
<a href="/profile" id="profile">{{ username }}</a>
</li>

<li>
<a href="/createquestion">Add</a>
<a href="/createquestion" id="add">Add</a>
</li>

<li>
<a href="/logout">Logout</a>
<a href="/logout" id="logout">Logout</a>
</li>
{{else}}
<li>
<a href="/login">Login</a>
<a href="/login" id="login">Login</a>
</li>

<li>
<a href="/register">Register</a>
<a href="/register" id="register">Register</a>
</li>
{{/if}}
</ul>
@@ -7,10 +7,10 @@
<p class="msg">{{msg}}</p>
{{/if}}
<form action="/register-action" enctype="multipart/form-data" method="post">
<p>Full Name:<br /><input type="text" name="name" placeholder="What is your name?" value=""></p>
<p>Username:<br /><input type="text" name="username" placeholder="Your preferred username (no spaces)" value=""></p>
<p>Password:<br /><input type="password" name="password" placeholder="Your chosen password" value=""></p>
<p><input type="submit" value="Create"></p>
<p>Full Name:<br /><input type="text" name="name" placeholder="What is your name?" value="" id="name"></p>
<p>Username:<br /><input type="text" name="username" placeholder="Your preferred username (no spaces)" value="" id="username"></p>
<p>Password:<br /><input type="password" name="password" placeholder="Your chosen password" value="" id="password"></p>
<p><input type="submit" value="Create" id="submit"></p>
</form>
</section>
</main>
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# force the script to exit on first fail
set -e

# create any directories needed by the test script
mkdir -p screenshots

# delete any local databases (if you are using them)
rm -rf *.db

# install packages if none found
# [ ! -d "node_modules" ] && echo "INSTALLING MODULES" && npm install

# start the web server in background mode
# node index.js&

# run the test suite in background mode
node_modules/.bin/cucumber-js ./features -r ./steps &

# wait for the tests to complete
sleep 100

# kill the web server
pkill node
@@ -0,0 +1,33 @@
Feature: Register an account
The user should be able to register an account.

Scenario: register page
Given The browser is open on the home page
When I click on the "register" field
Then take a screenshot called "regsiter-page" in "register"
And the first "title" should be "Game Hub | Create an account"
And the first "h1" should be "CREATE AN ACCOUNT"
And the "h1" number "1" should be "Sign Up"
And the unordered list in header should be "Home Login Register"

Scenario: create an account without profile picture
Given The browser is open on the register page
And I enter "Sam Smith" in the "name" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
Then take a screenshot called "regsitered" in "register"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Vasper123 Add Logout"

Scenario: create another account with profile picture
Given The browser is open on the register page
And I enter "Emma Jones" in the "name" field
And I enter "Gamer123" in the "username" field
And I enter "1234" in the "password" field
And I click on the "submit" field
Then take a screenshot called "regsitered-another" in "register"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Gamer123 Add Logout"
@@ -0,0 +1,33 @@
Feature: Login to an account
The user should be able to login to an account.

Scenario: login page
Given The browser is open on the home page
When I click on the "login" field
Then take a screenshot called "login-page" in "login"
And the first "title" should be "Game Hub | Login"
And the first "h1" should be "LOGIN"
And the "h1" number "1" should be "Login"
And the unordered list in header should be "Home Login Register"

Scenario: login to an account
Given The browser is open on the login page
When I click on the "login" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
Then take a screenshot called "logged-in" in "login"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Vasper123 Add Logout"

Scenario: login to another account
Given The browser is open on the login page
When I click on the "login" field
And I enter "Gamer123" in the "username" field
And I enter "1234" in the "password" field
And I click on the "submit" field
Then take a screenshot called "logged-in-another" in "login"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Gamer123 Add Logout"
@@ -0,0 +1,15 @@
Feature: Logout an account
The user should be able to logout an account.

Scenario: logout an account
Given The browser is open on the home page
When I click on the "login" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
And I click on the "logout" field
Then take a screenshot called "logged-out" in "logout"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Login Register"

@@ -0,0 +1,32 @@
Feature: Create a question
The user should be able to create a question.

Scenario: createQuestion page
Given The browser is open on the home page
When I click on the "login" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
And I click on the "add" field
Then take a screenshot called "createquestion-page" in "addQuestion"
And the first "title" should be "Game Hub | Create a question"
And the first "h1" should be "CREATE A QUESTION"
And the "h1" number "1" should be "Create a Question"
And the unordered list in header should be "Home Vasper123 Add Logout"

Scenario: create a question without image
Given The browser is open on the home page
When I click on the "login" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
And I click on the "add" field
And I enter "Call of Duty" in the "title" field
And I enter "How to find pack-a-punch on Die Riese" in the "body" field
And I click on the "submit" field
Then take a screenshot called "question-created" in "addQuestion"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Vasper123 Add Logout"
And the first "h2" should be "Call of Duty"
And the first "h3" should be "How to find pack-a-punch on Die Riese"
@@ -0,0 +1,17 @@
Feature: Edit a profile
The user should be able to edit thier profile.

Scenario: profile page
Given The browser is open on the login page
When I click on the "login" field
And I enter "Vasper123" in the "username" field
And I enter "123" in the "password" field
And I click on the "submit" field
And I click on the "profile" field
Then take a screenshot called "profile-page" in "profile"
And the first "title" should be "Game Hub | Sam Smith's Profile"
And the first "h1" should be "SAM SMITH'S PROFILE"

And the "h1" number "1" should be "Profile"

And the unordered list in header should be "Home Vasper123 Add Logout"
@@ -0,0 +1,25 @@
Feature: Open Home page
The user should be able to view the home page.

Scenario: home page
Given The browser is open on the home page
Then take a screenshot called "home-page" in "home"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Login Register"

Scenario: home page link
Given The browser is open on the register page
When I click on the "home" field
Then take a screenshot called "home-page-another" in "home"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Login Register"

Scenario: home page logo button
Given The browser is open on the login page
When I click on the "logo" field
Then take a screenshot called "home-page-button" in "home"
And the first "title" should be "Game Hub | Welcome to the GameHub"
And the first "h1" should be "WELCOME TO THE GAMEHUB"
And the unordered list in header should be "Home Login Register"
@@ -12,7 +12,8 @@
"jsdoc": "node_modules/.bin/jsdoc -c jsdoc.conf",
"linter": "node_modules/.bin/eslint .",
"test": "jest --coverage --detectOpenHandles",
"unit": "node_modules/.bin/jest --coverage --runInBand tests/unit/"
"unit": "node_modules/.bin/jest --coverage --runInBand tests/unit/",
"cucumber": "./cucumberTest.sh"
},
"jest": {
"projects": [
@@ -56,6 +57,13 @@
"jsdoc": "^3.6.3",
"jsdoc-route-plugin": "^0.1.0",
"markdownlint": "^0.17.0",
"nodemon": "^1.19.4"
"nodemon": "^1.19.4",
"cucumber": "^5.1.0",
"featurebook": "0.0.32",
"jest-cucumber": "^2.0.11",
"jest-image-snapshot": "^2.11.0",
"jest-puppeteer": "^4.3.0",
"puppeteer": "^1.20.0",
"supertest": "^4.0.2"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fe01744

Please sign in to comment.