diff --git a/README.md b/README.md
index d13bb22..dd1e6f6 100644
--- a/README.md
+++ b/README.md
@@ -10,32 +10,17 @@ Two Mongoose Schema models are created (resources) to route and manipulate throu
##Dev dependencies
* Gulp
- * Gulp-Eslint
+ * gulp-protractor
+ * Webpack-stream
-### How to Use
-Run mongo ```mongod --dbpath=./db
+### How to test with protractor and selenium
+Run a gulp command to bundle build, start server and run selenium and protractor:
```
-Run ```node index
-``` to start the client and backend servers.
-Go to ```localhost:5000```
-
-## Slugs and Rabbits
-Enter Name, Type and Food in the test fields and click the update Slug or update Rabbit buttons.
-
-New entry will display in url.
-Example:
-```http://localhost:5000/?name=Sven&type=black&food=leaf
+gulp
```
-
-### Database
-See slugs by posting to localhost:4020/api/slugs
-
-The databases is located at ```localhost:4020
+or
```
-
-```/api/rabbits
-``` and ```/api/slugs
+npm start
```
-The angular app is located at ```localhost:5000
-```
+*Bella - the only concern I have for you running this, is the server I'm using for mongo in gulp is from my rest_api and I'm not sure it will exist for you? I followed Tyler's code on this. Please let me know if it's a problem and if you have any suggestions...
diff --git a/app/index.html b/app/index.html
index e9966d6..f3067ac 100644
--- a/app/index.html
+++ b/app/index.html
@@ -1,64 +1,14 @@
-
+
-
- Slug and Rabbit dance off!
-
+
+ Stuff
+
-
-
-
-
-
-
- {{slug.name}}, {{slug.type}}, eats: {{slug.food}}
-
-
-
-
-
-
-
-
-
-
-
-
- {{rabbit.name}}, {{rabbit.type}}, eats: {{rabbit.food}}
-
-
-
-
-
-
-
-
-
+
+ {{greeting}}
+
+
-
diff --git a/app/js/entry.js b/app/js/entry.js
index b228897..ee3a083 100644
--- a/app/js/entry.js
+++ b/app/js/entry.js
@@ -1,65 +1,2 @@
const angular = require('angular');
-const myApp = angular.module('myApp', []);
-const baseUrl = 'http://localhost:5000';
-
-var handleErrors = function(error) {
- console.log(error);
- this.errors = (this.errors || []).push(error);
-};
-
-myApp.controller('SlugController', ['$http', function($http) {
- this.slug = [];
- this.getAll = () => {
- $http.get(baseUrl + '/api/slugs')
- .then((res) => {
- this.slug = res.data;
- }, handleErrors.bind(this));
- };
-
- this.createSlug = () => {
- $http.post(baseUrl + '/api/slugs', this.newSlug)
- .then((res) => {
- this.slug.push(res.data);
- this.newSlug = null;
- }, handleErrors.bind(this));
- };
-
- this.updateSlug = (slug) => {
- $http.put(baseUrl + '/api/slugs' + slug._id, slug)
- .then(() => {
- slug.editing = false;
- }, handleErrors.bind(this));
- };
-}]);
-
-myApp.controller('RabbitController', ['$http', function($http) {
- this.rabbit = [];
- this.getAll = () => {
- $http.get(baseUrl + '/api/rabbits')
- .then((res) => {
- this.rabbit = res.data;
- }, handleErrors.bind(this));
- };
-
- this.createRabbit = () => {
- $http.post(baseUrl + '/api/rabbits', this.newRabbit)
- .then((res) => {
- this.rabbit.push(res.data);
- this.newRabbit = null;
- }, handleErrors.bind(this));
- };
-
- this.updateRabbit = (rabbit) => {
- $http.put(baseUrl + '/api/rabbits' + rabbit._id, rabbit)
- .then(() => {
- this.rabbit.splice(this.rabbit.indexOf(rabbit), 1);
- }, handleErrors.bind(this));
- };
-
- this.deleteRabbit = (rabbit) => {
- $http.delete(baseUrl + '/api/rabbits/' + rabbit._id)
- .then(() => {
- this.rabbit.splice(this.rabbit.indexOf(rabbit), 1);
- }, handleErrors.bind(this));
- };
-}]);
+const demoApp = angular.module('demoApp', []);
diff --git a/client_server.js b/client_server.js
deleted file mode 100644
index cd51cc2..0000000
--- a/client_server.js
+++ /dev/null
@@ -1,2 +0,0 @@
-const express = require('express');
-express().use(express.static(__dirname + '/build')).listen(5000, () => console.log('server up'));
diff --git a/gulpfile.js b/gulpfile.js
index 285408b..a79fcc2 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,33 +1,14 @@
-var gulp = require('gulp');
-var eslint = require('gulp-eslint');
-var webpack = require('webpack-stream');
+const gulp = require('gulp');
+const webpack = require('webpack-stream');
+const nodemon = require('gulp-nodemon');
+const cp = require('child_process');
+const exec = require('child_process').exec;
+const protractor = require('gulp-protractor').protractor;
+const mongoUri = 'mongodb://localhost/test_server';
+var children = [];
-var path = {
- scripts: ['client_server.js', 'index.js', 'router/**/*.js',
-'models/**/*.js', 'gulpfile.js'],
- tests: [__dirname + '/test/server-test.js'],
- client: ['app/js/entry.js']
-};
-
-gulp.task('lintServer', () => {
- return gulp.src(path.scripts)
- .pipe(eslint({
- envs: [
- 'mocha',
- 'es6'
- ]
- }))
- .pipe(eslint.format());
-});
-
-gulp.task('lintClient', () => {
- return gulp.src(path.client)
- .pipe(eslint('./app/.eslintrc'))
- .pipe(eslint.format());
-});
-
-gulp.task('entry', () => {
- return gulp.src('app/js/entry.js')
+gulp.task('webpack:dev', () => {
+ gulp.src('./app/js/entry.js')
.pipe(webpack({
output: {
filename: 'bundle.js'
@@ -36,11 +17,34 @@ gulp.task('entry', () => {
.pipe(gulp.dest('./build'));
});
-gulp.task('html', () => {
- return gulp.src('app/**/*.html')
+gulp.task('static:dev', () => {
+ gulp.src('app/**/*.html')
.pipe(gulp.dest('./build'));
});
-gulp.task('lint', ['lintServer', 'lintClient']);
-gulp.task('build', ['entry', 'html']);
-gulp.task('default', ['build', 'lint']);
+gulp.task('css:dev', () => {
+ gulp.src('app/css/*.css')
+ .pipe(gulp.dest('./build'));
+});
+
+gulp.task('startservers:test', ['webpack:dev', 'static:dev', 'css:dev'], () => {
+ children.push(cp.fork('server.js'));
+ children.push(cp.spawn('webdriver-manager', ['start']));
+ children.push(cp.spawn('mongod', ['--dbpath=./db']));
+ children.push(cp.fork('../../week_3//rest_api/heidilaursen/server/server.js', [], {env: {MONGO_URI: mongoUri}}));
+});
+
+gulp.task('protractor', ['startservers:test'], () => {
+ gulp.src(['./test/*spec.js'])
+ .pipe(protractor({
+ configFile: 'test/config.js',
+ args: ['--baseUrl', 'http:127.0.0.1:5000']
+ }))
+ .on('end', () => {
+ children.forEach((child) => {
+ child.kill('SIGTERM');
+ });
+ });
+});
+
+gulp.task('default', ['protractor']);
diff --git a/index.js b/index.js
deleted file mode 100644
index 8ced9a3..0000000
--- a/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-require(__dirname + '/server.js');
-require(__dirname + '/client_server.js');
diff --git a/lib/basic_http.js b/lib/basic_http.js
deleted file mode 100644
index a50096b..0000000
--- a/lib/basic_http.js
+++ /dev/null
@@ -1,21 +0,0 @@
-module.exports = exports = function(req, res, next) {
- try {
- var authHeader = req.headers.authorization;
- var namePassword = authHeader.split(' ')[1];
- var namePassBuf = new Buffer(namePassword, 'base64');
- var namePassPT = namePassBuf.toString();
- namePassBuf.fill(0);
- var namePassArr = namePassPT.split(':');
- req.auth = {
- username: namePassArr[0],
- password: namePassArr[1]
- };
- if (req.auth.username.length < 1 || req.auth.password.length < 1) {
- throw new Error('no username or password');
- }
- } catch (e) {
- console.log(e);
- return res.status(418).json({ msg: 'not working' });
- }
- next();
-};
diff --git a/lib/errorHandler.js b/lib/errorHandler.js
deleted file mode 100644
index 426906e..0000000
--- a/lib/errorHandler.js
+++ /dev/null
@@ -1,4 +0,0 @@
-module.exports = function(err, res) {
- console.log(err);
- res.status(500).json({ msg: 'server error' });
-};
diff --git a/lib/jwt_auth.js b/lib/jwt_auth.js
deleted file mode 100644
index 6dda543..0000000
--- a/lib/jwt_auth.js
+++ /dev/null
@@ -1,19 +0,0 @@
-const User = require(__dirname + '/../models/user');
-const jwt = require('jsonwebtoken');
-
-/*eslint-disable */
-module.exports = exports = function(req, res, next) {
- jwt.verify(req.headers.token, process.env.APP_SECRET, function(err, decoded) {
- if (err) return res.status(403).json({ msg: 'could not authenticat' });
-
- User.findOne({ findHash: decoded.idd }, function(err, data) {
- if (err) return res.status(403).json({ msg: 'could not authenticat' });
-
- if (!data) return res.status(403).json({ msg: 'could not authenticat' });
-
- req.user = data;
- next();
- });
- });
-};
-/*eslint-enable */
diff --git a/models/rabbit.js b/models/rabbit.js
deleted file mode 100644
index c654586..0000000
--- a/models/rabbit.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const mongoose = require('mongoose');
-
-var rabbitSchema = new mongoose.Schema({
- name: { type: String, unique: true },
- variety: { type: String },
- food: { type: String, default: 'parsley' }
-});
-
-module.exports = exports = mongoose.model('Rabbit', rabbitSchema);
diff --git a/models/slug.js b/models/slug.js
deleted file mode 100644
index b017453..0000000
--- a/models/slug.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const mongoose = require('mongoose');
-
-var slugSchema = new mongoose.Schema({
- name: { type: String, unique: true },
- variety: { type: String },
- food: { type: String, default: 'spinach' }
-});
-
-module.exports = exports = mongoose.model('Slug', slugSchema);
diff --git a/package.json b/package.json
index d92fbb2..83a82c2 100644
--- a/package.json
+++ b/package.json
@@ -1,41 +1,21 @@
{
- "name": "heidilaursen",
+ "name": "week_6",
"version": "1.0.0",
- "description": "Express api with REST and two Mongo databases. ",
- "main": "node index.js",
- "directories": {
- "test": "test"
- },
+ "description": "",
+ "main": "gulpfile.js",
"scripts": {
- "test": " ./node_modules/mocha/bin/mocha test",
- "start": "node index.js'"
- },
- "repository": {
- "type": "git",
- "url": "https://github.com/pnwlady/rest_api.git"
+ "test": "echo \"Error: no test specified\" && exit 1",
+ "start": "gulp"
},
- "keywords": [
- "REST",
- "Express",
- "Mongodb"
- ],
- "author": "Heidi Laursen",
+ "author": "",
"license": "MIT",
- "bugs": {
- "url": "https://github.com/pnwlady/rest_api/issues"
- },
- "homepage": "https://github.com/pnwlady/rest_api#readme",
"dependencies": {
- "body-parser": "^1.15.0",
- "express": "^4.13.4",
- "mongodb": "^2.1.16",
- "mongoose": "^4.4.13"
+ "express": "^4.13.4"
},
"devDependencies": {
"angular": "^1.5.5",
"gulp": "^3.9.1",
- "gulp-eslint": "^2.0.0",
- "gulp-protractor": "^2.3.0",
+ "gulp-protractor": "^2.4.0",
"webpack-stream": "^3.2.0"
}
}
diff --git a/router/rabbitRouter.js b/router/rabbitRouter.js
deleted file mode 100644
index 2a86a86..0000000
--- a/router/rabbitRouter.js
+++ /dev/null
@@ -1,36 +0,0 @@
-const Router = require('express').Router;
-const Rabbit = require(__dirname + '/../models/rabbit');
-const bodyParser = require('body-parser').json();
-const serverErrorHandler = require(__dirname + '/../lib/errorHandler');
-const rabbitRouter = module.exports = new Router();
-
-rabbitRouter.post('/rabbits', bodyParser, (req, res) => {
- var newRabbit = new Rabbit(req.body);
- newRabbit.save((err, data) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json(data);
- });
-});
-
-rabbitRouter.get('/rabbits', (req, res) => {
- Rabbit.find({}, (err, data) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json(data);
- });
-});
-
-rabbitRouter.put('/rabbits/:id', bodyParser, (req, res) => {
- var rabbitData = req.body;
- delete rabbitData._id;
- Rabbit.update({ _id: req.params.id }, rabbitData, (err, data) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json(data);
- });
-});
-
-rabbitRouter.delete('/rabbits/:id', (req, res) => {
- Rabbit.remove({ _id: req.params.id }, (err) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json({ msg: 'the rabbits gone' });
- });
-});
diff --git a/router/slugRouter.js b/router/slugRouter.js
deleted file mode 100644
index 3eb3fd4..0000000
--- a/router/slugRouter.js
+++ /dev/null
@@ -1,36 +0,0 @@
-const Router = require('express').Router;
-const Slug = require(__dirname + '/../models/slug');
-const bodyParser = require('body-parser').json();
-const serverErrorHandler = require(__dirname + '/../lib/errorHandler');
-const slugRouter = module.exports = new Router();
-
-slugRouter.post('/slugs', bodyParser, (req, res) => {
- var newSlug = new Slug(req.body);
- newSlug.save((err) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json({ msg: 'great job!' });
- });
-});
-
-slugRouter.get('/slugs', (req, res) => {
- Slug.find(null, (err, data) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json(data);
- });
-});
-
-slugRouter.put('/slugs/:id', bodyParser, (req, res) => {
- var slugData = req.body;
- delete slugData._id;
- Slug.update({ _id: req.params.id }, slugData, (err, data) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json(data);
- });
-});
-
-slugRouter.delete('/slugs/:id', (req, res) => {
- Slug.remove({ _id: req.params.id }, (err) => {
- if (err) return serverErrorHandler(err, res);
- res.status(200).json({ msg: 'the slugs are gone' });
- });
-});
diff --git a/server.js b/server.js
index 4cdef26..2015f70 100644
--- a/server.js
+++ b/server.js
@@ -1,25 +1 @@
-const express = require('express');
-const app = express();
-const PORT = process.env.PORT || 3000;
-const rabbitRouter = require(__dirname + '/router/rabbitRouter');
-const slugRouter = require(__dirname + '/router/slugRouter');
-const mongoose = require('mongoose');
-
-mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/slug_rabbit_db');
-
-app.use('/api', rabbitRouter);
-app.use('/api', slugRouter);
-
-module.exports = exports = {
- server: { close: function() { throw new Error('server not started yet'); } },
- listen: function(port, mongoString, cb) {
- mongoose.connect(mongoString);
- return this.server = app.listen(port, cb);
- },
- close: function(cb) {
- this.server.close();
- if (cb) cb();
- }
-};
-
-app.listen(PORT, () => {console.log('server up on ' + PORT);});
+const express = require('express')().use(require('express').static(__dirname + '/build')).listen(4020, () => { console.log('server up'); });
diff --git a/test/ang-spec.js b/test/ang-spec.js
new file mode 100644
index 0000000..bf6c6c7
--- /dev/null
+++ b/test/ang-spec.js
@@ -0,0 +1,9 @@
+describe('our super awesome angular app', function() {
+ it('should have a 2 way data binding', () => {
+ browser.get('http://localhost:4030');
+ element(by.model('greeting')).sendKeys('hello world');
+ element(by.id('greeting')).getText().then(function(text) {
+ expect(text).toEqual('hello world');
+ });
+ });
+});
diff --git a/test/config.js b/test/config.js
new file mode 100644
index 0000000..465d79c
--- /dev/null
+++ b/test/config.js
@@ -0,0 +1,4 @@
+exports.config = {
+ seleniumAddress: 'http://localhost:4444/wd/hub',
+ specs: ['ang-spec.js']
+};