Skip to content

Commit

Permalink
Setting up jest in travis
Browse files Browse the repository at this point in the history
  • Loading branch information
NBNARADHYA committed Sep 8, 2019
1 parent 49d2f35 commit 77f93a9
Show file tree
Hide file tree
Showing 15 changed files with 7,220 additions and 276 deletions.
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
42 changes: 22 additions & 20 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"extends": ["eslint:recommended", "prettier"],
"env": {
"node": true,
"browser": false,
"commonjs": true,
"es6": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"plugins": ["prettier"],
"rules": {
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"],
"prettier/prettier": ["error", { "singleQuote": true }]
}
"extends": ["eslint:recommended", "prettier"],
"env": {
"node": true,
"browser": true,
"commonjs": true,
"es6": true,
"jest": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"plugins": ["prettier"],
"rules": {
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"],
"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
Docker Files
.dockerignore
docker-compose.yml
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

0 comments on commit 77f93a9

Please sign in to comment.