Skip to content

Commit

Permalink
Update All files to pass linting. Ensure all server tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mallek committed Jan 31, 2018
1 parent 93bdc35 commit 46b5412
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 83 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"extends": "airbnb-base"
"extends": "airbnb-base",
"env": {
"node": true,
"mocha": true,
"jasmine": true
}
}
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const app = express();
*/

// Setup MongoDB connection using the global promise library and then get connection
mongoose.connect(DB_URL, { promiseLibrary: global.Promise }, error => {
mongoose.connect(DB_URL, { promiseLibrary: global.Promise }, (error) => {
if (error) {
console.log(`MongoDB connection error: ${error}`);

Expand All @@ -39,7 +39,7 @@ app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Access, Authorization'
'Origin, X-Requested-With, Content-Type, Access, Authorization',
);

if (req.method === 'OPTIONS') {
Expand Down
6 changes: 3 additions & 3 deletions config/dev.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const SECRETS = require('./secrets.json'); // nodejs will auto read json
const SECRETS = require('./secrets.json'); // nodejs will auto read json

module.exports = {
NODE_ENV: process.env.NODE_ENV || 'development',
HOST: process.env.HOST || 'http://localhost',
PORT: process.env.PORT || 8081,
DB_URL : SECRETS.mongodb_dev.db_url,
GOOGLE_API_KEY: SECRETS.google_maps.api_key
DB_URL: SECRETS.mongodb_dev.db_url,
GOOGLE_API_KEY: SECRETS.google_maps.api_key,
};
4 changes: 2 additions & 2 deletions config/prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
NODE_ENV: process.env.NODE_ENV || 'production',
HOST: process.env.HOST,
PORT: process.env.PORT,
DB_URL : SECRETS.mongodb_prod.db_url,
GOOGLE_API_KEY: SECRETS.google_maps.api_key
DB_URL: SECRETS.mongodb_prod.db_url,
GOOGLE_API_KEY: SECRETS.google_maps.api_key,
};
54 changes: 27 additions & 27 deletions controllers/google-api-controller.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const http = require('https');
const {GOOGLE_API_KEY} = require('../config');
const { GOOGLE_API_KEY } = require('../config');

/**
* Geolocation API access
* Geolocation requests are sent using POST to the following URL:
* https://www.googleapis.com/geolocation/v1/geolocate?key=<YOUR_KEY>
*/
const GEOLOCATION_OPTIONS = {
"method": "POST",
"hostname": "www.googleapis.com",
"port": null,
"path": `/geolocation/v1/geolocate?key=${GOOGLE_API_KEY}`,
"headers": {
"content-type": "application/json",
"cache-control": "no-cache"
}
method: 'POST',
hostname: 'www.googleapis.com',
port: null,
path: `/geolocation/v1/geolocate?key=${GOOGLE_API_KEY}`,
headers: {
'content-type': 'application/json',
'cache-control': 'no-cache',
},
};

/**
* @description Hanlder for Geolocation API call
* @returns {JSON} 'location': estimated 'lat' and 'lng'; 'accuracy': accuracy of
* the estimated location, in meters
*/
exports.getGeolocation = function(appReq, appRes) {
const req = http.request(GEOLOCATION_OPTIONS, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
appRes.send(JSON.parse(body.toString()));
});
});
req.write(JSON.stringify({}));
req.end();
}
exports.getGeolocation = (appReq, appRes) => {
const req = http.request(GEOLOCATION_OPTIONS, (res) => {
const chunks = [];

res.on('data', (chunk) => {
chunks.push(chunk);
});

res.on('end', () => {
const body = Buffer.concat(chunks);
console.log(body.toString());
appRes.send(JSON.parse(body.toString()));
});
});

req.write(JSON.stringify({}));
req.end();
};
2 changes: 1 addition & 1 deletion controllers/saved-directions-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const SavedDirections = require('../models/saved-directions');

/**
* TODO - export functions to be used for completing requests in ../routes/search.js
*/
*/
2 changes: 1 addition & 1 deletion controllers/saved-pins-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const SavedPins = require('../models/saved-pins');

/**
* TODO - export functions to be used for completing requests in ../routes/search.js
*/
*/
13 changes: 7 additions & 6 deletions models/saved-directions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const savedDirectionsSchema = new Schema({
origin: {type: Schema.Types.Mixed, required: true},
destination: {type: Schema.Types.Mixed, required: true},
geocoded_waypoints: {type: [Schema.Types.Mixed], required: true},
routes: {type: [Schema.Types.Mixed], required: true},
save_date: {type: Date, default: Date.now}
origin: { type: Schema.Types.Mixed, required: true },
destination: { type: Schema.Types.Mixed, required: true },
geocoded_waypoints: { type: [Schema.Types.Mixed], required: true },
routes: { type: [Schema.Types.Mixed], required: true },
save_date: { type: Date, default: Date.now },
});

module.exports = mongoose.model('SavedDirections', savedDirectionsSchema);
module.exports = mongoose.model('SavedDirections', savedDirectionsSchema);
17 changes: 11 additions & 6 deletions models/saved-pins.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const savedPinsSchema = new Schema({
lat: {type: Number, min: -90, max: 90, required: true},
lng: {type: Number, min: -180, max: 180, required: true},
place_id: {type: String, required: true},
save_date: {type: Date, default: Date.now},
})
lat: {
type: Number, min: -90, max: 90, required: true,
},
lng: {
type: Number, min: -180, max: 180, required: true,
},
place_id: { type: String, required: true },
save_date: { type: Date, default: Date.now },
});

module.exports = mongoose.model('SavedPins', savedPinsSchema);
module.exports = mongoose.model('SavedPins', savedPinsSchema);
7 changes: 4 additions & 3 deletions models/search-history.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const searchHistorySchema = new Schema({
query: {type: String, required: true},
save_date: {type: Date, default: Date.now}
query: { type: String, required: true },
save_date: { type: Date, default: Date.now },
});

module.exports = mongoose.model('SearchHistory', searchHistorySchema);
module.exports = mongoose.model('SearchHistory', searchHistorySchema);
5 changes: 3 additions & 2 deletions models/users.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const usersSchema = new Schema({
name: {type: String, required: true}
name: { type: String, required: true },
});

module.exports = mongoose.model('Users', usersSchema);
module.exports = mongoose.model('Users', usersSchema);
9 changes: 5 additions & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var express = require('express');
var router = express.Router();
let express = require('express');

let router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.send('Hello World!');
router.get('/', (req, res, next) => {
res.send('Hello World!');
});

module.exports = router;
15 changes: 8 additions & 7 deletions routes/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');

const router = express.Router();

// require controller modules
Expand All @@ -8,12 +9,12 @@ const googleApiController = require('../controllers/google-api-controller');
* TODO - hook up url route end points to constroller functions
*/

// temporary hook to confirm base routing is working
router.get('/', function(req, res) {
res.send('NOT IMPLEMENTED: Map View');
})
// temporary hook to confirm base routing is working
router.get('/', (req, res) => {
res.send('NOT IMPLEMENTED: Map View');
});

// Geolocation api hook
router.get('/geolocation', googleApiController.getGeolocation);
// Geolocation api hook
router.get('/geolocation', googleApiController.getGeolocation);

module.exports = router;
module.exports = router;
11 changes: 6 additions & 5 deletions routes/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');

const router = express.Router();

// require controller modules
Expand All @@ -11,9 +12,9 @@ const searchHistoryController = require('../controllers/search-history-controlle
* TODO - hook up url route end points to constroller functions
*/

// temporary hook to confirm base routing is working
router.get('/', function(req, res) {
res.send('NOT IMPLEMENTED: Search View');
})
// temporary hook to confirm base routing is working
router.get('/', (req, res) => {
res.send('NOT IMPLEMENTED: Search View');
});

module.exports = router;
module.exports = router;
11 changes: 6 additions & 5 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');

const router = express.Router();

// Middleware
Expand All @@ -12,16 +13,16 @@ const authenticateUser = (req, res, next) => {
next();
};

/*
TODO:
/*
TODO:
Setup API Routes
*/
// temporary hook to confirm base routing is working
router.get('/', function(req, res) {
router.get('/', (req, res) => {
res.send('NOT IMPLEMENTED: Users View');
})
});

router.get('/users/current', authenticateUser, (req, res) => {
router.get('/current', authenticateUser, (req, res) => {
res.status(200).send({});
});

Expand Down
14 changes: 7 additions & 7 deletions tests/apiRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ const request = require('supertest');
const app = require('../app');

describe('API Routes', () => {
describe('GET /api/users/current', () => {
describe('GET /users/current', () => {
it('does not send a user if not logged in', async () => {
try {
const res = await request(app)
.get('/api/users/current')
.get('/users/current')
.expect(401);
expect(res).to.be.an('object')

expect(res).to.be.an('object');
} catch (error) {
throw error;
}
})
})
})
});
});
});
2 changes: 1 addition & 1 deletion tests/server.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
it('test runner should work', () => {
const foo = 'bar';
const beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
const beverages = { tea: ['chai', 'matcha', 'oolong'] };

expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
Expand Down

0 comments on commit 46b5412

Please sign in to comment.