├── .babelrc ├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── gulpfile.js ├── package.json ├── src ├── controllers │ └── userController.js ├── index.js ├── models │ └── usersModel.js ├── routes │ └── users.js └── services │ └── db.js ├── tests └── index-spec.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015","stage-0"] 3 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | "sourceType": "module" 5 | }, 6 | "rules": { 7 | // disable requiring trailing commas because it might be nice to revert to 8 | // being JSON at some point, and I don't want to make big changes now. 9 | "comma-dangle": 0, 10 | "indent":2 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # Webstorm 36 | .idea 37 | 38 | # Build 39 | dist -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Just a another express api 2 | 3 | ## Features 4 | 5 | * Webpack Build Ready 6 | * Babel & ES2015 7 | * Mongoose 8 | * Mocha for tests 9 | * ESlint 10 | 11 | ## Install 12 | ``` 13 | npm install 14 | ``` 15 | 16 | ## Scripts 17 | 18 | #### Start the project for development 19 | ``` 20 | npm run dev 21 | ``` 22 | 23 | #### Run All tests 24 | ``` 25 | npm test 26 | ``` 27 | 28 | #### Run ESlint 29 | ``` 30 | npm run lint 31 | ``` 32 | 33 | #### Remove dist and tmp 34 | ``` 35 | npm run clean 36 | ``` 37 | 38 | #### Build the API for production 39 | ``` 40 | npm run webpack 41 | ``` 42 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var zip = require('gulp-zip'); 3 | var del = require('del'); 4 | var install = require('gulp-install'); 5 | var runSequence = require('run-sequence'); 6 | var awsLambda = require("node-aws-lambda"); 7 | var bump = require('gulp-bump'); 8 | 9 | var gulp = require('gulp'); 10 | require('gulp-release-it')(gulp); 11 | 12 | gulp.task('bump', function(){ 13 | gulp.src('./package.json') 14 | .pipe(bump({key: "version"})) 15 | .pipe(gulp.dest('./')); 16 | }); 17 | 18 | gulp.task('modules', function() { 19 | return gulp.src('./package.json') 20 | .pipe(gulp.dest('dist/')) 21 | .pipe(install({production: true})); 22 | }); 23 | 24 | gulp.task('zip', function() { 25 | return gulp.src(['dist/**/*', '!dist/package.json']) 26 | .pipe(zip('./tmp/dist.zip')) 27 | .pipe(gulp.dest('./')); 28 | }); 29 | 30 | gulp.task('upload', function(callback) { 31 | awsLambda.deploy('./tmp/dist.zip', require('./config/'+process.env.APP), callback); 32 | }); 33 | 34 | gulp.task('deploy', function(callback) { 35 | return runSequence( 36 | ['modules'], 37 | ['zip'], 38 | ['upload'], 39 | callback 40 | ); 41 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basic-api", 3 | "version": "0.1.0", 4 | "description": "A Boilerplate Express/ES2015/Mocha/MongoDB API", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "clean": "rm -rf dist && rm -rf tmp", 11 | "webpack": "NODE_ENV=production webpack -p", 12 | "dev": "./node_modules/.bin/nodemon src/index.js --exec ./node_modules/.bin/babel-node --presets es2015,stage-0", 13 | "test": "mocha ./tests/* --compilers js:babel-register", 14 | "lint": "eslint src --ignore-path ./src/boot/import-data.js" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/dbuarque/basic-api.git" 19 | }, 20 | "keywords": [ 21 | "express", 22 | "mocha", 23 | "es2015", 24 | "es6", 25 | "babel" 26 | ], 27 | "author": "Diogenes Ianakiara", 28 | "license": "ISC", 29 | "bugs": { 30 | "url": "https://github.com/dbuarque/basic-api/issues" 31 | }, 32 | "homepage": "https://github.com/dbuarque/basic-api#readme", 33 | "devDependencies": { 34 | "babel-cli": "^6.5.1", 35 | "babel-core": "^6.5.2", 36 | "babel-loader": "^6.2.3", 37 | "babel-polyfill": "^6.5.0", 38 | "babel-preset-es2015": "^6.3.13", 39 | "babel-preset-stage-0": "^6.3.13", 40 | "babel-register": "^6.5.2", 41 | "debug": "^2.2.0", 42 | "del": "^2.2.0", 43 | "eslint": "^2.2.0", 44 | "json-loader": "^0.5.4", 45 | "mocha": "^2.4.5", 46 | "nodemon": "^1.8.1", 47 | "should": "^8.2.0", 48 | "source-list-map": "^0.1.5", 49 | "source-map": "^0.5.3", 50 | "supertest": "^1.2.0", 51 | "webpack": "^1.12.13" 52 | }, 53 | "dependencies": { 54 | "body-parser": "^1.15.0", 55 | "compression": "^1.6.1", 56 | "connect": "^3.4.1", 57 | "express": "^4.13.4", 58 | "jfs": "^0.2.6", 59 | "mongodb": "^2.1.7", 60 | "mongoose": "^4.4.5" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/controllers/userController.js: -------------------------------------------------------------------------------- 1 | import Users from '../models/usersModel'; 2 | 3 | /** 4 | * userController.js 5 | * 6 | * @description :: Server-side logic for managing users. 7 | */ 8 | module.exports = { 9 | 10 | /** 11 | * userController.search() 12 | */ 13 | search: function (req, res) { 14 | let q = req.query.q; 15 | Users.find({ $text: { $search: q } }, function(err, users) { 16 | if(err) { 17 | return res.status(500).json({ 18 | message: 'Error on search.' 19 | }); 20 | } 21 | return res.json(users); 22 | }); 23 | }, 24 | 25 | 26 | /** 27 | * userController.list() 28 | */ 29 | list: function(req, res) { 30 | Users.find(function(err, users){ 31 | if(err) { 32 | return res.status(500).json({ 33 | message: 'Error getting user.' 34 | }); 35 | } 36 | return res.json(users); 37 | }); 38 | }, 39 | 40 | /** 41 | * userController.show() 42 | */ 43 | show: function(req, res) { 44 | var id = req.params.id; 45 | Users.findOne({_id: id}, function(err, user){ 46 | if(err) { 47 | return res.status(500).json({ 48 | message: 'Error getting user.' 49 | }); 50 | } 51 | if(!user) { 52 | return res.status(404).json( { 53 | message: 'No such user' 54 | }); 55 | } 56 | return res.json(user); 57 | }); 58 | }, 59 | 60 | /** 61 | * userController.create() 62 | */ 63 | create: function(req, res) { 64 | var user = new Users(req.body); 65 | 66 | user.save(function(err, user){ 67 | if(err) { 68 | return res.status(500).json( { 69 | message: 'Error saving user', 70 | error: err 71 | }); 72 | } 73 | return res.json({ 74 | message: 'saved', 75 | _id: user._id 76 | }); 77 | }); 78 | }, 79 | 80 | /** 81 | * userController.update() 82 | */ 83 | update: function(req, res) { 84 | console.log(req.body.email) 85 | var id = req.params.id; 86 | Users.findOne({_id: id}, function(err, user){ 87 | if(err) { 88 | return res.status(500).json({ 89 | message: 'Error saving user', 90 | error: err 91 | }); 92 | } 93 | if(!user) { 94 | return res.status(404).json({ 95 | message: 'No such user' 96 | }); 97 | } 98 | 99 | user.gender = req.body.gender; 100 | user.email = req.body.email ? req.body.email : user.email; 101 | user.username = req.body.username; 102 | user.password = req.body.password; 103 | user.salt = req.body.salt; 104 | user.md5 = req.body.md5; 105 | user.sha1 = req.body.sha1; 106 | user.sha256 = req.body.sha256; 107 | user.registered = req.body.registered; 108 | user.dob = req.body.dob; 109 | user.phone = req.body.phone; 110 | user.cell = req.body.cell; 111 | user.PPS = req.body.PPS; 112 | user.picture = req.body.picture; 113 | 114 | user.save(function(err, user){ 115 | if(err) { 116 | return res.status(500).json({ 117 | message: 'Error getting user.' 118 | }); 119 | } 120 | if(!user) { 121 | return res.status(404).json({ 122 | message: 'No such user' 123 | }); 124 | } 125 | return res.json(user); 126 | }); 127 | }); 128 | }, 129 | 130 | /** 131 | * userController.remove() 132 | */ 133 | remove: function(req, res) { 134 | var id = req.params.id; 135 | Users.findByIdAndRemove(id, function(err, user){ 136 | if(err) { 137 | return res.json(500, { 138 | message: 'Error getting user.' 139 | }); 140 | } 141 | return res.json(user); 142 | }); 143 | } 144 | }; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import compression from 'compression'; 3 | 4 | import db from './services/db' 5 | import users from './routes/users'; 6 | import bodyParser from 'body-parser'; 7 | 8 | 9 | var app = express(); 10 | 11 | app.use(bodyParser.json()); 12 | app.use(users); 13 | 14 | var server = app.listen(3000, function () { 15 | console.log('Listening on port 3000!'); 16 | }); 17 | 18 | module.exports = server; -------------------------------------------------------------------------------- /src/models/usersModel.js: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | 3 | let userSchema = new mongoose.Schema({ 4 | "gender": String, 5 | "name": { 6 | "title": String, 7 | "first": String, 8 | "last": String 9 | }, 10 | "location": { 11 | "street": String, 12 | "city": String, 13 | "state": String, 14 | "zip": Number 15 | }, 16 | "email": String, 17 | "username": String, 18 | "password": String, 19 | "salt": String, 20 | "md5": String, 21 | "sha1": String, 22 | "sha256": String, 23 | "registered": Number, 24 | "dob": Number, 25 | "phone": String, 26 | "cell": String, 27 | "PPS": String, 28 | "picture": { 29 | "large": String, 30 | "medium": String, 31 | "thumbnail": String 32 | } 33 | }); 34 | 35 | module.exports = mongoose.model('users', userSchema); -------------------------------------------------------------------------------- /src/routes/users.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import userController from '../controllers/userController.js' 3 | 4 | let router = express.Router(); 5 | 6 | /* 7 | * GET 8 | */ 9 | router.get('/search', function(req, res) { 10 | userController.search(req, res); 11 | }); 12 | 13 | /* 14 | * GET 15 | */ 16 | router.get('/', function(req, res) { 17 | userController.list(req, res); 18 | }); 19 | 20 | /* 21 | * GET 22 | */ 23 | router.get('/:id', function(req, res) { 24 | userController.show(req, res); 25 | }); 26 | 27 | /* 28 | * POST 29 | */ 30 | router.post('/', function(req, res) { 31 | userController.create(req, res); 32 | }); 33 | 34 | /* 35 | * POST 36 | */ 37 | router.post('/:id', function(req, res) { 38 | userController.update(req, res); 39 | }); 40 | 41 | /* 42 | * DELETE 43 | */ 44 | router.delete('/:id', function(req, res) { 45 | userController.remove(req, res); 46 | }); 47 | 48 | 49 | 50 | module.exports = router; -------------------------------------------------------------------------------- /src/services/db.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by dbuarque on 2/24/16. 3 | */ 4 | // Bring Mongoose into the app 5 | import mongoose from 'mongoose'; 6 | 7 | const MONGO_URL = process.env.MONGO_URL || 'mongodb://localhost/basicapi'; 8 | 9 | mongoose.connect(MONGO_URL); 10 | 11 | mongoose.connection.on('connected', function () { 12 | console.log('Mongoose default connection open to ' + MONGO_URL); 13 | }); 14 | 15 | mongoose.connection.on('error',function (err) { 16 | console.log('Mongoose default connection error: ' + err); 17 | }); 18 | 19 | mongoose.connection.on('disconnected', function () { 20 | console.log('Mongoose default connection disconnected'); 21 | }); 22 | 23 | process.on('SIGINT', function() { 24 | mongoose.connection.close(function () { 25 | console.log('Mongoose default connection disconnected through app termination'); 26 | process.exit(0); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /tests/index-spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const should = require('should'); 4 | const util = require('util'); 5 | 6 | describe('api', function() { 7 | }); 8 | var request = require('supertest'), 9 | express = require('express'); 10 | 11 | var app = require('../src/index'); 12 | 13 | describe('Create a user', function(){ 14 | it('responds with a json success message', function(done){ 15 | request(app) 16 | .post('/users') 17 | .set('Accept', 'application/json') 18 | .expect('Content-Type', /json/) 19 | .send( 20 | { 21 | "gender": "female", 22 | "email": "alison.reid@example2.com", 23 | "username": "2", 24 | "password": "rockon", 25 | "salt": "lypI10wj", 26 | "md5": "bbdd6140e188e3bf68ae7ae67345df65", 27 | "sha1": "4572d25c99aa65bbf0368168f65d9770b7cacfe6", 28 | "sha256": "ec0705aec7393e2269d4593f248e649400d4879b2209f11bb2e012628115a4eb", 29 | "registered": 1237176893, 30 | "dob": 932871968, 31 | "phone": "031-541-9181", 32 | "cell": "081-647-4650", 33 | "PPS": "3302243T", 34 | "picture": { 35 | "large": "https://randomuser.me/api/portraits/women/60.jpg", 36 | "medium": "https://randomuser.me/api/portraits/med/women/60.jpg", 37 | "thumbnail": "https://randomuser.me/api/portraits/thumb/women/60.jpg" 38 | } 39 | } 40 | ) 41 | .expect(200, done); 42 | }); 43 | }); 44 | 45 | 46 | describe('Update a user', function(){ 47 | it('responds with a json success message', function(done){ 48 | request(app) 49 | .post('/users/56ce57d50066d66e12498bda') 50 | .set('Accept', 'application/json') 51 | .expect('Content-Type', /json/) 52 | .send( 53 | { 54 | "gender": "female", 55 | "email": "alison.reid@abc.com", 56 | "username": "xxxxxxx", 57 | "password": "rockon!", 58 | "salt": "lypI10wj", 59 | "md5": "xxxxxx", 60 | "sha1": "xxx", 61 | "sha256": "xxxxxxxxx", 62 | "registered": 1234123123, 63 | "dob": 932871968, 64 | "phone": "031-541-9181", 65 | "cell": "081-647-4650", 66 | "PPS": "3302243T", 67 | "picture": { 68 | "large": "https://randomuser.me/api/portraits/women/60.jpg", 69 | "medium": "https://randomuser.me/api/portraits/med/women/60.jpg", 70 | "thumbnail": "https://randomuser.me/api/portraits/thumb/women/60.jpg" 71 | } 72 | } 73 | ) 74 | .expect(200, done); 75 | }); 76 | }); 77 | 78 | describe('List Users', function(){ 79 | it('responds with a list of users in JSON', function(done){ 80 | request(app) 81 | .get('/users') 82 | .set('Accept', 'application/json') 83 | .expect('Content-Type', /json/) 84 | .expect(200, done); 85 | }); 86 | }); 87 | 88 | describe('Get a User', function(){ 89 | it('responds with a single todo item in JSON based on the author', function(done){ 90 | request(app) 91 | .get('/users/56ce57d50066d66e12498bda') 92 | .set('Accept', 'application/json') 93 | .expect('Content-Type', /json/) 94 | .expect(200, done); 95 | }); 96 | }); 97 | 98 | 99 | describe('Search a User', function(){ 100 | it('responds with a single todo item in JSON based on the author', function(done){ 101 | request(app) 102 | .get('/users/search?q=silvergorilla666') 103 | .set('Accept', 'application/json') 104 | .expect('Content-Type', /json/) 105 | .expect(200, done); 106 | }); 107 | }); 108 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by dbuarque on 2/24/16. 3 | */ 4 | const webpack = require('webpack'); 5 | 6 | var path = require('path'); 7 | 8 | module.exports = { 9 | devtool: 'cheap-module-source-map', 10 | target: 'node', 11 | entry: './src/index.js', 12 | output: { 13 | path: './dist', 14 | filename: 'index.js' 15 | }, 16 | resolve: { 17 | extensions: [ '', '.js', '.json' ] 18 | }, 19 | module: { 20 | noParse: /node_modules\/json-schema\/lib\/validate\.js/, 21 | loaders: [ 22 | { 23 | test: /\.js$/, 24 | loader: 'babel-loader', 25 | exclude: /node_modules/, 26 | query: { 27 | presets: ['es2015', 'stage-0'] 28 | } 29 | }, 30 | { 31 | test: /\.json$/, 32 | loader: "json-loader" 33 | } 34 | ] 35 | }, 36 | plugins: [ 37 | new webpack.DefinePlugin({ 38 | 'process.env': { 39 | 'NODE_ENV': JSON.stringify('production') 40 | } 41 | }) 42 | ], 43 | }; --------------------------------------------------------------------------------