From a3af93edc3e410079c431e9cca64bafe92d195aa Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 16:29:42 -0700 Subject: [PATCH 01/13] remove mystery file --- module.exports = { | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 module.exports = { diff --git a/module.exports = { b/module.exports = { deleted file mode 100644 index 4357cb5..0000000 --- a/module.exports = { +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - secret: 'lskdjfl343oriweufpi34r0wepfkoj309werl' -}; From 998dfb266f58f250175251a7c63b8f4cf027fe6b Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 16:40:42 -0700 Subject: [PATCH 02/13] fix resolve git ignored - wasnt handling case where folders didnt exist --- tools/resolveGitIgnored.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/resolveGitIgnored.js b/tools/resolveGitIgnored.js index d075408..5887a56 100644 --- a/tools/resolveGitIgnored.js +++ b/tools/resolveGitIgnored.js @@ -3,6 +3,8 @@ const path = require('path'); const shell = require('shelljs'); const PRIVATE_DIR = path.join(__dirname, '/../../carvis-private-info'); +console.log(PRIVATE_DIR); +makePrivateDirsIfNeeded(); let fileDirectory = fs.readdirSync(PRIVATE_DIR); updatePrivateDirectory(fileDirectory); fileDirectory = fileDirectory.filter((file) => file[0] !== '.'); @@ -17,16 +19,23 @@ fileDirectory.forEach((file) => { fs.createReadStream(currentFile).pipe(fs.createWriteStream(path.join(__dirname, `/../${filePath}`))); }); - -function updatePrivateDirectory(directory) { - let pwd = shell.pwd(); - if (directory.length === 0) { +function makePrivateDirsIfNeeded() { + let searchDir = path.join(__dirname, '/../../'); + let thisDir = path.join(__dirname, '/../'); + if (fs.readdirSync(thisDir).indexOf('secret') === -1) { + shell.exec('mkdir secret'); + } + if (fs.readdirSync(searchDir).indexOf('carvis-private-info') === -1) { shell.cd('..'); shell.exec('git clone https://github.com/alexcstark/carvis-private-info.git'); + shell.exec('git remote add upstream https://github.com/alexcstark/carvis-private-info.git'); shell.cd('carvis-private-info'); - } else { - shell.cd('../carvis-private-info'); } - shell.exec('git pull upstream master'); +} +function updatePrivateDirectory(directory) { + console.log(directory); + let pwd = shell.pwd(); + shell.cd('../carvis-private-info'); + shell.exec('git pull origin master'); shell.cd(pwd); } From 85acbc5889c7f30beb8e1725db7615f4414f599c Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 16:49:38 -0700 Subject: [PATCH 03/13] slimmed travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index acb94d5..48044bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,3 @@ install: - npm install script: - npm run build -- npm test From 16662fd9a0526871f4bc5dc858f440aed3aa332f Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 17:09:30 -0700 Subject: [PATCH 04/13] basic server test --- .travis.yml | 1 + package.json | 10 +++++----- src/server/routes.js | 4 ++++ tests/index.js | 25 +++++++++++++++++++++++-- tests/testServer.js | 11 +++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 tests/testServer.js diff --git a/.travis.yml b/.travis.yml index 48044bd..8ca2f66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ install: - npm install script: - npm run build +- npm start diff --git a/package.json b/package.json index 8d4f3f6..c5610ac 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "build:db": "babel ./src/db -d ./dist/db --presets es2015,stage-2,es2016 --copy-files", "build": "npm run build:db; npm run build:server", "reset:db": "babel-node ./utils/wipeDB.js", - "setup":"node ./tools/resolveGitIgnored.js;", + "setup": "node ./tools/resolveGitIgnored.js;", "docker:deploy": "npm run build; docker build -t alexcstark/carvis-api .; docker push alexcstark/carvis-api", - "start": "npm run build; node ./dist/server/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha --compilers js:babel-core/register ./tests/index.js", + "start": "npm run build; node ./dist/server/index.js" }, "repository": { "type": "git", @@ -36,12 +36,10 @@ "bluebird": "^3.4.1", "body-parser": "^1.15.2", "btoa": "^1.1.2", - "cookie-parser": "^1.4.3", "cors": "^2.7.1", "express": "^4.14.0", "express-session": "^1.14.0", "jwt-simple": "^0.5.0", - "knex": "^0.11.10", "lodash": "^4.15.0", "node-fetch": "^1.6.0", "passport": "^0.3.2", @@ -52,6 +50,8 @@ "twilio": "^2.9.2" }, "devDependencies": { + "chai": "^3.5.0", + "mocha": "^3.0.2", "morgan": "^1.7.0" } } diff --git a/src/server/routes.js b/src/server/routes.js index 1abbe7e..2fac85c 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -8,6 +8,10 @@ import hasValidAPIToken from './server-configuration/hasValidAPIToken'; export default function(app) { // TODO only let the user with that ID find users (middleware); + app.get('/', (req, res) => { + res.status(200).send('Welcome to the Carvi API.'); + }); + app.get('/users/:userid', getUserDashboardData); app.get('/dev/users', hasValidAPIToken, getAllUserData); diff --git a/tests/index.js b/tests/index.js index e471444..ef31d94 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,5 +1,26 @@ -describe('test carvis api', () => { +const assert = require('chai').assert; +const axios = require('axios'); +const server = require('./testServer'); +let currentListeningServer; + +describe('API server', function () { + before(function () { + currentListeningServer = server.default.listen(3030); + }); + + after(function () { + currentListeningServer.close(); + }); + + describe('Check basic build', function () { + it('should return 200', function (done) { + axios.get('http://localhost:3030/') + .then((res) => { + assert.equal(res.status, 200, 'did not return 200', res.status); + done(); + }); + }); + }); - }); diff --git a/tests/testServer.js b/tests/testServer.js new file mode 100644 index 0000000..2b812cf --- /dev/null +++ b/tests/testServer.js @@ -0,0 +1,11 @@ +import express from 'express'; +import { PORT, configureServer } from '../src/server/server-configuration/config'; +import routes from '../src/server/routes'; + +const app = express(); +// Sessions, passport, auth middleware +configureServer(app); +// Set up routes +routes(app); + +export default app; From 0081f531f01bd1395892178b1612d7907dbe91b7 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 17:14:02 -0700 Subject: [PATCH 05/13] cookie parser back in --- package.json | 1 + src/server/server-configuration/config.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c5610ac..f82c7d3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "bluebird": "^3.4.1", "body-parser": "^1.15.2", "btoa": "^1.1.2", + "cookie-parser": "^1.4.3", "cors": "^2.7.1", "express": "^4.14.0", "express-session": "^1.14.0", diff --git a/src/server/server-configuration/config.js b/src/server/server-configuration/config.js index 1cbb500..2da715b 100644 --- a/src/server/server-configuration/config.js +++ b/src/server/server-configuration/config.js @@ -12,7 +12,7 @@ export const PORT = process.env.PORT || 8000; export const configureServer = function(app) { app.use(express.static(path.join(__dirname, '/../../client'))); app.use(express.static(path.join(__dirname, '/../../../node_modules'))); - // app.use(cookieParser()); + app.use(cookieParser()); app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); From f9bde991432528790615246a232755a8e6792ad8 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 17:17:06 -0700 Subject: [PATCH 06/13] travis npm test --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8ca2f66..acb94d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ install: - npm install script: - npm run build -- npm start +- npm test From e148c66708007667656562de94e3f2fc66053d18 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 17:17:50 -0700 Subject: [PATCH 07/13] attempt to fix secret config for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index acb94d5..500d037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ install: - npm install script: - npm run build +- npm run setup - npm test From b8abb3740be6bd70d9f62cc1bd416f5fdb832986 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Sat, 13 Aug 2016 17:31:05 -0700 Subject: [PATCH 08/13] was missing shelljs --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index f82c7d3..0ee66be 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "passport-jwt": "^2.1.0", "passport-local": "^1.0.0", "pg": "^6.1.0", + "shelljs": "^0.7.3", "storkSQL": "^0.1.13", "twilio": "^2.9.2" }, From d6a3ca2c0a9bc2b43646ac1f23f801a43acb93bd Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Mon, 15 Aug 2016 16:45:30 -0700 Subject: [PATCH 09/13] update to use process.env environment variables --- .travis.yml | 1 - src/db/User.js | 2 +- src/db/db.js | 2 +- src/server/server-configuration/hasValidAPIToken.js | 4 +++- src/server/utils/lyft-helper.js | 3 +-- src/server/utils/twilioHelper.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 500d037..acb94d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,4 @@ install: - npm install script: - npm run build -- npm run setup - npm test diff --git a/src/db/User.js b/src/db/User.js index 57a809d..a50aa5d 100644 --- a/src/db/User.js +++ b/src/db/User.js @@ -53,7 +53,7 @@ export const UserSchema = function (user) { export const User = db.model('users', { secureFields: { - password: USER_ENCRYPT, + password: process.env.USER_ENCRYPT || USER_ENCRYPT, fields: ['lyftToken', 'lyftPaymentInfo', 'uberPassword', 'uberToken', 'password', 'alexaUserId'] } }); diff --git a/src/db/db.js b/src/db/db.js index fb51722..729db6d 100644 --- a/src/db/db.js +++ b/src/db/db.js @@ -1,5 +1,5 @@ -const DB_CONFIG_OBJ = require('../../secret/config').DB_CONFIG_OBJ; import Stork from 'storkSQL'; +const DB_CONFIG_OBJ = process.env.DB_CONFIG_JSON ? JSON.parse(DB_CONFIG_JSON) : require('../../secret/config').DB_CONFIG_OBJ; const dbConnection = new Stork(DB_CONFIG_OBJ, 'pg'); export default dbConnection; diff --git a/src/server/server-configuration/hasValidAPIToken.js b/src/server/server-configuration/hasValidAPIToken.js index 7e2771f..ced3af7 100644 --- a/src/server/server-configuration/hasValidAPIToken.js +++ b/src/server/server-configuration/hasValidAPIToken.js @@ -1,9 +1,11 @@ import {CARVIS_API_KEY} from '../../../secret/config'; +let API_KEY = process.env.CARVIS_API_KEY ? process.env.CARVIS_API_KEY : CARVIS_API_KEY; + export default function(req, res, next) { console.log('checking validity'); const token = req.body.token || req.query.token || req.headers['x-access-token'] || null; - if (CARVIS_API_KEY.indexOf(token) >= 0) { + if (API_KEY.indexOf(token) >= 0) { next(); console.log('this is valid!'); } else { diff --git a/src/server/utils/lyft-helper.js b/src/server/utils/lyft-helper.js index 7513011..b70b554 100644 --- a/src/server/utils/lyft-helper.js +++ b/src/server/utils/lyft-helper.js @@ -1,8 +1,7 @@ var fetch = require('node-fetch'); var btoa = require('btoa'); var lyftMethods = require('./lyftPrivateMethods'); -var auth = require('../../../secret/config.js') - .LYFT_USER_ID; +var auth = process.env.LYFT_USER_ID || require('../../../secret/config.js').LYFT_USER_ID; var baseURL = 'https://api.lyft.com/v1/'; // on which path is added. // TODO: database posts in each response -- with generic key naming. diff --git a/src/server/utils/twilioHelper.js b/src/server/utils/twilioHelper.js index 831be39..03f11a8 100644 --- a/src/server/utils/twilioHelper.js +++ b/src/server/utils/twilioHelper.js @@ -1,4 +1,4 @@ -var twilioCredentials = require('../../../secret/config.js').twilioCredentials; +var twilioCredentials = JSON.parse(process.env.twilioCredentials) || require('../../../secret/config.js').twilioCredentials; var client = require('twilio')(twilioCredentials.accountSid, twilioCredentials.authToken); // NOTE: Twilio will only work with approved numbers on the free trial account, for now Chris' number is approved. From 5117331b697448f91c2c7d733adfed27a9ef3a3b Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Mon, 15 Aug 2016 16:56:09 -0700 Subject: [PATCH 10/13] add test for getting dev users --- .gitignore | 3 +- secret/config.js | 30 +++++++++++++++++++ src/db/User.js | 4 +-- src/server/routes.js | 2 +- src/server/server-configuration/config.js | 2 -- .../server-configuration/hasValidAPIToken.js | 4 +-- tests/index.js | 12 ++++++++ 7 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 secret/config.js diff --git a/.gitignore b/.gitignore index 167c2b4..f6f8872 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ ### node etc ### -secret + + work-stash # Logs diff --git a/secret/config.js b/secret/config.js new file mode 100644 index 0000000..0a1880d --- /dev/null +++ b/secret/config.js @@ -0,0 +1,30 @@ +// secret/config.js + +// Create a copy of this file called config.js and put your API keys there +module.exports = { + DB_CONFIG_OBJ: { + host: 'ec2-54-225-89-110.compute-1.amazonaws.com', + password: 'oRSQ_ftv16N6j73loVMTdwgbZW', + database: 'd2f7venevnjv5t', + port: 5432, + user: 'ecogqyqjcbbetg', + ssl: true + }, + UBER_SERVER_TOKEN: 'pG-f76yk_TFCTMHtYHhY7xUfLVwmt9u-l4gmgiHE', + GOOGLE_PLACES_API_KEY: 'AIzaSyDlX18NHXJ27_aZaXfpuABKe4B_ysOcoPA', + LYFT_BEARER_TOKEN: 'gAAAAABXqkmC1umTQbXVia0xRwloEZkq1ljy5eT1Mk2VfTuE6iMqkWeRDiTBXEmhlNuFUTpwJLu6zbEeRoACqnfp_uFZnpGAEROwnIm3nvV8QLAJD0jrGBGk8ErUgyMlytHXpJ0-cup_3aSv1TH3or368C34grkfSIkN3xbnrH7u6MsQMvHUXN8VJi8xbUNaMLK1Y9HMA51NXApOxhGUan2ZDTqop9UM2A==', + LYFT_USER_ID: 'gC8NlVZa847Y:PB3nRSO6pvd6SqV_85yr_hC-wgIDL0e-', + twilioCredentials: { + accountSid: 'ACbec44eaea12e629b07ccc6f5a8371836', + authToken: 'a3adbdb1e299c34ef0ac11e8cc859bfd' + }, + CARVIS_API: '54.183.205.82', + CARVIS_API_KEY: 'o2h3nrkjSDfQ@#rjlks2$TASjdfs', + USER_ENCRYPT: '239823jf' +}; + +/* +LYFT_BEARER_TOKEN currently hardcoded, needs to be updated every 86400 seconds. +TODO: update dynamically: +-- for updating one has to use the `refreshBearerToken` function from './../src/server/utils/lyft-helper.js'. +*/ diff --git a/src/db/User.js b/src/db/User.js index a50aa5d..2965db1 100644 --- a/src/db/User.js +++ b/src/db/User.js @@ -1,5 +1,5 @@ import db from './db'; -import {USER_ENCRYPT} from '../../secret/config'; + export const UserSchema = function (user) { user.increments('id') .primary(); @@ -53,7 +53,7 @@ export const UserSchema = function (user) { export const User = db.model('users', { secureFields: { - password: process.env.USER_ENCRYPT || USER_ENCRYPT, + password: process.env.USER_ENCRYPT || require('../../secret/config').USER_ENCRYPT, fields: ['lyftToken', 'lyftPaymentInfo', 'uberPassword', 'uberToken', 'password', 'alexaUserId'] } }); diff --git a/src/server/routes.js b/src/server/routes.js index 2fac85c..c6ff0d5 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -9,7 +9,7 @@ import hasValidAPIToken from './server-configuration/hasValidAPIToken'; export default function(app) { // TODO only let the user with that ID find users (middleware); app.get('/', (req, res) => { - res.status(200).send('Welcome to the Carvi API.'); + res.status(200).send('Welcome to the Carvis API.'); }); app.get('/users/:userid', getUserDashboardData); diff --git a/src/server/server-configuration/config.js b/src/server/server-configuration/config.js index 2da715b..5068c74 100644 --- a/src/server/server-configuration/config.js +++ b/src/server/server-configuration/config.js @@ -5,7 +5,6 @@ import bodyParser from 'body-parser'; import cookieParser from 'cookie-parser'; import cors from 'cors'; import morgan from 'morgan'; -import config from '../../../secret/config'; export const PORT = process.env.PORT || 8000; @@ -21,6 +20,5 @@ export const configureServer = function(app) { resave: true, saveUninitialized: true })); - app.set('tokenSecret', config.secret); app.use(morgan('dev')); }; diff --git a/src/server/server-configuration/hasValidAPIToken.js b/src/server/server-configuration/hasValidAPIToken.js index ced3af7..41f2a09 100644 --- a/src/server/server-configuration/hasValidAPIToken.js +++ b/src/server/server-configuration/hasValidAPIToken.js @@ -1,6 +1,4 @@ -import {CARVIS_API_KEY} from '../../../secret/config'; - -let API_KEY = process.env.CARVIS_API_KEY ? process.env.CARVIS_API_KEY : CARVIS_API_KEY; +const API_KEY = process.env.CARVIS_API_KEY ? process.env.CARVIS_API_KEY : require('../../../secret/config').CARVIS_API_KEY; export default function(req, res, next) { console.log('checking validity'); diff --git a/tests/index.js b/tests/index.js index ef31d94..ae2214e 100644 --- a/tests/index.js +++ b/tests/index.js @@ -20,6 +20,18 @@ describe('API server', function () { done(); }); }); + + describe('Check restful routes', function () { + it('should ', function (done) { + axios.get('http://localhost:3030/dev/users', { + headers: {'x-access-token': process.env.CARVIS_API_KEY || require('../secret/config').CARVIS_API_KEY} + }) + .then((res) => { + assert.equal(res.status, 200, 'did not return 200', res.status); + done(); + }); + }); + }); }); From 923185a8b02bdb1816067481a029e67ab7cd5249 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Mon, 15 Aug 2016 16:58:12 -0700 Subject: [PATCH 11/13] attempt to push using npm run setup --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index acb94d5..500d037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ install: - npm install script: - npm run build +- npm run setup - npm test From 73a86138b9e911bab057daccedce17a5fb3ac24c Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Mon, 15 Aug 2016 17:07:38 -0700 Subject: [PATCH 12/13] additional tests and handling private methods --- src/server/models/User.js | 6 ++++++ src/server/routes.js | 7 ++++++- src/server/utils/lyft-helper.js | 2 +- src/server/utils/uber-helper.js | 2 +- tests/index.js | 27 ++++++++++++++++++++++++++- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/server/models/User.js b/src/server/models/User.js index a2c9813..147331c 100644 --- a/src/server/models/User.js +++ b/src/server/models/User.js @@ -36,3 +36,9 @@ export const updateOrCreateUser = (req, res) => { .then((user) => res.json(user)) .catch((err) => res.json(err)); }; + +export const deleteUser = (req, res) => { + User.remove({id: req.params.userid}) + .then((user) => res.json(user)) + .catch((err) => res.json(err)); +}; diff --git a/src/server/routes.js b/src/server/routes.js index c6ff0d5..27c9c8f 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -1,5 +1,5 @@ import {getUserDashboardData, updateUserData, createUser, - getAllUserData, findOrCreateUser, updateOrCreateUser } from './models/User'; + getAllUserData, findOrCreateUser, updateOrCreateUser, deleteUser } from './models/User'; import {getRidesForUser, addRide, updateRide, getAllRideData, deleteRide} from './models/Ride'; import passport from 'passport'; // import passportService from './services/passport'; @@ -24,6 +24,9 @@ export default function(app) { app.put('/users/update/:userid', updateUserData); + app.delete('/dev/users/:userid', deleteUser); + + app.get('/dev/rides', getAllRideData); app.get('/rides/user/:userid', getRidesForUser); @@ -34,6 +37,8 @@ export default function(app) { app.delete('/rides/:rideid', deleteRide); + + // app.post('/signin', requireSignin, Authentication.signin); // app.post('/signup', Authentication.signup); diff --git a/src/server/utils/lyft-helper.js b/src/server/utils/lyft-helper.js index b70b554..d747c79 100644 --- a/src/server/utils/lyft-helper.js +++ b/src/server/utils/lyft-helper.js @@ -1,6 +1,6 @@ var fetch = require('node-fetch'); var btoa = require('btoa'); -var lyftMethods = require('./lyftPrivateMethods'); +var lyftMethods = !process.env.TRAVIS ? require('./lyftPrivateMethods') : null; var auth = process.env.LYFT_USER_ID || require('../../../secret/config.js').LYFT_USER_ID; var baseURL = 'https://api.lyft.com/v1/'; // on which path is added. diff --git a/src/server/utils/uber-helper.js b/src/server/utils/uber-helper.js index afa6a2b..d1a60b7 100644 --- a/src/server/utils/uber-helper.js +++ b/src/server/utils/uber-helper.js @@ -1,5 +1,5 @@ var fetch = require('node-fetch'); -var uberMethods = require('./uberPrivateMethods'); +var uberMethods = !process.env.TRAVIS ? require('./uberPrivateMethods') : null; var baseURL = 'https://cn-sjc1.uber.com'; // https ? var login = function(username, password) { diff --git a/tests/index.js b/tests/index.js index ae2214e..833fbc7 100644 --- a/tests/index.js +++ b/tests/index.js @@ -22,7 +22,8 @@ describe('API server', function () { }); describe('Check restful routes', function () { - it('should ', function (done) { + + it('should get all users when presented with the API access token', function (done) { axios.get('http://localhost:3030/dev/users', { headers: {'x-access-token': process.env.CARVIS_API_KEY || require('../secret/config').CARVIS_API_KEY} }) @@ -31,6 +32,30 @@ describe('API server', function () { done(); }); }); + + let testUserId; + + it('should allow a developer to add a user when presented with the right access token', function (done) { + axios.post('http://localhost:3030/dev/users', {email: 'test@gmail.com', password: 'test'}, { + headers: {'x-access-token': process.env.CARVIS_API_KEY || require('../secret/config').CARVIS_API_KEY} + }) + .then((res) => { + testUserId = res.data[0].id; + assert.equal(res.status, 200, 'did not return 200', res.status); + done(); + }); + }); + + it('should delete the user created by the developer', function (done) { + axios.delete('http://localhost:3030/dev/users/' + testUserId, { + headers: {'x-access-token': process.env.CARVIS_API_KEY || require('../secret/config').CARVIS_API_KEY} + }) + .then((res) => { + assert.equal(res.status, 200, 'did not return 200', res.status); + done(); + }); + }); + }); }); From e9b5aa66d813c5d472edfa1dd8e2a0987b044e69 Mon Sep 17 00:00:00 2001 From: Alex Stark Date: Mon, 15 Aug 2016 17:23:07 -0700 Subject: [PATCH 13/13] fix broken test --- .travis.yml | 1 - src/server/routes.js | 3 --- tests/index.js | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 500d037..acb94d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,4 @@ install: - npm install script: - npm run build -- npm run setup - npm test diff --git a/src/server/routes.js b/src/server/routes.js index 27c9c8f..997751f 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -26,7 +26,6 @@ export default function(app) { app.delete('/dev/users/:userid', deleteUser); - app.get('/dev/rides', getAllRideData); app.get('/rides/user/:userid', getRidesForUser); @@ -37,8 +36,6 @@ export default function(app) { app.delete('/rides/:rideid', deleteRide); - - // app.post('/signin', requireSignin, Authentication.signin); // app.post('/signup', Authentication.signup); diff --git a/tests/index.js b/tests/index.js index 833fbc7..ae51d43 100644 --- a/tests/index.js +++ b/tests/index.js @@ -36,7 +36,7 @@ describe('API server', function () { let testUserId; it('should allow a developer to add a user when presented with the right access token', function (done) { - axios.post('http://localhost:3030/dev/users', {email: 'test@gmail.com', password: 'test'}, { + axios.post('http://localhost:3030/dev/users', {email: 'testy@gmail.com', password: 'test'}, { headers: {'x-access-token': process.env.CARVIS_API_KEY || require('../secret/config').CARVIS_API_KEY} }) .then((res) => {