Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Test Driven Development in Travis CI #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ language: node_js
node_js:
- lts/*

services:
- mysql

jobs:
include:
- stage: 'Test the server'
before_install: cd backend
script: npm run lint
before_script:
- wget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
- sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb
- sudo apt-get update -q
- sudo apt-get install -q -y --allow-unauthenticated -o Dpkg::Options::=--force-confnew mysql-server
- sudo systemctl restart mysql
- sudo mysql_upgrade
- mysql --version
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test;'
- mysql -u root test < database.sql
- ssh-keygen -f rsa_secret -N abcde -q
script:
- npm run lint
- npm run test

- stage: 'Test frontend code'
before_install: cd frontend
script: npm run lint
script:
- npm run lint
- npm run test
8 changes: 5 additions & 3 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"extends": ["eslint:recommended", "prettier"],
"env": {
"node": true,
"browser": false,
"browser": true,
"commonjs": true,
"es6": true
"es6": true,
"jest": true
},
"globals": {
"Atomics": "readonly",
Expand All @@ -17,6 +18,7 @@
"rules": {
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"],
"prettier/prettier": ["error", { "singleQuote": true }]
"prettier/prettier": ["error", { "singleQuote": true }],
"no-unused-vars": ["error", { "args": "none" }]
}
}
4 changes: 4 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
node_modules
rsa_secret
rsa_secret.pub
.vscode
.dockerignore
docker-compose.yml
Dockerfile
24 changes: 11 additions & 13 deletions backend/Routes/Controllers/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const middleware = require('../auth/middlewares');
const ajv = require('../../../Schema');
const express = require('express');
const router = express.Router();
router.use(express.json());
router.use(express.urlencoded({ extended: false }));

const {
signupSchema,
Expand All @@ -25,7 +27,7 @@ function sumErrors(errArray) {
return errArray.reduce(cb, '');
}

router.post('/signup', async (req, res) => {
router.post('/signup', (req, res) => {
let validate = ajv.compile(signupSchema);
let valid = validate(req.body);
if (!valid) {
Expand All @@ -38,13 +40,16 @@ router.post('/signup', async (req, res) => {
auth
.signup(req.body)
.then(results => {
console.log(res.json);
return res.status(200).json({
success: true,
error: null,
results
});
})
.catch(error => {
console.log('HI');
console.log(error);
return res.status(400).json({
success: false,
error,
Expand All @@ -53,7 +58,7 @@ router.post('/signup', async (req, res) => {
});
});

router.post('/login', async (req, res) => {
router.post('/login', (req, res) => {
let validate = ajv.compile(loginSchema);
let valid = validate(req.body);
if (!valid) {
Expand Down Expand Up @@ -91,7 +96,7 @@ router.post('/login', async (req, res) => {
router.get(
'/users/:username',
middleware.verifyUser.verifyAccessToken,
async (req, res) => {
(req, res) => {
const username = req.params.username;
if (!username) {
return res.status(404).json({
Expand Down Expand Up @@ -126,7 +131,7 @@ router.get(
}
);

router.post('/verify_email', async (req, res) => {
router.post('/verify_email', (req, res) => {
let validate = ajv.compile(verifyEmailSchema);
let valid = validate(req.body);
if (!valid) {
Expand Down Expand Up @@ -154,7 +159,7 @@ router.post('/verify_email', async (req, res) => {
});
});

router.post('/verify_new_email', async (req, res) => {
router.post('/verify_new_email', (req, res) => {
let validate = ajv.compile(verifyNewEmailSchema);
let valid = validate(req.body);
if (!valid) {
Expand Down Expand Up @@ -273,14 +278,7 @@ router.post('/forgot_password', (req, res) => {
});
})
.catch(error => {
if (error === 'Email not linked to the username') {
return res.status(401).json({
success: false,
error,
results: null
});
}
return res.status(400).json({
return res.status(401).json({
success: false,
error,
results: null
Expand Down
Loading