Skip to content

Commit

Permalink
ch(test) Add frontend controller test units
Browse files Browse the repository at this point in the history
  - Mock http request for angular
  - write unit test cases for controller methods
  - modified controller methods to return promise
  [Finishes #158457036]
  • Loading branch information
Ben Onah committed Jul 12, 2018
1 parent fcbbe72 commit 7b11fff
Show file tree
Hide file tree
Showing 24 changed files with 248 additions and 391 deletions.
3 changes: 0 additions & 3 deletions .env 2

This file was deleted.

2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MONGOHQ_URL_TEST=<Test database url>
MONGOHQ_URL_DEV=<Development database url>
MONGODB_URI=<Development database url>
SECRET_KEY=<Secret key for JWT>
GMAIL_PASSWORD=<password is pinned at slack channel>
26 changes: 15 additions & 11 deletions .eslintrc.js → .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
"root": true,
{
"root": true,
"extends": "airbnb-base",
"env": {
"node": true,
Expand All @@ -25,19 +25,23 @@ module.exports = {
"requireReturnDescription": true
}],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
},
"globals": {
"document": true,
"window": true,
"localStorage": true,
"window": true,
"localStorage": true,
"FormData": true,
"angular": true,
"$": true,
"require": true,
"describe": true,
"before": true,
"it": true,
"$": true
}
};
}
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
},
"env": {
"MONGOHQ_URL": {
"MONGODB_URI": {
"required": true
},
"GMAIL_PASSWORD": {
Expand Down
9 changes: 4 additions & 5 deletions backend-test/integration/findUsers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill';
import request from 'supertest';
import { expect } from 'chai';
import mongoose from 'mongoose';
Expand Down Expand Up @@ -44,9 +43,9 @@ describe('User endpoints', () => {
Promise.resolve(User.remove({}));
});

it('GET /users/findUsers/:searchKey should return statusCode 200 with 2 users', (done) => {
it('GET /api/users/findUsers/:searchKey should return statusCode 200 with 2 users', (done) => {
request(app)
.get('/users/findUsers/ben')
.get('/api/users/findUsers/ben')
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
if (err) return done(err);
Expand All @@ -56,9 +55,9 @@ describe('User endpoints', () => {
});
});

it('GET /users/findUsers/:searchKey should return statusCode 200 with no user', (done) => {
it('GET /api/users/findUsers/:searchKey should return statusCode 200 with no user', (done) => {
request(app)
.get('/users/findUsers/nothing')
.get('/api/users/findUsers/nothing')
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
if (err) return done(err);
Expand Down
13 changes: 6 additions & 7 deletions backend-test/integration/inviteUsers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'babel-polyfill';
import request from 'supertest';
import { expect } from 'chai';
import app from '../../server';
Expand All @@ -13,7 +12,7 @@ const user = {
const token = Tokenizer(user);

describe('User endpoints', () => {
it('POST /users/invite should return statusCode 200 with a user object', (done) => {
it('POST /api/users/invite should return statusCode 200 with a user object', (done) => {
const payload = {
user: {
name: 'Ben Onah',
Expand All @@ -23,7 +22,7 @@ describe('User endpoints', () => {
link: 'http://localhost:3333/app'
};
request(app)
.post('/users/invite')
.post('/api/users/invite')
.set('Authorization', `Bearer ${token}`)
.send(payload)
.end((err, res) => {
Expand All @@ -34,7 +33,7 @@ describe('User endpoints', () => {
});
});

it('POST /users/invite should return statusCode 400 with error message if wrong email is used', (done) => {
it('POST /api/users/invite should return statusCode 400 with error message if wrong email is used', (done) => {
const payload = {
user: {
name: 'Ben Onah',
Expand All @@ -44,7 +43,7 @@ describe('User endpoints', () => {
link: 'http://localhost:3333/app'
};
request(app)
.post('/users/invite')
.post('/api/users/invite')
.set('Authorization', `Bearer ${token}`)
.send(payload)
.end((err, res) => {
Expand All @@ -55,7 +54,7 @@ describe('User endpoints', () => {
});
});

it('POST /users/invite should return statusCode 400 with error message if wrong link is used', (done) => {
it('POST /api/users/invite should return statusCode 400 with error message if wrong link is used', (done) => {
const payload = {
user: {
name: 'Ben Onah',
Expand All @@ -65,7 +64,7 @@ describe('User endpoints', () => {
link: 'htt/localhost:3333/app'
};
request(app)
.post('/users/invite')
.post('/api/users/invite')
.set('Authorization', `Bearer ${token}`)
.send(payload)
.end((err, res) => {
Expand Down
2 changes: 1 addition & 1 deletion config/env/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ dotenv.config();
module.exports = {
root: rootPath,
port: process.env.PORT || 3000,
db: process.env.MONGOHQ_URL,
db: process.env.MONGODB_URI,
};
2 changes: 1 addition & 1 deletion config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
name: 'Cards for Humanity - Development'
},
port: process.env.PORT,
MONGOHQ_URL: process.env.MONGOHQ_URL_DEV,
MONGOHQ_URL: process.env.MONGODB_URI,
facebook: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
Expand Down
2 changes: 1 addition & 1 deletion config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
app: {
name: 'Cards for Humanity'
},
MONGOHQ_URL: process.env.MONGOHQ_URL,
MONGOHQ_URL: process.env.MONGODB_URI,
facebook: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
Expand Down
8 changes: 4 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export default (router, passport, app) => {
const api = Router();
api
.post('/auth/login', users.handleLogin)
.post('/auth/signup', users.handleSignUp);
.post('/auth/signup', users.handleSignUp)
.get('/users/findUsers/:searchKey', middleware.auth, users.findUsers)
.get('/users/findUsers/', middleware.auth, users.findUsers)
.post('/users/invite', middleware.auth, users.invite);

router.get('/signin', users.signin);
router.get('/signup', users.signup);
Expand All @@ -21,9 +24,6 @@ export default (router, passport, app) => {
// Setting up the users api
router.post('/users', users.create);
router.post('/users/avatars', users.avatars);
router.get('/users/findUsers/:searchKey', middleware.auth, users.findUsers);
router.get('/users/findUsers/', middleware.auth, users.findUsers);
router.post('/users/invite', middleware.auth, users.invite);

// Donation Routes
router.post('/donations', users.addDonation);
Expand Down
Loading

0 comments on commit 7b11fff

Please sign in to comment.