From ac77c9d2eadb9d81a5259bf7ba30d99b9b13676a Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 14 Jun 2016 15:05:08 -0700 Subject: [PATCH 01/41] Set up basic controller structure for customers and tested out our code on a similar index controller --- app.js | 7 +++++-- controllers/customers.js | 7 +++++++ controllers/index.js | 7 +++++++ routes/customers.js | 8 ++++++++ routes/index.js | 7 +++++-- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 controllers/customers.js create mode 100644 controllers/index.js create mode 100644 routes/customers.js diff --git a/app.js b/app.js index f0579b1dc..ef85cf28d 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,6 @@ var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); -var routes = require('./routes/index'); var app = express(); @@ -21,7 +20,11 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); -app.use('/', routes); +var indexRoutes = require('./routes/index'); +app.use('/', indexRoutes); + +var customerRoutes = require('./routes/customers'); +app.use('/customers', customerRoutes); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/controllers/customers.js b/controllers/customers.js new file mode 100644 index 000000000..cfa099b41 --- /dev/null +++ b/controllers/customers.js @@ -0,0 +1,7 @@ +var CustomerController = { + index: function(req, res, next) { + // res.json(); + } +}; + +module.exports = CustomerController; diff --git a/controllers/index.js b/controllers/index.js new file mode 100644 index 000000000..f04ddf04b --- /dev/null +++ b/controllers/index.js @@ -0,0 +1,7 @@ +var IndexController = { + index: function(req, res, next) { + res.json('It works!!'); + } +}; + +module.exports = IndexController; diff --git a/routes/customers.js b/routes/customers.js new file mode 100644 index 000000000..b150b59b0 --- /dev/null +++ b/routes/customers.js @@ -0,0 +1,8 @@ +var express = require('express'); +var router = express.Router(); +var CustomerController = require('../controllers/customers'); + +/* GET home page. */ +router.get('/', CustomerController.index); + +module.exports = router; diff --git a/routes/index.js b/routes/index.js index 06cfc1137..4e4d54247 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,9 +1,12 @@ var express = require('express'); var router = express.Router(); +var IndexController = require('../controllers/index.js'); /* GET home page. */ -router.get('/', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) +router.get('/zomg', function(req, res, next) { + res.status(200).json({whatevs: 'whatevs!!!'}); }); +router.get('/stuff', IndexController.index); + module.exports = router; From 060d1a6f952c5ebb5f99c8c1ce265df46bb37402 Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 14 Jun 2016 16:11:32 -0700 Subject: [PATCH 02/41] Created other controller bases and added massive as a dependency --- app.js | 10 ++++++++++ controllers/movies.js | 0 controllers/rentals.js | 0 package.json | 1 + 4 files changed, 11 insertions(+) create mode 100644 controllers/movies.js create mode 100644 controllers/rentals.js diff --git a/app.js b/app.js index ef85cf28d..747e8b41f 100644 --- a/app.js +++ b/app.js @@ -26,6 +26,16 @@ app.use('/', indexRoutes); var customerRoutes = require('./routes/customers'); app.use('/customers', customerRoutes); +var movieRoutes = require('./routes/movies'); +app.use('/movies', movieRoutes); + +var rentalRoutes = require('./routes/rentals'); +app.use('/rentals', rentalRoutes); + + + + + // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); diff --git a/controllers/movies.js b/controllers/movies.js new file mode 100644 index 000000000..e69de29bb diff --git a/controllers/rentals.js b/controllers/rentals.js new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index d39b26403..404578a7a 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "debug": "~2.2.0", "express": "~4.13.1", "jade": "~1.11.0", + "massive": "^2.3.0", "morgan": "~1.6.1", "sequelize": "^3.23.3", "serve-favicon": "~2.3.0" From 39bd7469b8e9108c88338a35f0ccf85360e69c38 Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 14 Jun 2016 16:53:11 -0700 Subject: [PATCH 03/41] Wrote some scripts for handling database, and set up connection with massivejs --- app.js | 13 ++++++++++++ db/setup/schema.sql | 10 +++++++++ npm-debug.log | 48 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 ++++++- tasks/load_schema.js | 13 ++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 db/setup/schema.sql create mode 100644 npm-debug.log create mode 100644 tasks/load_schema.js diff --git a/app.js b/app.js index 747e8b41f..f44c48875 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,18 @@ var bodyParser = require('body-parser'); var app = express(); +var massive = require("massive") +var connectionString = "postgres://localhost/videostore_api" + +// connect to Massive and get the db instance. You can safely use the +// convenience sync method here because its on app load +// you can also use loadSync - it's an alias +var massiveInstance = massive.connectSync({connectionString : connectionString}) + +// Set a reference to the massive instance on Express' app: +app.set('db', massiveInstance) + + // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); @@ -20,6 +32,7 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); +//routes var indexRoutes = require('./routes/index'); app.use('/', indexRoutes); diff --git a/db/setup/schema.sql b/db/setup/schema.sql new file mode 100644 index 000000000..3da68d524 --- /dev/null +++ b/db/setup/schema.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS movies; +CREATE TABLE movies( + id serial PRIMARY KEY, + title text, + overview text, + release_date text, + inventory integer +); + +CREATE INDEX movies_movie ON movies (movie); diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..c99667ff6 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,48 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'run', +1 verbose cli 'db:schema' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'predb:schema', 'db:schema', 'postdb:schema' ] +5 info lifecycle video-store-api@0.0.0~predb:schema: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~predb:schema: no script for predb:schema, continuing +7 info lifecycle video-store-api@0.0.0~db:schema: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~db:schema: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~db:schema: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/valerieconklin/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/valerieconklin/.rvm/gems/ruby-2.3.0/bin:/Users/valerieconklin/.rvm/gems/ruby-2.3.0@global/bin:/Users/valerieconklin/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/valerieconklin/.rvm/bin:/Users/valerieconklin/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~db:schema: CWD: /Users/valerieconklin/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~db:schema: Args: [ '-c', 'clear; node tasks/load_schema.js' ] +12 silly lifecycle video-store-api@0.0.0~db:schema: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~db:schema: Failed to exec db:schema script +14 verbose stack Error: video-store-api@0.0.0 db:schema: `clear; node tasks/load_schema.js` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:852:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) +15 verbose pkgid video-store-api@0.0.0 +16 verbose cwd /Users/valerieconklin/C5/projects/VideoStoreAPI +17 error Darwin 15.5.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:schema" +19 error node v6.2.1 +20 error npm v3.9.3 +21 error code ELIFECYCLE +22 error video-store-api@0.0.0 db:schema: `clear; node tasks/load_schema.js` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 db:schema script 'clear; node tasks/load_schema.js'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the video-store-api package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error clear; node tasks/load_schema.js +23 error You can get information on how to open an issue for this project with: +23 error npm bugs video-store-api +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls video-store-api +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 404578a7a..0b5f5f09b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,12 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/" + "test": "clear; jasmine-node --verbose spec/", + "db:drop": "dropdb videostore_api", + "db:create": "createdb videostore_api", + "db:schema": "clear; node tasks/load_schema.js", + "db:seed": "", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" }, "dependencies": { "body-parser": "~1.13.2", diff --git a/tasks/load_schema.js b/tasks/load_schema.js new file mode 100644 index 000000000..2ca3c530b --- /dev/null +++ b/tasks/load_schema.js @@ -0,0 +1,13 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/videostore_api" + +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([], function(err, res) { + if (err) { + throw(new Error(err.message)) + } + + console.log("yay schema!") + process.exit() +}) From 95af55685ba4f97feb607a2c26423c9f43a857da Mon Sep 17 00:00:00 2001 From: Yordanos Date: Wed, 15 Jun 2016 15:40:54 -0700 Subject: [PATCH 04/41] removed load_schema file and added a seed file in tasks. Seeding data works. Added seed script to package.json --- db/setup/schema.sql | 41 ++++++++++++++++++++++++++++++++++++-- npm-debug.log | 48 --------------------------------------------- package.json | 4 ++-- tasks/seed.js | 30 ++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 52 deletions(-) delete mode 100644 npm-debug.log create mode 100644 tasks/seed.js diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 3da68d524..4f583e941 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -1,10 +1,47 @@ +-- movies------------------------------------------------- DROP TABLE IF EXISTS movies; CREATE TABLE movies( id serial PRIMARY KEY, title text, overview text, release_date text, - inventory integer + inventory integer, + created_at timestamp, + updated_at timestamp ); -CREATE INDEX movies_movie ON movies (movie); +CREATE INDEX movies_title ON movies (title); + +-- customers------------------------------------------------- +DROP TABLE IF EXISTS customers; +CREATE TABLE customers( + id serial PRIMARY KEY, + name text, + address text, + city text, + state text, + postal_code text, + account_credit decimal, + phone text, + registered_at timestamp, + created_at timestamp, + updated_at timestamp + +); + +CREATE INDEX customers_name ON customers (name); + +-- rentals------------------------------------------------- +DROP TABLE IF EXISTS rentals; +CREATE TABLE rentals( + id serial PRIMARY KEY, + movie_id integer, + customer_id integer, + status text, + overview text, + return_date timestamp, + created_at timestamp, + updated_at timestamp +); + +CREATE INDEX rentals_status ON rentals (status); diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index c99667ff6..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,48 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'db:schema' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'predb:schema', 'db:schema', 'postdb:schema' ] -5 info lifecycle video-store-api@0.0.0~predb:schema: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~predb:schema: no script for predb:schema, continuing -7 info lifecycle video-store-api@0.0.0~db:schema: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~db:schema: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~db:schema: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/valerieconklin/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/valerieconklin/.rvm/gems/ruby-2.3.0/bin:/Users/valerieconklin/.rvm/gems/ruby-2.3.0@global/bin:/Users/valerieconklin/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/valerieconklin/.rvm/bin:/Users/valerieconklin/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~db:schema: CWD: /Users/valerieconklin/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~db:schema: Args: [ '-c', 'clear; node tasks/load_schema.js' ] -12 silly lifecycle video-store-api@0.0.0~db:schema: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~db:schema: Failed to exec db:schema script -14 verbose stack Error: video-store-api@0.0.0 db:schema: `clear; node tasks/load_schema.js` -14 verbose stack Exit status 1 -14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:852:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) -15 verbose pkgid video-store-api@0.0.0 -16 verbose cwd /Users/valerieconklin/C5/projects/VideoStoreAPI -17 error Darwin 15.5.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:schema" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 db:schema: `clear; node tasks/load_schema.js` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 db:schema script 'clear; node tasks/load_schema.js'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the video-store-api package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error clear; node tasks/load_schema.js -23 error You can get information on how to open an issue for this project with: -23 error npm bugs video-store-api -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls video-store-api -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 0b5f5f09b..9858b298c 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "db:drop": "dropdb videostore_api", "db:create": "createdb videostore_api", "db:schema": "clear; node tasks/load_schema.js", - "db:seed": "", - "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" + "db:seed": "node tasks/seed.js", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" }, "dependencies": { "body-parser": "~1.13.2", diff --git a/tasks/seed.js b/tasks/seed.js new file mode 100644 index 000000000..4d2607852 --- /dev/null +++ b/tasks/seed.js @@ -0,0 +1,30 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/videostore_api" + +var db = massive.connectSync({connectionString : connectionString}) + +var customers = require('../db/seeds/customers.json'); +var movies = require('../db/seeds/movies.json'); + +var date = new Date(); +var totalCount = customers.length + movies.length; + +var count = 0 + +console.log(totalCount) + +for(customer of customers){ + customer.created_at = date + db.customers.save(customer, function(err, result){ + count++ + if(count === totalCount){process.exit()} + }); +}; + +for(movie of movies){ + movie.created_at = date + db.movies.save(movie, function(err, result){ + count++ + if(count === totalCount){process.exit()} + }); +}; From 31e69696b54b720daf2fb6449324d59f8de9fef0 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 16 Jun 2016 15:50:25 -0700 Subject: [PATCH 05/41] Set up controller for movies and movie.all method in movie model. working on callback function that handles that data now. --- app.js | 8 ++++---- controllers/movies.js | 17 +++++++++++++++++ controllers/rentals.js | 7 +++++++ models/movie.js | 43 ++++++++++++++++++++++++++++++++++++++++++ routes/index.js | 2 +- routes/movies.js | 8 ++++++++ routes/rentals.js | 8 ++++++++ 7 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 models/movie.js create mode 100644 routes/movies.js create mode 100644 routes/rentals.js diff --git a/app.js b/app.js index f44c48875..f0cea736c 100644 --- a/app.js +++ b/app.js @@ -5,19 +5,19 @@ var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); +var app = module.exports = express(); -var app = express(); - +//database setup var massive = require("massive") var connectionString = "postgres://localhost/videostore_api" // connect to Massive and get the db instance. You can safely use the // convenience sync method here because its on app load // you can also use loadSync - it's an alias -var massiveInstance = massive.connectSync({connectionString : connectionString}) +var db = massive.connectSync({connectionString : connectionString}) // Set a reference to the massive instance on Express' app: -app.set('db', massiveInstance) +app.set('db', db) // view engine setup diff --git a/controllers/movies.js b/controllers/movies.js index e69de29bb..8e0bd15b3 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -0,0 +1,17 @@ +var Movie = require("../models/movie.js"); + + +var MoviesController = { + index: function(req, res, next) { + Movie.all(function (error, result){ + + + + return result; + }; + + } + +}; + +module.exports = MoviesController; diff --git a/controllers/rentals.js b/controllers/rentals.js index e69de29bb..9a488d846 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -0,0 +1,7 @@ +var RentalsController = { + index: function(req, res, next) { + res.json("look, a rentals index!"); + } +}; + +module.exports = RentalsController; diff --git a/models/movie.js b/models/movie.js new file mode 100644 index 000000000..873aa2840 --- /dev/null +++ b/models/movie.js @@ -0,0 +1,43 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Movie = function(id) { + this.id = id; +}; + + +// Instance functions +Movie.all = function (after_run) { + // this whole thing immediately gets thrown on the event loop and Movie.all finishes and goes to whatever's next. But .run is not finished yet; it still has to go through the event loop and get executed. + + // the callback (second parameter below) is how you deal with the data returned by whatever happened in the first parameter. + db.movies.run("SELECT * FROM movies;", function(error, result) { //the error and result are basically coming from .run() + // after_run(error, result); + if(error) { + //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. + after_run(error, undefined); + } else { + after_run(null, result); + } + }); +}; + +// Movie.all(function (error, result){ + // I can also just put after_run(error, result); in the callback for db.run above instead of an if-else statement if I want access to both the error and the result in this function + + //but, if I want to modify what the error or result is, I use the if/else in the db.run callback above + + // make sure to deal with both errors and results + + // return result; + // but make it into a hash so we can use it to initialize + +// }) + +function run(cmd, cb) { + //do cmd + err = undefined + result = {s:3} + cb(err, result) +} diff --git a/routes/index.js b/routes/index.js index 4e4d54247..a4bb11a64 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,7 +2,7 @@ var express = require('express'); var router = express.Router(); var IndexController = require('../controllers/index.js'); -/* GET home page. */ +/* test GET page. */ router.get('/zomg', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}); }); diff --git a/routes/movies.js b/routes/movies.js new file mode 100644 index 000000000..07459decf --- /dev/null +++ b/routes/movies.js @@ -0,0 +1,8 @@ +var express = require('express'); +var router = express.Router(); +var MoviesController = require('../controllers/movies'); + +/* GET home page. */ +router.get('/', MoviesController.index); + +module.exports = router; diff --git a/routes/rentals.js b/routes/rentals.js new file mode 100644 index 000000000..4d460e29b --- /dev/null +++ b/routes/rentals.js @@ -0,0 +1,8 @@ +var express = require('express'); +var router = express.Router(); +var RentalsController = require('../controllers/rentals'); + +/* GET home page. */ +router.get('/', RentalsController.index); + +module.exports = router; From 03945db55ca3359f4c37451302eee85b4e6d11f2 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 16 Jun 2016 16:05:46 -0700 Subject: [PATCH 06/41] Made it so db.movies.run callback method creates a new instance of movie --- models/movie.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/models/movie.js b/models/movie.js index 873aa2840..a22709b4d 100644 --- a/models/movie.js +++ b/models/movie.js @@ -2,8 +2,9 @@ var app = require("../app"); var db = app.get("db"); // Constructor function -var Movie = function(id) { - this.id = id; +var Movie = function(movieInfo) { + this.id = movieInfo.id; + this.title = movieInfo.title; }; @@ -12,13 +13,15 @@ Movie.all = function (after_run) { // this whole thing immediately gets thrown on the event loop and Movie.all finishes and goes to whatever's next. But .run is not finished yet; it still has to go through the event loop and get executed. // the callback (second parameter below) is how you deal with the data returned by whatever happened in the first parameter. - db.movies.run("SELECT * FROM movies;", function(error, result) { //the error and result are basically coming from .run() + db.movies.run("SELECT * FROM movies;", function(error, movies) { //the error and result are basically coming from .run() // after_run(error, result); - if(error) { + if(error || !movies) { //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. after_run(error, undefined); } else { - after_run(null, result); + after_run(null, movies.map(function(movie) { + return new Movie(movie); + })); } }); }; From 9e675f836c110972f8c87d341eda78969f543590 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Thu, 16 Jun 2016 16:11:18 -0700 Subject: [PATCH 07/41] added models folder and account.js file. created a find function in the model and got cutomers.all to render a json response --- app.js | 19 +++++-------------- controllers/customers.js | 30 +++++++++++++++++++++++++++--- models/customer.js | 33 +++++++++++++++++++++++++++++++++ package.json | 4 ++-- routes/customers.js | 2 ++ tasks/load_schema.js | 2 +- tasks/seed.js | 2 +- 7 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 models/customer.js diff --git a/app.js b/app.js index f44c48875..d3d8f78ce 100644 --- a/app.js +++ b/app.js @@ -5,20 +5,15 @@ var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); - -var app = express(); - var massive = require("massive") -var connectionString = "postgres://localhost/videostore_api" -// connect to Massive and get the db instance. You can safely use the -// convenience sync method here because its on app load -// you can also use loadSync - it's an alias -var massiveInstance = massive.connectSync({connectionString : connectionString}) -// Set a reference to the massive instance on Express' app: -app.set('db', massiveInstance) +var app = module.exports = express(); +// database setup +var connectionString = "postgres://localhost/videostore_api_" + app.get('env'); +var db = massive.connectSync({connectionString: connectionString}); +app.set('db', db); // view engine setup app.set('views', path.join(__dirname, 'views')); @@ -45,10 +40,6 @@ app.use('/movies', movieRoutes); var rentalRoutes = require('./routes/rentals'); app.use('/rentals', rentalRoutes); - - - - // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); diff --git a/controllers/customers.js b/controllers/customers.js index cfa099b41..5bc319be1 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -1,7 +1,31 @@ -var CustomerController = { +var Customer = require("../models/customer"); + +var CustomersController = { index: function(req, res, next) { - // res.json(); + Customer.all(function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers); + } + }); } + current: function(req, res, next) { + Customer.find(req.params.id, function(error, customer) { + if(error) { + var err = new Error("No such customer"); + err.status = 404; + next(err); + } else { + customer.getCurrent(function(error, balance) { + res.render(customer); + }); + } + }); + } }; -module.exports = CustomerController; + +module.exports = CustomersController; diff --git a/models/customer.js b/models/customer.js new file mode 100644 index 000000000..d124d1f3a --- /dev/null +++ b/models/customer.js @@ -0,0 +1,33 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Customer = function(customerInfo) { + this.id = customerInfo.id; + this.name = customerInfo.name; + +}; + +Customer.all = function(callback) { + db.customers.find(function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve customers"), undefined); + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer); + })); + } + }); +}; + +Customer.find = function(id, callback) { + db.accounts.findOne({id: id}, function(error, customer) { + if(error || !customer) { + callback(error || new Error("Account not found"), undefined); + } else { + callback(null, new Customer(customer.id)); + } + }); +}; + +module.exports = Customer; diff --git a/package.json b/package.json index 9858b298c..4e289ed2c 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:drop": "dropdb videostore_api", - "db:create": "createdb videostore_api", + "db:drop": "dropdb videostore_api_development && dropdb videostore_api_test", + "db:create": "createdb videostore_api_development && createdb videostore_api_test ", "db:schema": "clear; node tasks/load_schema.js", "db:seed": "node tasks/seed.js", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" diff --git a/routes/customers.js b/routes/customers.js index b150b59b0..d0aac9867 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -5,4 +5,6 @@ var CustomerController = require('../controllers/customers'); /* GET home page. */ router.get('/', CustomerController.index); +router.get('/:customer_id/current', CustomerController.current); + module.exports = router; diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 2ca3c530b..003d95141 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostore_api" +var connectionString = "postgres://localhost/videostore_api_development" var db = massive.connectSync({connectionString : connectionString}) diff --git a/tasks/seed.js b/tasks/seed.js index 4d2607852..4fac1bfe8 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostore_api" +var connectionString = "postgres://localhost/videostore_api_development" var db = massive.connectSync({connectionString : connectionString}) From 4594099b97e1cc1054d011d8cfadbdb67478da48 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Thu, 16 Jun 2016 16:26:36 -0700 Subject: [PATCH 08/41] fixed a missing a comma in the controller before current that was crashing the app file --- app.js | 12 +++++++----- controllers/customers.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 35f18f348..f673b6e09 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,8 @@ var bodyParser = require('body-parser'); var massive = require("massive") +var app = module.exports = express(); + // database setup var connectionString = "postgres://localhost/videostore_api_" + app.get('env'); var db = massive.connectSync({connectionString: connectionString}); @@ -31,11 +33,11 @@ app.use('/', indexRoutes); var customerRoutes = require('./routes/customers'); app.use('/customers', customerRoutes); -var movieRoutes = require('./routes/movies'); -app.use('/movies', movieRoutes); - -var rentalRoutes = require('./routes/rentals'); -app.use('/rentals', rentalRoutes); +// var movieRoutes = require('./routes/movies'); +// app.use('/movies', movieRoutes); +// +// var rentalRoutes = require('./routes/rentals'); +// app.use('/rentals', rentalRoutes); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/controllers/customers.js b/controllers/customers.js index 5bc319be1..19d6b6743 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -11,7 +11,7 @@ var CustomersController = { res.json(customers); } }); - } + }, current: function(req, res, next) { Customer.find(req.params.id, function(error, customer) { if(error) { From 74f7d14703487d864abe32b1337eafff8fafbc74 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 16 Jun 2016 16:33:47 -0700 Subject: [PATCH 09/41] Set up error handling for movies controller index method --- controllers/movies.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 8e0bd15b3..14b49655c 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -4,10 +4,14 @@ var Movie = require("../models/movie.js"); var MoviesController = { index: function(req, res, next) { Movie.all(function (error, result){ + if (error) { + var err = new Error("Error retrieving movies:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(result); + } - - - return result; }; } From f519cdf6d778b2e0b8bc43191ba5469f006160be Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 16 Jun 2016 16:47:49 -0700 Subject: [PATCH 10/41] movies index endpoint WORKING FOR REALS yay --- app.js | 4 ++-- controllers/movies.js | 4 ++-- models/movie.js | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index f673b6e09..126e86f77 100644 --- a/app.js +++ b/app.js @@ -33,8 +33,8 @@ app.use('/', indexRoutes); var customerRoutes = require('./routes/customers'); app.use('/customers', customerRoutes); -// var movieRoutes = require('./routes/movies'); -// app.use('/movies', movieRoutes); +var movieRoutes = require('./routes/movies'); +app.use('/movies', movieRoutes); // // var rentalRoutes = require('./routes/rentals'); // app.use('/rentals', rentalRoutes); diff --git a/controllers/movies.js b/controllers/movies.js index 14b49655c..879ed63f3 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -3,7 +3,7 @@ var Movie = require("../models/movie.js"); var MoviesController = { index: function(req, res, next) { - Movie.all(function (error, result){ + Movie.all(function (error, result) { if (error) { var err = new Error("Error retrieving movies:\n" + error.message); err.status = 500; @@ -12,7 +12,7 @@ var MoviesController = { res.json(result); } - }; + }); } diff --git a/models/movie.js b/models/movie.js index a22709b4d..09b44021b 100644 --- a/models/movie.js +++ b/models/movie.js @@ -13,7 +13,7 @@ Movie.all = function (after_run) { // this whole thing immediately gets thrown on the event loop and Movie.all finishes and goes to whatever's next. But .run is not finished yet; it still has to go through the event loop and get executed. // the callback (second parameter below) is how you deal with the data returned by whatever happened in the first parameter. - db.movies.run("SELECT * FROM movies;", function(error, movies) { //the error and result are basically coming from .run() + db.run("SELECT * FROM movies;", function(error, movies) { //the error and result are basically coming from .run() // after_run(error, result); if(error || !movies) { //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. @@ -38,9 +38,4 @@ Movie.all = function (after_run) { // }) -function run(cmd, cb) { - //do cmd - err = undefined - result = {s:3} - cb(err, result) -} +module.exports = Movie; From ec2b0ceef30282ea2af3c309a7f20d01507712ba Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 09:59:49 -0700 Subject: [PATCH 11/41] Wrote callback method for Movie.sort in moviecontroller --- controllers/movies.js | 13 ++++++++++++- models/movie.js | 13 ++++++++----- routes/movies.js | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 879ed63f3..c54825399 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -11,9 +11,20 @@ var MoviesController = { } else { res.json(result); } - }); + }, + + sort: function(req, res, next) { + Movie.sort(function (error, result)) { + if (error) { + var err = new Error("Error retrieving movies:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(result); + } + }); } }; diff --git a/models/movie.js b/models/movie.js index 09b44021b..7aa22259c 100644 --- a/models/movie.js +++ b/models/movie.js @@ -9,7 +9,7 @@ var Movie = function(movieInfo) { // Instance functions -Movie.all = function (after_run) { +Movie.all = function (callback) { // this whole thing immediately gets thrown on the event loop and Movie.all finishes and goes to whatever's next. But .run is not finished yet; it still has to go through the event loop and get executed. // the callback (second parameter below) is how you deal with the data returned by whatever happened in the first parameter. @@ -17,9 +17,9 @@ Movie.all = function (after_run) { // after_run(error, result); if(error || !movies) { //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. - after_run(error, undefined); + callback(error, undefined); } else { - after_run(null, movies.map(function(movie) { + callback(null, movies.map(function(movie) { return new Movie(movie); })); } @@ -27,7 +27,7 @@ Movie.all = function (after_run) { }; // Movie.all(function (error, result){ - // I can also just put after_run(error, result); in the callback for db.run above instead of an if-else statement if I want access to both the error and the result in this function + // I can also just put callback(error, result); in the callback for db.run above instead of an if-else statement if I want access to both the error and the result in this function //but, if I want to modify what the error or result is, I use the if/else in the db.run callback above @@ -35,7 +35,10 @@ Movie.all = function (after_run) { // return result; // but make it into a hash so we can use it to initialize - // }) +Movie.sort = function (callback) { + +} + module.exports = Movie; diff --git a/routes/movies.js b/routes/movies.js index 07459decf..570ae2631 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -5,4 +5,8 @@ var MoviesController = require('../controllers/movies'); /* GET home page. */ router.get('/', MoviesController.index); +router.get('/sort/release-date', MoviesController.sortMovies); + +router.get('/sort/title', MoviesController.sortMovies) + module.exports = router; From 58f07cd109d152539476c9f09c9a80b6a7f696c4 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 11:15:24 -0700 Subject: [PATCH 12/41] Finished Movie.sort method in model --- controllers/movies.js | 2 +- models/movie.js | 13 +++++++++++-- routes/movies.js | 4 +--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index c54825399..2c6393e70 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -16,7 +16,7 @@ var MoviesController = { }, sort: function(req, res, next) { - Movie.sort(function (error, result)) { + Movie.sort(req.params.sort_param, function (error, result) { if (error) { var err = new Error("Error retrieving movies:\n" + error.message); err.status = 500; diff --git a/models/movie.js b/models/movie.js index 7aa22259c..9b4a5f4cc 100644 --- a/models/movie.js +++ b/models/movie.js @@ -37,8 +37,17 @@ Movie.all = function (callback) { // but make it into a hash so we can use it to initialize // }) -Movie.sort = function (callback) { - +Movie.sort = function (field, callback) { + db.movies.find({}, {order: field}, function(error, movies) { + if(error || !movies) { + //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. + callback(error, undefined); + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie); + })); + } + }); } module.exports = Movie; diff --git a/routes/movies.js b/routes/movies.js index 570ae2631..a787e6a33 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -5,8 +5,6 @@ var MoviesController = require('../controllers/movies'); /* GET home page. */ router.get('/', MoviesController.index); -router.get('/sort/release-date', MoviesController.sortMovies); - -router.get('/sort/title', MoviesController.sortMovies) +router.get('/sort/:sort_param', MoviesController.sort); module.exports = router; From 424a3195dedf6aceab021a3fa9697dd41dac07cf Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 11:32:17 -0700 Subject: [PATCH 13/41] Added limit and offset functionality to Movie.sort --- controllers/movies.js | 3 ++- models/movie.js | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 2c6393e70..3259f6cec 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -16,7 +16,8 @@ var MoviesController = { }, sort: function(req, res, next) { - Movie.sort(req.params.sort_param, function (error, result) { + console.log(req.query); + Movie.sort(req.params.sort_param, req.query.n, req.query.p, function (error, result) { if (error) { var err = new Error("Error retrieving movies:\n" + error.message); err.status = 500; diff --git a/models/movie.js b/models/movie.js index 9b4a5f4cc..bd50be13e 100644 --- a/models/movie.js +++ b/models/movie.js @@ -37,8 +37,13 @@ Movie.all = function (callback) { // but make it into a hash so we can use it to initialize // }) -Movie.sort = function (field, callback) { - db.movies.find({}, {order: field}, function(error, movies) { +Movie.sort = function (field, n, p, callback) { + var sort_options = { + order: field, + limit: n, + offset: p + }; + db.movies.find({}, sort_options, function(error, movies) { if(error || !movies) { //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. callback(error, undefined); From 4ee5fa19edf432b52533a66ddc5d38c55c94ca32 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 17 Jun 2016 13:08:40 -0700 Subject: [PATCH 14/41] completed customers sort path --- controllers/customers.js | 19 ++++++++++++--- models/customer.js | 50 +++++++++++++++++++++++++++++++++++++++- routes/customers.js | 2 ++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 19d6b6743..09b071149 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -19,12 +19,25 @@ var CustomersController = { err.status = 404; next(err); } else { - customer.getCurrent(function(error, balance) { - res.render(customer); + customer.getCurrent(function(error, current) { + res.render(current); }); } }); - } + }, + sort: function(req, res, next) { + var options = {order: req.params.search, limit: req.query.n, offset: req.query.p} + Customer.sort(options, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers); + } + }); + }, + }; diff --git a/models/customer.js b/models/customer.js index d124d1f3a..238fc08cb 100644 --- a/models/customer.js +++ b/models/customer.js @@ -5,9 +5,45 @@ var db = app.get("db"); var Customer = function(customerInfo) { this.id = customerInfo.id; this.name = customerInfo.name; + this.address = customerInfo.address; + this.city = customerInfo.city; + this.state = customerInfo.state; + this.postal_code = customerInfo.postal_code; + this.account_credit = customerInfo.account_credit; + this.phone = customerInfo.phone; + this.registered_at = customerInfo.registered_at; + this.created_at = customerInfo.created_at; + this.updated_at = customerInfo.updated_at; +}; + +// Instance functions +Customer.prototype.getCurrent = function(callback) { + db.customers.findOne(this.id, function(error, result) { + if(error) { + callback(error, undefined); + } else { + // var rentals = rentals where cutomer id = user_id and status = "checkout" + callback(null, result.balance); + } + }); + + return this; }; +// Customer.prototype.getCurrent = function(callback) { +// db.customers.findOne(this.id, function(error, result) { +// if(error) { +// callback(error, undefined); +// } else { +// callback(null, result.balance); +// } +// }); +// +// return this; +// }; + + Customer.all = function(callback) { db.customers.find(function(error, customers) { if(error || !customers) { @@ -25,7 +61,19 @@ Customer.find = function(id, callback) { if(error || !customer) { callback(error || new Error("Account not found"), undefined); } else { - callback(null, new Customer(customer.id)); + callback(null, new Customer(customer)); + } + }); +}; + +Customer.sort = function(options,callback) { + db.customers.find({}, options, function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve customers"), undefined); + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer); + })); } }); }; diff --git a/routes/customers.js b/routes/customers.js index d0aac9867..de65571f7 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -5,6 +5,8 @@ var CustomerController = require('../controllers/customers'); /* GET home page. */ router.get('/', CustomerController.index); +router.get('/sort/:search?', CustomerController.sort); + router.get('/:customer_id/current', CustomerController.current); module.exports = router; From 622ea10f2ac95cf8aed4f1791fbb66e27035fffb Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 17 Jun 2016 13:16:46 -0700 Subject: [PATCH 15/41] uncommented movie and rental routes in app file --- app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index f673b6e09..fb51ca6a8 100644 --- a/app.js +++ b/app.js @@ -33,11 +33,11 @@ app.use('/', indexRoutes); var customerRoutes = require('./routes/customers'); app.use('/customers', customerRoutes); -// var movieRoutes = require('./routes/movies'); -// app.use('/movies', movieRoutes); -// -// var rentalRoutes = require('./routes/rentals'); -// app.use('/rentals', rentalRoutes); +var movieRoutes = require('./routes/movies'); +app.use('/movies', movieRoutes); + +var rentalRoutes = require('./routes/rentals'); +app.use('/rentals', rentalRoutes); // catch 404 and forward to error handler app.use(function(req, res, next) { From 772c29ea73acc376e08ca092f3dfae13f52f6ed5 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 17 Jun 2016 13:32:36 -0700 Subject: [PATCH 16/41] created a script to run our test env --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4e289ed2c..977f0f768 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", + "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", "db:drop": "dropdb videostore_api_development && dropdb videostore_api_test", "db:create": "createdb videostore_api_development && createdb videostore_api_test ", From 5232b468ca37061e2dcdd1a202f970e93c8e6df3 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 13:37:40 -0700 Subject: [PATCH 17/41] Created blank files for all controller tests and unit tests --- controllers/customers.spec.js | 0 models/movie.js | 2 ++ spec/controllers/customers.spec.js | 0 spec/controllers/movies.spec.js | 2 +- spec/controllers/rentals.spec.js | 0 spec/models/customer.spec.js | 0 spec/models/movie.spec.js | 0 spec/models/rental.spec.js | 0 8 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 controllers/customers.spec.js create mode 100644 spec/controllers/customers.spec.js create mode 100644 spec/controllers/rentals.spec.js create mode 100644 spec/models/customer.spec.js create mode 100644 spec/models/movie.spec.js create mode 100644 spec/models/rental.spec.js diff --git a/controllers/customers.spec.js b/controllers/customers.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/models/movie.js b/models/movie.js index bd50be13e..333d58788 100644 --- a/models/movie.js +++ b/models/movie.js @@ -55,4 +55,6 @@ Movie.sort = function (field, n, p, callback) { }); } + + module.exports = Movie; diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index ddcaf2f68..aa6c5df81 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -2,4 +2,4 @@ var request = require('request'); describe("Endpoints under /movies", function() { -}) +}); diff --git a/spec/controllers/rentals.spec.js b/spec/controllers/rentals.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js new file mode 100644 index 000000000..e69de29bb From 105ddba935169d57bf3b643adf37f253086a8954 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 14:34:20 -0700 Subject: [PATCH 18/41] Trying to get test script working --- package.json | 2 +- spec/controllers/movies.spec.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 977f0f768..d47e39fe0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/", + "test": "NODE_ENV=test ./node_modules/.bin/jasmine-node --verbose spec/", "db:drop": "dropdb videostore_api_development && dropdb videostore_api_test", "db:create": "createdb videostore_api_development && createdb videostore_api_test ", "db:schema": "clear; node tasks/load_schema.js", diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index aa6c5df81..55040d3f9 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,5 +1,15 @@ var request = require('request'); +var base_url = "http://localhost:3000/" +var app = require('../../app.js'); describe("Endpoints under /movies", function() { - + it('responds with a 200 status code', function (done) { + request.get(base_url, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }); + + + }); From 2c3aa1c3965bcb24b916c1ce7bd7c0eeda98fe04 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 17 Jun 2016 15:21:07 -0700 Subject: [PATCH 19/41] Fixed WEIRD issue with npm test not working --- spec/controllers/index.spec.js | 20 +------------------- spec/controllers/movies.spec.js | 6 +++--- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/spec/controllers/index.spec.js b/spec/controllers/index.spec.js index e4151d267..88ca20901 100644 --- a/spec/controllers/index.spec.js +++ b/spec/controllers/index.spec.js @@ -8,22 +8,4 @@ describe("Endpoint at /", function () { done() }) }) - - describe("the returned json data", function() { - it('has the right keys', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(Object.keys(data)).toEqual(['whatevs']) - done() - }) - }) - - it('has the right values for the keys', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data.whatevs).toEqual('whatevs!!!') - done() - }) - }) - }) -}) +}); diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 55040d3f9..58e2a4478 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,14 +1,14 @@ var request = require('request'); -var base_url = "http://localhost:3000/" +var base_url = "http://localhost:3000" var app = require('../../app.js'); describe("Endpoints under /movies", function() { it('responds with a 200 status code', function (done) { - request.get(base_url, function(error, response, body) { + request.get(base_url + "/movies", function(error, response, body) { expect(response.statusCode).toEqual(200) done() }) - }); + }) From 8e1622aa9153ba54f23a242766d1ecbc65ec38ce Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 17 Jun 2016 15:47:53 -0700 Subject: [PATCH 20/41] added test db connection to seed and schema file --- controllers/customers.spec.js | 0 npm-debug.log | 49 ++++++++++++++++++++++++++++++ package.json | 2 +- spec/controllers/customers.spec.js | 16 ++++++++++ spec/controllers/movies.spec.js | 8 ++--- tasks/load_schema.js | 4 ++- tasks/seed.js | 3 +- 7 files changed, 75 insertions(+), 7 deletions(-) delete mode 100644 controllers/customers.spec.js create mode 100644 npm-debug.log diff --git a/controllers/customers.spec.js b/controllers/customers.spec.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..f6907b753 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,49 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'run', +1 verbose cli 'test' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'pretest', 'test', 'posttest' ] +5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing +7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Yordanos/Ada/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/Yordanos/.rvm/gems/ruby-2.3.0/bin:/Users/Yordanos/.rvm/gems/ruby-2.3.0@global/bin:/Users/Yordanos/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Yordanos/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/Yordanos/Ada/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', +11 silly lifecycle 'clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] +12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script +14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:852:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) +15 verbose pkgid video-store-api@0.0.0 +16 verbose cwd /Users/Yordanos/Ada/C5/projects/VideoStoreAPI +17 error Darwin 15.0.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" +19 error node v6.2.1 +20 error npm v3.9.3 +21 error code ELIFECYCLE +22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the video-store-api package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ +23 error You can get information on how to open an issue for this project with: +23 error npm bugs video-store-api +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls video-store-api +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index d47e39fe0..0f5e75c70 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "NODE_ENV=test ./node_modules/.bin/jasmine-node --verbose spec/", + "test": "clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/", "db:drop": "dropdb videostore_api_development && dropdb videostore_api_test", "db:create": "createdb videostore_api_development && createdb videostore_api_test ", "db:schema": "clear; node tasks/load_schema.js", diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index e69de29bb..e48677949 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -0,0 +1,16 @@ +var request = require('request'); +var base_url = "http://localhost:3000/" +var route = "customers/" +// var app = require('../../app.js'); + +describe("Endpoints under /customers", function() { + it('responds with a 200 status code', function (done) { + request.get(base_url + route, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }); + + + +}); diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 58e2a4478..2d8dea1d3 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,14 +1,14 @@ var request = require('request'); -var base_url = "http://localhost:3000" -var app = require('../../app.js'); +var base_url = "http://localhost:3000/" +// var app = require('../../app.js'); describe("Endpoints under /movies", function() { it('responds with a 200 status code', function (done) { - request.get(base_url + "/movies", function(error, response, body) { + request.get(base_url, function(error, response, body) { expect(response.statusCode).toEqual(200) done() }) - }) + }); diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 003d95141..aaa3f32a0 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,5 +1,7 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostore_api_development" + +var connectionString = "postgres://localhost/videostore_api_development"; +var connectionString = "postgres://localhost/videostore_api_test"; var db = massive.connectSync({connectionString : connectionString}) diff --git a/tasks/seed.js b/tasks/seed.js index 4fac1bfe8..177110243 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,5 +1,6 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostore_api_development" +var connectionString = "postgres://localhost/videostore_api_development"; +var connectionString = "postgres://localhost/videostore_api_test"; var db = massive.connectSync({connectionString : connectionString}) From 75ab1a40cac219b02d2b4b1c0b447bf8d4c95603 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 17 Jun 2016 15:56:59 -0700 Subject: [PATCH 21/41] added '/' route and added 'movies route' to movies controller test --- npm-debug.log | 49 --------------------------------- routes/index.js | 3 +- spec/controllers/movies.spec.js | 5 ++-- 3 files changed, 5 insertions(+), 52 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index f6907b753..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,49 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'test' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'pretest', 'test', 'posttest' ] -5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing -7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Yordanos/Ada/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/Yordanos/.rvm/gems/ruby-2.3.0/bin:/Users/Yordanos/.rvm/gems/ruby-2.3.0@global/bin:/Users/Yordanos/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Yordanos/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/Yordanos/Ada/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', -11 silly lifecycle 'clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] -12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script -14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -14 verbose stack Exit status 1 -14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:852:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) -15 verbose pkgid video-store-api@0.0.0 -16 verbose cwd /Users/Yordanos/Ada/C5/projects/VideoStoreAPI -17 error Darwin 15.0.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the video-store-api package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ -23 error You can get information on how to open an issue for this project with: -23 error npm bugs video-store-api -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls video-store-api -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/routes/index.js b/routes/index.js index a4bb11a64..b56ca02a3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,11 +2,12 @@ var express = require('express'); var router = express.Router(); var IndexController = require('../controllers/index.js'); +router.get('/', IndexController.index); + /* test GET page. */ router.get('/zomg', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}); }); -router.get('/stuff', IndexController.index); module.exports = router; diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 2d8dea1d3..b1690b2b9 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,10 +1,11 @@ var request = require('request'); var base_url = "http://localhost:3000/" -// var app = require('../../app.js'); +var route = "movies/" + describe("Endpoints under /movies", function() { it('responds with a 200 status code', function (done) { - request.get(base_url, function(error, response, body) { + request.get(base_url + route, function(error, response, body) { expect(response.statusCode).toEqual(200) done() }) From 77fb09c0842a17b051b41f2f784cd041ec7c7b1e Mon Sep 17 00:00:00 2001 From: Yordanos Date: Mon, 20 Jun 2016 13:40:13 -0700 Subject: [PATCH 22/41] finished reseeding data for both database types --- app.js | 1 + controllers/rentals.js | 15 ++++++-- db/setup/schema.sql | 4 +-- models/customer.js | 17 ++------- models/movie.js | 4 +++ models/rental.js | 21 ++++++++++++ routes/rentals.js | 2 +- tasks/load_schema.js | 27 +++++++++------ tasks/seed.js | 78 ++++++++++++++++++++++++++++++------------ 9 files changed, 117 insertions(+), 52 deletions(-) create mode 100644 models/rental.js diff --git a/app.js b/app.js index 451d39a36..883affca8 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,7 @@ var app = module.exports = express(); // database setup var connectionString = "postgres://localhost/videostore_api_" + app.get('env'); + var db = massive.connectSync({connectionString: connectionString}); app.set('db', db); diff --git a/controllers/rentals.js b/controllers/rentals.js index 9a488d846..16a89c687 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -1,7 +1,18 @@ +var Rental = require("../models/rental.js"); + var RentalsController = { - index: function(req, res, next) { - res.json("look, a rentals index!"); + show: function(req, res, next) { + Rental.findTitle(req.params.title, function(error, movie) { + if(error) { + var err = new Error("No such movie title"); + err.status = 404; + next(err); + } else { + res.json(movie); + }; + }); } }; + module.exports = RentalsController; diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 4f583e941..c0060a114 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -5,7 +5,8 @@ CREATE TABLE movies( title text, overview text, release_date text, - inventory integer, + total_inventory integer, + available_inventory integer, created_at timestamp, updated_at timestamp ); @@ -38,7 +39,6 @@ CREATE TABLE rentals( movie_id integer, customer_id integer, status text, - overview text, return_date timestamp, created_at timestamp, updated_at timestamp diff --git a/models/customer.js b/models/customer.js index 238fc08cb..7063097b5 100644 --- a/models/customer.js +++ b/models/customer.js @@ -18,8 +18,8 @@ var Customer = function(customerInfo) { // Instance functions -Customer.prototype.getCurrent = function(callback) { - db.customers.findOne(this.id, function(error, result) { +Customer.prototype.getCurrent = function(user_id, callback) { + db.customers.find({id: user_id}, {}, function(error, customers) { if(error) { callback(error, undefined); } else { @@ -31,19 +31,6 @@ Customer.prototype.getCurrent = function(callback) { return this; }; -// Customer.prototype.getCurrent = function(callback) { -// db.customers.findOne(this.id, function(error, result) { -// if(error) { -// callback(error, undefined); -// } else { -// callback(null, result.balance); -// } -// }); -// -// return this; -// }; - - Customer.all = function(callback) { db.customers.find(function(error, customers) { if(error || !customers) { diff --git a/models/movie.js b/models/movie.js index 333d58788..6603416df 100644 --- a/models/movie.js +++ b/models/movie.js @@ -5,6 +5,10 @@ var db = app.get("db"); var Movie = function(movieInfo) { this.id = movieInfo.id; this.title = movieInfo.title; + this.available_inventory = movieInfo.available_inventory; + this.total_inventory = movieInfo.total_inventory; + this.overview = movieInfo.overview; + this.release_date = movieInfo.release_date; }; diff --git a/models/rental.js b/models/rental.js new file mode 100644 index 000000000..5a7633064 --- /dev/null +++ b/models/rental.js @@ -0,0 +1,21 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Rental = function(rentalInfo) { + this.id = rentalInfo.id; + this.movie_id = rentalInfo.movie_id; + this.customer_id = rentalInfo.customer_id; + this.status = rentalInfo.status; //"returned" and "checkedOut" +}; + +// show title --> from movies --> overview, release_date, available inventory +Rental.find = function(movie_id, callback) { + db.movies.find({id: movie_id}, function(error, customer) { + if(error || !customer) { + callback(error || new Error("Account not found"), undefined); + } else { + callback(null, new Customer(customer)); + } + }); +}; diff --git a/routes/rentals.js b/routes/rentals.js index 4d460e29b..ac2f29e40 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -3,6 +3,6 @@ var router = express.Router(); var RentalsController = require('../controllers/rentals'); /* GET home page. */ -router.get('/', RentalsController.index); +router.get('/:title', RentalsController.show); module.exports = router; diff --git a/tasks/load_schema.js b/tasks/load_schema.js index aaa3f32a0..7cd4142ba 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,15 +1,22 @@ var massive = require('massive') +var count = 0; +var databaseType = ["test", "development"] +for(var type of databaseType){ + console.log(type) + var connectionString = "postgres://localhost/videostore_api_" + type; + console.log(connectionString) -var connectionString = "postgres://localhost/videostore_api_development"; -var connectionString = "postgres://localhost/videostore_api_test"; + // var connectionString = "postgres://localhost/videostore_api_test"; -var db = massive.connectSync({connectionString : connectionString}) + var db = massive.connectSync({connectionString : connectionString}) -db.setup.schema([], function(err, res) { - if (err) { - throw(new Error(err.message)) - } + db.setup.schema([], function(err, res) { + if (err) { + throw(new Error(err.message)) + } - console.log("yay schema!") - process.exit() -}) + console.log("yay schema!") + count ++ + if(count == 2){process.exit()} + }) +}; diff --git a/tasks/seed.js b/tasks/seed.js index 177110243..ad8bf54fe 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,31 +1,65 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostore_api_development"; -var connectionString = "postgres://localhost/videostore_api_test"; +var databaseCount = 0; +var databaseType = ["test", "development"] -var db = massive.connectSync({connectionString : connectionString}) -var customers = require('../db/seeds/customers.json'); -var movies = require('../db/seeds/movies.json'); -var date = new Date(); -var totalCount = customers.length + movies.length; +var seedDb = function(type){ + var connectionString = "postgres://localhost/videostore_api_" + type; -var count = 0 + var db = massive.connectSync({connectionString : connectionString}) -console.log(totalCount) + var customers = require('../db/seeds/customers.json'); + var movies = require('../db/seeds/movies.json'); -for(customer of customers){ - customer.created_at = date - db.customers.save(customer, function(err, result){ - count++ - if(count === totalCount){process.exit()} - }); -}; + var date = new Date(); + var totalCount = (customers.length + movies.length); + + var count = 0 + + console.log("Seeding to " + type + " database, total records: " + totalCount) + + for(customer of customers){ + customer.created_at = customer.updated_at = date + db.customers.save(customer, function(err, result){ + if(err) { + console.log("Unable to save customer " + movie.title + ": " + err.message) + } + + count++ + if(count === totalCount) { + console.log("Done seeding customers. " + count + " records seeded to " + type + " database.") + databaseCount++ + } + if(databaseCount === databaseType.length ) { + console.log("Done seeding both databases. " + count + " records seeded to " + type + " database.") + process.exit() + } + }); + }; + + for(movie of movies){ + movie.created_at = movie.updated_at = date + movie.total_inventory = movie.available_inventory = movie.inventory + delete movie.inventory + db.movies.save(movie, function(err, result){ + if(err) { + console.log("Unable to save movie " + movie.title + ": " + err.message) + } + + count++ + if(count === totalCount) { + console.log("Done seeding movies. " + count + " records seeded to " + type + " database.") + databaseCount++ + } + if(databaseCount === databaseType.length ) { + console.log("Done seeding both databases. " + count + " records seeded to " + type + " database.") + process.exit() + } + }); + }; +} -for(movie of movies){ - movie.created_at = date - db.movies.save(movie, function(err, result){ - count++ - if(count === totalCount){process.exit()} - }); +for(var type of databaseType){ + seedDb(type) }; From 3632ea9a6d1731db863564be4f1281eaa804552d Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 14:33:05 -0700 Subject: [PATCH 23/41] Got rentals show URL working --- controllers/rentals.js | 1 + models/rental.js | 15 ++++++++++----- routes/movies.js | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 16a89c687..258710212 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -2,6 +2,7 @@ var Rental = require("../models/rental.js"); var RentalsController = { show: function(req, res, next) { + console.log(req.params.title) Rental.findTitle(req.params.title, function(error, movie) { if(error) { var err = new Error("No such movie title"); diff --git a/models/rental.js b/models/rental.js index 5a7633064..b216b3ae8 100644 --- a/models/rental.js +++ b/models/rental.js @@ -1,4 +1,5 @@ var app = require("../app"); +var Movie = require("./movie.js"); var db = app.get("db"); // Constructor function @@ -10,12 +11,16 @@ var Rental = function(rentalInfo) { }; // show title --> from movies --> overview, release_date, available inventory -Rental.find = function(movie_id, callback) { - db.movies.find({id: movie_id}, function(error, customer) { - if(error || !customer) { - callback(error || new Error("Account not found"), undefined); +Rental.findTitle = function(movie_title, callback) { + db.movies.find({title: movie_title}, function(error, movies) { + if(error || !movies) { + callback(error || new Error("Movie with this title not found"), undefined); } else { - callback(null, new Customer(customer)); + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) } }); }; + +module.exports = Rental; diff --git a/routes/movies.js b/routes/movies.js index a787e6a33..ac724a76c 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -7,4 +7,6 @@ router.get('/', MoviesController.index); router.get('/sort/:sort_param', MoviesController.sort); +// router.get('/:title/current', MoviesController.current); + module.exports = router; From f12e2cfe0b1d25de35e82e4be78dd01da0d2067c Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 14:42:31 -0700 Subject: [PATCH 24/41] Adjusted rentals show method so it gives back a single instance of a movie instead of an array --- models/rental.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/models/rental.js b/models/rental.js index b216b3ae8..843a099dc 100644 --- a/models/rental.js +++ b/models/rental.js @@ -12,13 +12,11 @@ var Rental = function(rentalInfo) { // show title --> from movies --> overview, release_date, available inventory Rental.findTitle = function(movie_title, callback) { - db.movies.find({title: movie_title}, function(error, movies) { - if(error || !movies) { + db.movies.findOne({title: movie_title}, function(error, movie) { + if(error || !movie) { callback(error || new Error("Movie with this title not found"), undefined); } else { - callback(null, movies.map(function(movie) { - return new Movie(movie) - })) + callback(null, new Movie(movie)); } }); }; From 46f492b009e4d8f083bf6430c2d7e36760a3425e Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 14:44:42 -0700 Subject: [PATCH 25/41] Removed id from JSON response for rentals show route --- controllers/rentals.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/rentals.js b/controllers/rentals.js index 258710212..ec8aafb7c 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -9,6 +9,7 @@ var RentalsController = { err.status = 404; next(err); } else { + delete movie.id; res.json(movie); }; }); From 6810c88fdcfba6e258064dd521c4ee3fb2aaca53 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 15:02:58 -0700 Subject: [PATCH 26/41] Removed total_inventory column and replaced with regular ol inventory because test and development environment were getting different results because of STUFF --- db/setup/schema.sql | 2 +- routes/rentals.js | 2 ++ tasks/seed.js | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index c0060a114..e5c27feeb 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -5,7 +5,7 @@ CREATE TABLE movies( title text, overview text, release_date text, - total_inventory integer, + inventory integer, available_inventory integer, created_at timestamp, updated_at timestamp diff --git a/routes/rentals.js b/routes/rentals.js index ac2f29e40..922498a4e 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -5,4 +5,6 @@ var RentalsController = require('../controllers/rentals'); /* GET home page. */ router.get('/:title', RentalsController.show); +// router.post('/:title/check-out') + module.exports = router; diff --git a/tasks/seed.js b/tasks/seed.js index ad8bf54fe..f8827c8ea 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -40,8 +40,7 @@ var seedDb = function(type){ for(movie of movies){ movie.created_at = movie.updated_at = date - movie.total_inventory = movie.available_inventory = movie.inventory - delete movie.inventory + movie.available_inventory = movie.inventory db.movies.save(movie, function(err, result){ if(err) { console.log("Unable to save movie " + movie.title + ": " + err.message) From 812608d8ecfa13f3cb7c412b24024737d116d4b4 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 16:38:28 -0700 Subject: [PATCH 27/41] Added POST route for rentals/:title/check-out --- controllers/rentals.js | 15 ++++++++++++++- models/customer.js | 4 ++-- models/movie.js | 2 +- models/rental.js | 34 ++++++++++++++++++++++++++++++++++ routes/rentals.js | 2 +- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index ec8aafb7c..428983c04 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -2,7 +2,6 @@ var Rental = require("../models/rental.js"); var RentalsController = { show: function(req, res, next) { - console.log(req.params.title) Rental.findTitle(req.params.title, function(error, movie) { if(error) { var err = new Error("No such movie title"); @@ -13,6 +12,20 @@ var RentalsController = { res.json(movie); }; }); + }, + + checkOut: function(req, res, next) { + var customer_id = req.body.customer_id; + var title = req.params.title; + Rental.createCheckOut(customer_id, title, function(error, rental) { + if(error) { + var err = new Error("Rental checkout failed"); + err.status = 404; + next(err); + } else { + res.json(rental); + } + }); } }; diff --git a/models/customer.js b/models/customer.js index 7063097b5..629483f46 100644 --- a/models/customer.js +++ b/models/customer.js @@ -44,9 +44,9 @@ Customer.all = function(callback) { }; Customer.find = function(id, callback) { - db.accounts.findOne({id: id}, function(error, customer) { + db.customers.findOne({id: id}, function(error, customer) { if(error || !customer) { - callback(error || new Error("Account not found"), undefined); + callback(error || new Error("Customer not found"), undefined); } else { callback(null, new Customer(customer)); } diff --git a/models/movie.js b/models/movie.js index 6603416df..6b3ce0bf7 100644 --- a/models/movie.js +++ b/models/movie.js @@ -6,7 +6,7 @@ var Movie = function(movieInfo) { this.id = movieInfo.id; this.title = movieInfo.title; this.available_inventory = movieInfo.available_inventory; - this.total_inventory = movieInfo.total_inventory; + this.inventory = movieInfo.inventory; this.overview = movieInfo.overview; this.release_date = movieInfo.release_date; }; diff --git a/models/rental.js b/models/rental.js index 843a099dc..b0aabeb88 100644 --- a/models/rental.js +++ b/models/rental.js @@ -1,7 +1,11 @@ var app = require("../app"); var Movie = require("./movie.js"); +var Customer = require("./customer.js"); var db = app.get("db"); +var rental_days = 5; // due date is in 5 days + + // Constructor function var Rental = function(rentalInfo) { this.id = rentalInfo.id; @@ -21,4 +25,34 @@ Rental.findTitle = function(movie_title, callback) { }); }; +Rental.createCheckOut = function(customer_id, title, callback) { + Rental.findTitle(title, function(error, movie) { + if(error || !movie) { + callback(error); + } else if (error || movie.available_inventory < 1) { + callback(error || new Error("Availability issue: All movies of this title are currently checked out"), undefined) + } else { + Customer.find(customer_id, function(error, customer) { + if (error || !customer) { + callback(error); + } else { + var rentalInfo = { + movie_id: movie.id, + customer_id: customer_id, + created_at: Date(), + updated_at: Date(), + status: "checked-out", + return_date: new Date(new Date().getTime()+(5*24*60*60*1000)) + }; + + db.rentals.save(rentalInfo); + callback(null, new Rental(rentalInfo)); // creating instance of Rental through the constructor so that we can do instance-like things to the rental + } + }) + + } + }) + +}; + module.exports = Rental; diff --git a/routes/rentals.js b/routes/rentals.js index 922498a4e..461bef11d 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -5,6 +5,6 @@ var RentalsController = require('../controllers/rentals'); /* GET home page. */ router.get('/:title', RentalsController.show); -// router.post('/:title/check-out') +router.post('/:title/check-out', RentalsController.checkOut) module.exports = router; From 56cdff76b969ae0fec02ae8f1be77dd46af2c499 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Mon, 20 Jun 2016 16:52:54 -0700 Subject: [PATCH 28/41] added the rental fee to customer and now returning both rental and customer info in call back for rental/:title/check-out --- models/rental.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models/rental.js b/models/rental.js index b0aabeb88..9460a09b3 100644 --- a/models/rental.js +++ b/models/rental.js @@ -4,6 +4,8 @@ var Customer = require("./customer.js"); var db = app.get("db"); var rental_days = 5; // due date is in 5 days +var rentalFee = 2 + // Constructor function @@ -33,8 +35,8 @@ Rental.createCheckOut = function(customer_id, title, callback) { callback(error || new Error("Availability issue: All movies of this title are currently checked out"), undefined) } else { Customer.find(customer_id, function(error, customer) { - if (error || !customer) { - callback(error); + if (error || !customer || customer.account_credit < 2) { + callback(error || new Error("Insufficient Funds: Account Credit balance is less than $2.00")); } else { var rentalInfo = { movie_id: movie.id, @@ -44,9 +46,10 @@ Rental.createCheckOut = function(customer_id, title, callback) { status: "checked-out", return_date: new Date(new Date().getTime()+(5*24*60*60*1000)) }; - + var new_balance = customer.account_credit - rentalFee + db.customers.save{id: customer.id, account_credit: new_balance} db.rentals.save(rentalInfo); - callback(null, new Rental(rentalInfo)); // creating instance of Rental through the constructor so that we can do instance-like things to the rental + callback(null, [{rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}]); // creating instance of Rental through the constructor so that we can do instance-like things to the rental } }) From 0f8896e2b1f4522e618e7e7ad91c3cce2556e6ad Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 20 Jun 2016 17:12:06 -0700 Subject: [PATCH 29/41] Added callback to updating customer info. The account credit now goes down by 2 --- models/rental.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/models/rental.js b/models/rental.js index 9460a09b3..26a163efb 100644 --- a/models/rental.js +++ b/models/rental.js @@ -47,9 +47,15 @@ Rental.createCheckOut = function(customer_id, title, callback) { return_date: new Date(new Date().getTime()+(5*24*60*60*1000)) }; var new_balance = customer.account_credit - rentalFee - db.customers.save{id: customer.id, account_credit: new_balance} - db.rentals.save(rentalInfo); - callback(null, [{rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}]); // creating instance of Rental through the constructor so that we can do instance-like things to the rental + db.customers.save({id: customer.id, account_credit: new_balance}, function(error,updated){ + if (error){ + callback(error || new Error("Update Not Succesfull: Unable to update customer account credit")) + } else{ + db.rentals.save(rentalInfo); + callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); + } + }) + // creating instance of Rental through the constructor so that we can do instance-like things to the rental } }) From fd96a6185aaf615106e7a09211092026e824502c Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 21 Jun 2016 10:23:49 -0700 Subject: [PATCH 30/41] Working on Movies.current functionality --- controllers/movies.js | 13 ++++++++++++- models/movie.js | 43 +++++++++++++++++++++++++++++++++++++++++-- models/rental.js | 1 - routes/movies.js | 2 +- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 3259f6cec..437c034fb 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -16,7 +16,6 @@ var MoviesController = { }, sort: function(req, res, next) { - console.log(req.query); Movie.sort(req.params.sort_param, req.query.n, req.query.p, function (error, result) { if (error) { var err = new Error("Error retrieving movies:\n" + error.message); @@ -26,6 +25,18 @@ var MoviesController = { res.json(result); } }); + }, + + current: function(req, res, next) { + Movie.current(req.params.title, function (error, result) { + if (error) { + var err = new Error("Error retrieving movies:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(result); + } + }); } }; diff --git a/models/movie.js b/models/movie.js index 6b3ce0bf7..86ac85b45 100644 --- a/models/movie.js +++ b/models/movie.js @@ -48,7 +48,7 @@ Movie.sort = function (field, n, p, callback) { offset: p }; db.movies.find({}, sort_options, function(error, movies) { - if(error || !movies) { + if (error || !movies) { //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback. callback(error, undefined); } else { @@ -57,7 +57,46 @@ Movie.sort = function (field, n, p, callback) { })); } }); -} +}; + +Movie.current = function (title, callback) { + + // db. + + db.movies.findOne({title: title}, function(error, movie) { + if (error || !movie ) { + callback(error || new Error("No movie with that title"), undefined); + } else { + + db.rentals.find({ movie_id: movie.id }, function(error, rentals) { + if (error || !rentals) { + callback(error || new Error("Movie not currently being rented"), undefined); + } else { + + // for each rental, map an array of customer ids + var ids_of_customers_renting_movie = []; + for (var rental of rentals) { + ids_of_customers_renting_movie = rentals.map(function (rental) {return rental.customer_id;}) + } + + // find the customers that have those ids + for (var id of ids_of_customers_renting_movie) { + db.customers.find({ id: id }, function(error, customers) { + if ( error || !customers ) { + callback(error || new Error("No customer matching id"), undefined); + } else { + callback(null, customers); + } + }); + } + + } + }; + } + }); + + +}; diff --git a/models/rental.js b/models/rental.js index 26a163efb..26843b6e5 100644 --- a/models/rental.js +++ b/models/rental.js @@ -55,7 +55,6 @@ Rental.createCheckOut = function(customer_id, title, callback) { callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); } }) - // creating instance of Rental through the constructor so that we can do instance-like things to the rental } }) diff --git a/routes/movies.js b/routes/movies.js index ac724a76c..a59d089b0 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -7,6 +7,6 @@ router.get('/', MoviesController.index); router.get('/sort/:sort_param', MoviesController.sort); -// router.get('/:title/current', MoviesController.current); +router.get('/:title/current', MoviesController.current); module.exports = router; From 4a3ea360344534ddf61ee5257f3e6bcab2d83d43 Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 21 Jun 2016 14:49:00 -0700 Subject: [PATCH 31/41] Movie.current method now fully working. Changed time value for created_at and updated_at to fix timezone issue. Added callback to rental.save for new instance of rental. YAY THINGS WORK --- controllers/movies.js | 3 +++ models/movie.js | 37 ++++++++++++++++++++----------------- models/rental.js | 33 +++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 437c034fb..8c387feaa 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -34,6 +34,9 @@ var MoviesController = { err.status = 500; next(err); } else { + // if (result.length === 0) { + // res.status(204); //not working for some reason, fix later + // } res.json(result); } }); diff --git a/models/movie.js b/models/movie.js index 86ac85b45..63c7dbb32 100644 --- a/models/movie.js +++ b/models/movie.js @@ -61,37 +61,40 @@ Movie.sort = function (field, n, p, callback) { Movie.current = function (title, callback) { - // db. - db.movies.findOne({title: title}, function(error, movie) { if (error || !movie ) { callback(error || new Error("No movie with that title"), undefined); } else { - + // console.log(movie) db.rentals.find({ movie_id: movie.id }, function(error, rentals) { if (error || !rentals) { + // console.log(error.message) callback(error || new Error("Movie not currently being rented"), undefined); } else { - + console.log(rentals); // for each rental, map an array of customer ids - var ids_of_customers_renting_movie = []; - for (var rental of rentals) { - ids_of_customers_renting_movie = rentals.map(function (rental) {return rental.customer_id;}) + var ids_of_customers_renting_movie = rentals.map(function (rental) { return rental.customer_id;}) + + // handles situations when no rentals exist + if (ids_of_customers_renting_movie.length === 0) { + callback(null, []); } // find the customers that have those ids - for (var id of ids_of_customers_renting_movie) { - db.customers.find({ id: id }, function(error, customers) { - if ( error || !customers ) { - callback(error || new Error("No customer matching id"), undefined); - } else { - callback(null, customers); - } - }); - } + // for (var id of ids_of_customers_renting_movie) { + db.customers.find({ id: ids_of_customers_renting_movie }, function(error, customers) { + if ( error || !customers ) { + // console.log(ids_of_customers_renting_movie) + // console.log(error.message) + callback(error || new Error("No customer matching id"), undefined); + } else { + callback(null, customers); + } + }); + // } } - }; + }); } }); diff --git a/models/rental.js b/models/rental.js index 26843b6e5..096b9dd6e 100644 --- a/models/rental.js +++ b/models/rental.js @@ -41,20 +41,33 @@ Rental.createCheckOut = function(customer_id, title, callback) { var rentalInfo = { movie_id: movie.id, customer_id: customer_id, - created_at: Date(), - updated_at: Date(), + created_at: new Date(), + updated_at: new Date(), status: "checked-out", return_date: new Date(new Date().getTime()+(5*24*60*60*1000)) }; - var new_balance = customer.account_credit - rentalFee - db.customers.save({id: customer.id, account_credit: new_balance}, function(error,updated){ - if (error){ - callback(error || new Error("Update Not Succesfull: Unable to update customer account credit")) - } else{ - db.rentals.save(rentalInfo); - callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); + + console.log(rentalInfo.created_at) + console.log(rentalInfo.return_date) + + + + db.rentals.save(rentalInfo, function(error, rental) { + if (error) { + callback(error || new Error("Rental was not saved to database")) + } else { + var new_balance = customer.account_credit - rentalFee + db.customers.save({id: customer.id, account_credit: new_balance}, function(error,updated){ + if (error){ + callback(error || new Error("Update Not Succesfull: Unable to update customer account credit")) + } else { + callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); + } + }) + } - }) + }); + } }) From 02faef674b38d78eca34b5b21d5678158d24b5e2 Mon Sep 17 00:00:00 2001 From: Valerie Date: Tue, 21 Jun 2016 14:56:13 -0700 Subject: [PATCH 32/41] Inventory for movie now decreases when you check a copy out --- models/rental.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/models/rental.js b/models/rental.js index 096b9dd6e..4d3fd0768 100644 --- a/models/rental.js +++ b/models/rental.js @@ -47,11 +47,6 @@ Rental.createCheckOut = function(customer_id, title, callback) { return_date: new Date(new Date().getTime()+(5*24*60*60*1000)) }; - console.log(rentalInfo.created_at) - console.log(rentalInfo.return_date) - - - db.rentals.save(rentalInfo, function(error, rental) { if (error) { callback(error || new Error("Rental was not saved to database")) @@ -59,9 +54,16 @@ Rental.createCheckOut = function(customer_id, title, callback) { var new_balance = customer.account_credit - rentalFee db.customers.save({id: customer.id, account_credit: new_balance}, function(error,updated){ if (error){ - callback(error || new Error("Update Not Succesfull: Unable to update customer account credit")) + callback(error || new Error("Update Not Successful: Unable to update customer account credit")) } else { - callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); + var new_inventory = movie.available_inventory - 1; + db.movies.save({id: movie.id, available_inventory: new_inventory}, function(error, movie) { + if (error) { + callback(error || new Error("Unable to reduce inventory count")); + } else { + callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)}); + } + }) } }) From cf79f7dde57e2b90809fcb3411d95d86ded2863b Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 22 Jun 2016 20:46:19 -0700 Subject: [PATCH 33/41] Started documentation for movies routes --- controllers/index.js | 6 +++++ docs.json | 63 ++++++++++++++++++++++++++++++++++++++++++++ models/movie.js | 4 --- routes/index.js | 1 + 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 docs.json diff --git a/controllers/index.js b/controllers/index.js index f04ddf04b..8c63ac2a7 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -1,6 +1,12 @@ +var docs = require('../docs.json'); + var IndexController = { index: function(req, res, next) { res.json('It works!!'); + }, + + docsJSON: function(req, res, next) { + res.json(200, docs); } }; diff --git a/docs.json b/docs.json new file mode 100644 index 000000000..6cf3ba969 --- /dev/null +++ b/docs.json @@ -0,0 +1,63 @@ +{ + "base_url": "http://localhost:3000", + + "endpoint": [ + { + "verb": "GET", + "uri": "/", + "description": "lala", + "required_parameters": [], + "optional_parameters": [], + "return_data": { + "some_data": "lala", + "no_data": "lala", + "error": "lala" + } + }, + + { + "verb": "GET", + "uri": "/movies", + "description": "Returns a list of all movies that exist in the database.", + "required_parameters": [], + "optional_parameters": [], + "return_data": { + "some_data": "an array of movie data in JSON format", + "no_data": "[]", + "error": "Error retrieving movies" + } + }, + + { + "verb": "GET", + "uri": "/movies/sort/:sort_param", + "description": "Returns a list of movies in the database, sorted by a given parameter such as release_date. By using an optional query param, the amount displayed can be restrained.", + "required_parameters": [ + { + "parameter": "release_date", + "description": "movies returned will be sorted in ascending order by release_date" + }, + { + "parameter": "title", + "description": "movies returned will be sorted in ascending order by title, starting with numbers" + } + ], + "optional_parameters": [ + { + "parameter": "n", + "description": "a query parameter that determines the number of movie records to return" + }, + { + "parameter": "p", + "description": "a query parameter that determines the offset of movie records, to create pages of movies" + } + ], + "return_data": { + "some_data": "an array of movie data in JSON format", + "no_data": "[]", + "error": "Error retrieving movies" + } + } + + ] +} diff --git a/models/movie.js b/models/movie.js index 63c7dbb32..a7883c28b 100644 --- a/models/movie.js +++ b/models/movie.js @@ -65,7 +65,6 @@ Movie.current = function (title, callback) { if (error || !movie ) { callback(error || new Error("No movie with that title"), undefined); } else { - // console.log(movie) db.rentals.find({ movie_id: movie.id }, function(error, rentals) { if (error || !rentals) { // console.log(error.message) @@ -84,14 +83,11 @@ Movie.current = function (title, callback) { // for (var id of ids_of_customers_renting_movie) { db.customers.find({ id: ids_of_customers_renting_movie }, function(error, customers) { if ( error || !customers ) { - // console.log(ids_of_customers_renting_movie) - // console.log(error.message) callback(error || new Error("No customer matching id"), undefined); } else { callback(null, customers); } }); - // } } }); diff --git a/routes/index.js b/routes/index.js index b56ca02a3..0bf737a7f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -9,5 +9,6 @@ router.get('/zomg', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}); }); +router.get('/api/docs.json', IndexController.docsJSON) module.exports = router; From 2ae54b18eca65bea0d60407a2421a0a29a7143c8 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 23 Jun 2016 11:18:56 -0700 Subject: [PATCH 34/41] Finished documentation for movie routes --- docs.json | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/docs.json b/docs.json index 6cf3ba969..f5e387a74 100644 --- a/docs.json +++ b/docs.json @@ -1,17 +1,18 @@ { "base_url": "http://localhost:3000", + "data_format": "JSON", "endpoint": [ { "verb": "GET", "uri": "/", - "description": "lala", + "description": "The root page, simply confirms that you've successfully connected with the API", "required_parameters": [], "optional_parameters": [], "return_data": { - "some_data": "lala", - "no_data": "lala", - "error": "lala" + "some_data": "It works!!", + "no_data": "", + "error": "" } }, @@ -22,7 +23,7 @@ "required_parameters": [], "optional_parameters": [], "return_data": { - "some_data": "an array of movie data in JSON format", + "some_data": "an array of movie data", "no_data": "[]", "error": "Error retrieving movies" } @@ -31,7 +32,7 @@ { "verb": "GET", "uri": "/movies/sort/:sort_param", - "description": "Returns a list of movies in the database, sorted by a given parameter such as release_date. By using an optional query param, the amount displayed can be restrained.", + "description": "Returns a list of movies in the database, sorted by a given parameter such as release_date. By using an optional query param, the amount displayed can be limited.", "required_parameters": [ { "parameter": "release_date", @@ -53,7 +54,42 @@ } ], "return_data": { - "some_data": "an array of movie data in JSON format", + "some_data": "an array of movie data", + "no_data": "[]", + "error": "Error retrieving movies" + } + }, + + { + "verb": "GET", + "uri": "/movies/:title/current", + "description": "Returns a list of customers that have currently checked out a copy of the film.", + "required_parameters": [], + "optional_parameters": [], + "return_data": { + "some_data": "an array of customer data", + "no_data": "[]", + "error": "Error retrieving movies" + } + }, + + { + "verb": "GET", + "uri": "/movies/:title/history/sort/:sort_param", + "description": "Returns a list of customers that have checked out a film in the past", + "required_parameters": [ + { + "parameter": "name", + "description": "customers returned will be sorted in ascending order by customer name" + }, + { + "parameter": "created_at", + "description": "customers returned will be sorted in ascending order by the date of their rental (e.g., the date that rental record was created)" + } + ], + "optional_parameters": [], + "return_data": { + "some_data": "an array of customer data", "no_data": "[]", "error": "Error retrieving movies" } From 3501756417e126c1e73d78d2f463627f69d0fe79 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 23 Jun 2016 11:29:58 -0700 Subject: [PATCH 35/41] Currently working on api HTML version --- controllers/index.js | 5 +++++ public/stylesheets/style.css | 4 ++++ routes/index.js | 8 +++++--- views/docs.ejs | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 views/docs.ejs diff --git a/controllers/index.js b/controllers/index.js index 8c63ac2a7..2681dacfc 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -1,10 +1,15 @@ var docs = require('../docs.json'); +var docs_view = require('../views/docs.ejs') var IndexController = { index: function(req, res, next) { res.json('It works!!'); }, + docsHTML: function(req, res, next) { + res.render(docs_view); + }, + docsJSON: function(req, res, next) { res.json(200, docs); } diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 9453385b9..4c70d03a1 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -3,6 +3,10 @@ body { font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; } +header { + background-color: #00B7FF; +} + a { color: #00B7FF; } diff --git a/routes/index.js b/routes/index.js index 0bf737a7f..f3305fed8 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,11 +4,13 @@ var IndexController = require('../controllers/index.js'); router.get('/', IndexController.index); -/* test GET page. */ +router.get('/api/docs', IndexController.docsHTML); + +router.get('/api/docs.json', IndexController.docsJSON); + +/**** just a test ****/ router.get('/zomg', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}); }); -router.get('/api/docs.json', IndexController.docsJSON) - module.exports = router; diff --git a/views/docs.ejs b/views/docs.ejs new file mode 100644 index 000000000..e3cb76d56 --- /dev/null +++ b/views/docs.ejs @@ -0,0 +1,15 @@ + + + + VideoStoreAPI Documentation + + + + +
+

VideoStoreAPI

+

API Documentation

+
+ + + From c06f64293962e0c9dfa8970bc22fb354141529a4 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 09:51:20 -0700 Subject: [PATCH 36/41] Got HTML view set up for documentation --- app.js | 2 +- controllers/index.js | 4 ++-- package.json | 1 + views/docs.ejs | 7 +++++-- views/{error.jade => error.ejs} | 0 views/{index.jade => index.ejs} | 0 views/{layout.jade => layout.ejs} | 0 7 files changed, 9 insertions(+), 5 deletions(-) rename views/{error.jade => error.ejs} (100%) rename views/{index.jade => index.ejs} (100%) rename views/{layout.jade => layout.ejs} (100%) diff --git a/app.js b/app.js index 883affca8..f4a30b49f 100644 --- a/app.js +++ b/app.js @@ -17,7 +17,7 @@ app.set('db', db); // view engine setup app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'jade'); +app.set('view engine', 'ejs'); // uncomment after placing your favicon in /public //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); diff --git a/controllers/index.js b/controllers/index.js index 2681dacfc..16551960d 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -1,5 +1,5 @@ var docs = require('../docs.json'); -var docs_view = require('../views/docs.ejs') +// var docs_view = require('../views/docs.ejs') var IndexController = { index: function(req, res, next) { @@ -7,7 +7,7 @@ var IndexController = { }, docsHTML: function(req, res, next) { - res.render(docs_view); + res.render('docs'); }, docsJSON: function(req, res, next) { diff --git a/package.json b/package.json index 0f5e75c70..598a6fb2d 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "body-parser": "~1.13.2", "cookie-parser": "~1.3.5", "debug": "~2.2.0", + "ejs": "^2.4.2", "express": "~4.13.1", "jade": "~1.11.0", "massive": "^2.3.0", diff --git a/views/docs.ejs b/views/docs.ejs index e3cb76d56..0e0ed7a96 100644 --- a/views/docs.ejs +++ b/views/docs.ejs @@ -1,5 +1,5 @@ - - + + VideoStoreAPI Documentation @@ -9,6 +9,9 @@

VideoStoreAPI

API Documentation

+ + +
diff --git a/views/error.jade b/views/error.ejs similarity index 100% rename from views/error.jade rename to views/error.ejs diff --git a/views/index.jade b/views/index.ejs similarity index 100% rename from views/index.jade rename to views/index.ejs diff --git a/views/layout.jade b/views/layout.ejs similarity index 100% rename from views/layout.jade rename to views/layout.ejs From ecbb4c7f9bd15aeb01ceafb1bce62cb5bb7b9295 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 11:19:16 -0700 Subject: [PATCH 37/41] Trying to format HTML view of documentation to show up in a user-readable way --- controllers/index.js | 8 ++++++-- docs.json | 2 +- views/docs.ejs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/controllers/index.js b/controllers/index.js index 16551960d..0b3f55e2d 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -1,13 +1,17 @@ var docs = require('../docs.json'); -// var docs_view = require('../views/docs.ejs') var IndexController = { + locals: { + documentation: docs + }, + index: function(req, res, next) { res.json('It works!!'); }, docsHTML: function(req, res, next) { - res.render('docs'); + // console.log(string_docs); + res.render('docs', IndexController.locals); }, docsJSON: function(req, res, next) { diff --git a/docs.json b/docs.json index f5e387a74..e2bdf4c65 100644 --- a/docs.json +++ b/docs.json @@ -2,7 +2,7 @@ "base_url": "http://localhost:3000", "data_format": "JSON", - "endpoint": [ + "endpoints": [ { "verb": "GET", "uri": "/", diff --git a/views/docs.ejs b/views/docs.ejs index 0e0ed7a96..d510cb219 100644 --- a/views/docs.ejs +++ b/views/docs.ejs @@ -10,8 +10,21 @@

VideoStoreAPI

API Documentation

+ <% for (var top_endpoint of Object.keys(documentation)) { %> + <%= top_endpoint %> + <% } %> +

+ + <% for (var endpoint of documentation.endpoints) { %> + Endpoint:
+ <% for (var info of Object.keys(endpoint)) { %> + <%= info %>:
+ <%= endpoint[info] %>
+ <% } %> + + <% } %> From 35dcf4e7ed2d43629d2efe6d2089ea3bdc5bd3a8 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 11:35:02 -0700 Subject: [PATCH 38/41] Added formatting for readability to HTML view --- views/docs.ejs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/views/docs.ejs b/views/docs.ejs index d510cb219..465c1fb30 100644 --- a/views/docs.ejs +++ b/views/docs.ejs @@ -10,20 +10,27 @@

VideoStoreAPI

API Documentation

- <% for (var top_endpoint of Object.keys(documentation)) { %> - <%= top_endpoint %> + <% for (var top_endpoint in documentation) { %> + <%= top_endpoint.toUpperCase() %>: +
+ <%= documentation[top_endpoint] %> + + <% // if documentation[top_endpoint] is an array, do the stuff you were doing below%> + +
<% } %>

<% for (var endpoint of documentation.endpoints) { %> - Endpoint:
+ <% for (var info of Object.keys(endpoint)) { %> - <%= info %>:
+ <%= info.toUpperCase() %>:
<%= endpoint[info] %>
<% } %> +

<% } %> From 893c08bc3d20f74a825329fb2b17a797504f1f7c Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 14:55:44 -0700 Subject: [PATCH 39/41] HTML VERSION OF DOCUMENTATION IS FINALLY DONE, I SHOULD HAVE USED RECURSION AHHH --- views/docs.ejs | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/views/docs.ejs b/views/docs.ejs index 465c1fb30..c08c7742f 100644 --- a/views/docs.ejs +++ b/views/docs.ejs @@ -11,27 +11,53 @@

API Documentation

<% for (var top_endpoint in documentation) { %> - <%= top_endpoint.toUpperCase() %>: + <%= top_endpoint.toUpperCase() %>:
- <%= documentation[top_endpoint] %> + <% if (Array.isArray(documentation[top_endpoint])) { %> + <% for (var endpoint of documentation.endpoints) { %> +

+ <% for (var info in endpoint) { %> + <%= info.toUpperCase() %> +
+ <% value = endpoint[info] %> - <% // if documentation[top_endpoint] is an array, do the stuff you were doing below%> + <% if (Array.isArray(value)) { %> + <% for (var sub_info of value) { %> + <% for (var sub_sub_info in sub_info) { %> + <%= sub_sub_info.toUpperCase() %> +
+ <%= sub_info[sub_sub_info] %> +
+ <% } %> + <% } %> + <% } else if (typeof value === "object") { %> -
+ <% for (var sub_info in value) { %> + <%= sub_info.toUpperCase() %> +
+ <%= value[sub_info] %> +
+ <% } %> + <% } else { %> + <%= value %> +
+ <% } %> + <% } %> + +

+ <% } %> + + <% } else { %> + <%= documentation[top_endpoint] %> +
+ <% } %> <% } %> -

+

- <% for (var endpoint of documentation.endpoints) { %> - <% for (var info of Object.keys(endpoint)) { %> - <%= info.toUpperCase() %>:
- <%= endpoint[info] %>
- <% } %> -

- <% } %> From 33104106c953b74bb52f284f7d1a401b84e6c699 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 16:31:54 -0700 Subject: [PATCH 40/41] Added controller test to see if JSON is returned from json docs page --- package.json | 3 ++- spec/controllers/index.spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 598a6fb2d..1cb812a7a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "clear; ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/", + "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/", "db:drop": "dropdb videostore_api_development && dropdb videostore_api_test", "db:create": "createdb videostore_api_development && createdb videostore_api_test ", "db:schema": "clear; node tasks/load_schema.js", @@ -18,6 +18,7 @@ "debug": "~2.2.0", "ejs": "^2.4.2", "express": "~4.13.1", + "istanbul": "^0.4.4", "jade": "~1.11.0", "massive": "^2.3.0", "morgan": "~1.6.1", diff --git a/spec/controllers/index.spec.js b/spec/controllers/index.spec.js index 88ca20901..08d58dae5 100644 --- a/spec/controllers/index.spec.js +++ b/spec/controllers/index.spec.js @@ -8,4 +8,14 @@ describe("Endpoint at /", function () { done() }) }) + }); + +describe("Endpoint at api/docs.json", function () { + it('returns json', function (done) { + request.get(base_url + 'api/docs.json', function(error, response, body) { + expect(JSON.parse(response.body)).toBeTruthy; + done() + }) + }) +}) From 256f4e28dce64cc61fa746908aef71d5499c50f0 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 24 Jun 2016 23:13:33 -0700 Subject: [PATCH 41/41] Added a model test to movie model, and one controller test for rentals --- coverage/coverage.json | 1 + .../lcov-report/VideoStoreAPI/app.js.html | 293 +++++++++ .../controllers/customers.js.html | 197 ++++++ .../VideoStoreAPI/controllers/index.html | 132 ++++ .../VideoStoreAPI/controllers/index.js.html | 131 ++++ .../VideoStoreAPI/controllers/movies.js.html | 206 +++++++ .../VideoStoreAPI/controllers/rentals.js.html | 164 +++++ coverage/lcov-report/VideoStoreAPI/index.html | 93 +++ .../VideoStoreAPI/models/customer.js.html | 269 ++++++++ .../VideoStoreAPI/models/index.html | 119 ++++ .../VideoStoreAPI/models/movie.js.html | 383 ++++++++++++ .../VideoStoreAPI/models/rental.js.html | 308 ++++++++++ .../VideoStoreAPI/routes/customers.js.html | 101 +++ .../VideoStoreAPI/routes/index.html | 132 ++++ .../VideoStoreAPI/routes/index.js.html | 113 ++++ .../VideoStoreAPI/routes/movies.js.html | 101 +++ .../VideoStoreAPI/routes/rentals.js.html | 95 +++ coverage/lcov-report/base.css | 213 +++++++ coverage/lcov-report/index.html | 132 ++++ coverage/lcov-report/prettify.css | 1 + coverage/lcov-report/prettify.js | 1 + coverage/lcov-report/sort-arrow-sprite.png | Bin 0 -> 209 bytes coverage/lcov-report/sorter.js | 158 +++++ coverage/lcov.info | 581 ++++++++++++++++++ models/movie.js | 4 + spec/controllers/rentals.spec.js | 16 + spec/models/movie.spec.js | 24 + 27 files changed, 3968 insertions(+) create mode 100644 coverage/coverage.json create mode 100644 coverage/lcov-report/VideoStoreAPI/app.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/customers.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/index.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/movies.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/rentals.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/customer.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/movie.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/rental.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/customers.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/index.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/movies.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/rentals.js.html create mode 100644 coverage/lcov-report/base.css create mode 100644 coverage/lcov-report/index.html create mode 100644 coverage/lcov-report/prettify.css create mode 100644 coverage/lcov-report/prettify.js create mode 100644 coverage/lcov-report/sort-arrow-sprite.png create mode 100644 coverage/lcov-report/sorter.js create mode 100644 coverage/lcov.info diff --git a/coverage/coverage.json b/coverage/coverage.json new file mode 100644 index 000000000..d8bc35297 --- /dev/null +++ b/coverage/coverage.json @@ -0,0 +1 @@ +{"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/movie.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/movie.js","s":{"1":1,"2":1,"3":1,"4":100,"5":100,"6":100,"7":100,"8":100,"9":100,"10":1,"11":1,"12":1,"13":0,"14":1,"15":100,"16":1,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":1,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":1,"40":1,"41":1,"42":1},"b":{"1":[0,1],"2":[1,1],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[1,0]},"f":{"1":100,"2":1,"3":1,"4":100,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":1},"fnMap":{"1":{"name":"(anonymous_1)","line":5,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":32}}},"2":{"name":"(anonymous_2)","line":16,"loc":{"start":{"line":16,"column":12},"end":{"line":16,"column":32}}},"3":{"name":"(anonymous_3)","line":20,"loc":{"start":{"line":20,"column":34},"end":{"line":20,"column":58}}},"4":{"name":"(anonymous_4)","line":26,"loc":{"start":{"line":26,"column":32},"end":{"line":26,"column":48}}},"5":{"name":"(anonymous_5)","line":44,"loc":{"start":{"line":44,"column":13},"end":{"line":44,"column":46}}},"6":{"name":"(anonymous_6)","line":50,"loc":{"start":{"line":50,"column":35},"end":{"line":50,"column":59}}},"7":{"name":"(anonymous_7)","line":55,"loc":{"start":{"line":55,"column":32},"end":{"line":55,"column":48}}},"8":{"name":"(anonymous_8)","line":62,"loc":{"start":{"line":62,"column":16},"end":{"line":62,"column":43}}},"9":{"name":"(anonymous_9)","line":64,"loc":{"start":{"line":64,"column":36},"end":{"line":64,"column":59}}},"10":{"name":"(anonymous_10)","line":68,"loc":{"start":{"line":68,"column":46},"end":{"line":68,"column":71}}},"11":{"name":"(anonymous_11)","line":75,"loc":{"start":{"line":75,"column":59},"end":{"line":75,"column":77}}},"12":{"name":"(anonymous_12)","line":84,"loc":{"start":{"line":84,"column":68},"end":{"line":84,"column":95}}},"13":{"name":"(anonymous_13)","line":101,"loc":{"start":{"line":101,"column":14},"end":{"line":101,"column":26}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":23}},"3":{"start":{"line":5,"column":0},"end":{"line":12,"column":2}},"4":{"start":{"line":6,"column":2},"end":{"line":6,"column":25}},"5":{"start":{"line":7,"column":2},"end":{"line":7,"column":31}},"6":{"start":{"line":8,"column":2},"end":{"line":8,"column":59}},"7":{"start":{"line":9,"column":2},"end":{"line":9,"column":39}},"8":{"start":{"line":10,"column":2},"end":{"line":10,"column":37}},"9":{"start":{"line":11,"column":2},"end":{"line":11,"column":45}},"10":{"start":{"line":16,"column":0},"end":{"line":31,"column":2}},"11":{"start":{"line":20,"column":2},"end":{"line":30,"column":5}},"12":{"start":{"line":22,"column":4},"end":{"line":29,"column":5}},"13":{"start":{"line":24,"column":6},"end":{"line":24,"column":33}},"14":{"start":{"line":26,"column":6},"end":{"line":28,"column":10}},"15":{"start":{"line":27,"column":8},"end":{"line":27,"column":32}},"16":{"start":{"line":44,"column":0},"end":{"line":60,"column":2}},"17":{"start":{"line":45,"column":2},"end":{"line":49,"column":4}},"18":{"start":{"line":50,"column":2},"end":{"line":59,"column":5}},"19":{"start":{"line":51,"column":4},"end":{"line":58,"column":5}},"20":{"start":{"line":53,"column":6},"end":{"line":53,"column":33}},"21":{"start":{"line":55,"column":6},"end":{"line":57,"column":10}},"22":{"start":{"line":56,"column":8},"end":{"line":56,"column":32}},"23":{"start":{"line":62,"column":0},"end":{"line":98,"column":2}},"24":{"start":{"line":64,"column":2},"end":{"line":95,"column":5}},"25":{"start":{"line":65,"column":4},"end":{"line":94,"column":5}},"26":{"start":{"line":66,"column":6},"end":{"line":66,"column":74}},"27":{"start":{"line":68,"column":6},"end":{"line":93,"column":9}},"28":{"start":{"line":69,"column":8},"end":{"line":92,"column":9}},"29":{"start":{"line":71,"column":10},"end":{"line":71,"column":86}},"30":{"start":{"line":73,"column":10},"end":{"line":73,"column":31}},"31":{"start":{"line":75,"column":10},"end":{"line":75,"column":107}},"32":{"start":{"line":75,"column":79},"end":{"line":75,"column":105}},"33":{"start":{"line":78,"column":10},"end":{"line":80,"column":11}},"34":{"start":{"line":79,"column":12},"end":{"line":79,"column":31}},"35":{"start":{"line":84,"column":10},"end":{"line":90,"column":13}},"36":{"start":{"line":85,"column":12},"end":{"line":89,"column":13}},"37":{"start":{"line":86,"column":14},"end":{"line":86,"column":81}},"38":{"start":{"line":88,"column":14},"end":{"line":88,"column":40}},"39":{"start":{"line":100,"column":0},"end":{"line":102,"column":1}},"40":{"start":{"line":101,"column":2},"end":{"line":101,"column":38}},"41":{"start":{"line":101,"column":28},"end":{"line":101,"column":37}},"42":{"start":{"line":106,"column":0},"end":{"line":106,"column":23}}},"branchMap":{"1":{"line":22,"type":"if","locations":[{"start":{"line":22,"column":4},"end":{"line":22,"column":4}},{"start":{"line":22,"column":4},"end":{"line":22,"column":4}}]},"2":{"line":22,"type":"binary-expr","locations":[{"start":{"line":22,"column":7},"end":{"line":22,"column":12}},{"start":{"line":22,"column":16},"end":{"line":22,"column":23}}]},"3":{"line":51,"type":"if","locations":[{"start":{"line":51,"column":4},"end":{"line":51,"column":4}},{"start":{"line":51,"column":4},"end":{"line":51,"column":4}}]},"4":{"line":51,"type":"binary-expr","locations":[{"start":{"line":51,"column":8},"end":{"line":51,"column":13}},{"start":{"line":51,"column":17},"end":{"line":51,"column":24}}]},"5":{"line":65,"type":"if","locations":[{"start":{"line":65,"column":4},"end":{"line":65,"column":4}},{"start":{"line":65,"column":4},"end":{"line":65,"column":4}}]},"6":{"line":65,"type":"binary-expr","locations":[{"start":{"line":65,"column":8},"end":{"line":65,"column":13}},{"start":{"line":65,"column":17},"end":{"line":65,"column":23}}]},"7":{"line":66,"type":"binary-expr","locations":[{"start":{"line":66,"column":15},"end":{"line":66,"column":20}},{"start":{"line":66,"column":24},"end":{"line":66,"column":61}}]},"8":{"line":69,"type":"if","locations":[{"start":{"line":69,"column":8},"end":{"line":69,"column":8}},{"start":{"line":69,"column":8},"end":{"line":69,"column":8}}]},"9":{"line":69,"type":"binary-expr","locations":[{"start":{"line":69,"column":12},"end":{"line":69,"column":17}},{"start":{"line":69,"column":21},"end":{"line":69,"column":29}}]},"10":{"line":71,"type":"binary-expr","locations":[{"start":{"line":71,"column":19},"end":{"line":71,"column":24}},{"start":{"line":71,"column":28},"end":{"line":71,"column":73}}]},"11":{"line":78,"type":"if","locations":[{"start":{"line":78,"column":10},"end":{"line":78,"column":10}},{"start":{"line":78,"column":10},"end":{"line":78,"column":10}}]},"12":{"line":85,"type":"if","locations":[{"start":{"line":85,"column":12},"end":{"line":85,"column":12}},{"start":{"line":85,"column":12},"end":{"line":85,"column":12}}]},"13":{"line":85,"type":"binary-expr","locations":[{"start":{"line":85,"column":17},"end":{"line":85,"column":22}},{"start":{"line":85,"column":26},"end":{"line":85,"column":36}}]},"14":{"line":86,"type":"binary-expr","locations":[{"start":{"line":86,"column":23},"end":{"line":86,"column":28}},{"start":{"line":86,"column":32},"end":{"line":86,"column":68}}]},"15":{"line":100,"type":"if","locations":[{"start":{"line":100,"column":0},"end":{"line":100,"column":0}},{"start":{"line":100,"column":0},"end":{"line":100,"column":0}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/app.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/app.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":1,"20":1,"21":1,"22":1,"23":1,"24":1,"25":1,"26":1,"27":1,"28":0,"29":0,"30":0,"31":1,"32":0,"33":0,"34":0,"35":1,"36":0,"37":0,"38":1},"b":{"1":[0,1],"2":[0,0],"3":[0,0]},"f":{"1":0,"2":0,"3":0},"fnMap":{"1":{"name":"(anonymous_1)","line":45,"loc":{"start":{"line":45,"column":8},"end":{"line":45,"column":33}}},"2":{"name":"(anonymous_2)","line":56,"loc":{"start":{"line":56,"column":10},"end":{"line":56,"column":40}}},"3":{"name":"(anonymous_3)","line":67,"loc":{"start":{"line":67,"column":8},"end":{"line":67,"column":38}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":39}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":31}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":44}},"6":{"start":{"line":6,"column":0},"end":{"line":6,"column":40}},"7":{"start":{"line":8,"column":0},"end":{"line":8,"column":32}},"8":{"start":{"line":10,"column":0},"end":{"line":10,"column":37}},"9":{"start":{"line":13,"column":0},"end":{"line":13,"column":79}},"10":{"start":{"line":15,"column":0},"end":{"line":15,"column":67}},"11":{"start":{"line":16,"column":0},"end":{"line":16,"column":18}},"12":{"start":{"line":19,"column":0},"end":{"line":19,"column":48}},"13":{"start":{"line":20,"column":0},"end":{"line":20,"column":30}},"14":{"start":{"line":24,"column":0},"end":{"line":24,"column":23}},"15":{"start":{"line":25,"column":0},"end":{"line":25,"column":27}},"16":{"start":{"line":26,"column":0},"end":{"line":26,"column":52}},"17":{"start":{"line":27,"column":0},"end":{"line":27,"column":24}},"18":{"start":{"line":28,"column":0},"end":{"line":28,"column":56}},"19":{"start":{"line":31,"column":0},"end":{"line":31,"column":44}},"20":{"start":{"line":32,"column":0},"end":{"line":32,"column":26}},"21":{"start":{"line":34,"column":0},"end":{"line":34,"column":51}},"22":{"start":{"line":35,"column":0},"end":{"line":35,"column":38}},"23":{"start":{"line":37,"column":0},"end":{"line":37,"column":45}},"24":{"start":{"line":38,"column":0},"end":{"line":38,"column":32}},"25":{"start":{"line":40,"column":0},"end":{"line":40,"column":47}},"26":{"start":{"line":41,"column":0},"end":{"line":41,"column":34}},"27":{"start":{"line":45,"column":0},"end":{"line":49,"column":3}},"28":{"start":{"line":46,"column":2},"end":{"line":46,"column":35}},"29":{"start":{"line":47,"column":2},"end":{"line":47,"column":19}},"30":{"start":{"line":48,"column":2},"end":{"line":48,"column":12}},"31":{"start":{"line":55,"column":0},"end":{"line":63,"column":1}},"32":{"start":{"line":56,"column":2},"end":{"line":62,"column":5}},"33":{"start":{"line":57,"column":4},"end":{"line":57,"column":34}},"34":{"start":{"line":58,"column":4},"end":{"line":61,"column":7}},"35":{"start":{"line":67,"column":0},"end":{"line":73,"column":3}},"36":{"start":{"line":68,"column":2},"end":{"line":68,"column":32}},"37":{"start":{"line":69,"column":2},"end":{"line":72,"column":5}},"38":{"start":{"line":76,"column":0},"end":{"line":76,"column":21}}},"branchMap":{"1":{"line":55,"type":"if","locations":[{"start":{"line":55,"column":0},"end":{"line":55,"column":0}},{"start":{"line":55,"column":0},"end":{"line":55,"column":0}}]},"2":{"line":57,"type":"binary-expr","locations":[{"start":{"line":57,"column":15},"end":{"line":57,"column":25}},{"start":{"line":57,"column":29},"end":{"line":57,"column":32}}]},"3":{"line":68,"type":"binary-expr","locations":[{"start":{"line":68,"column":13},"end":{"line":68,"column":23}},{"start":{"line":68,"column":27},"end":{"line":68,"column":30}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/index.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":0,"9":1},"b":{},"f":{"1":0},"fnMap":{"1":{"name":"(anonymous_1)","line":12,"loc":{"start":{"line":12,"column":20},"end":{"line":12,"column":45}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":30}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":57}},"4":{"start":{"line":5,"column":0},"end":{"line":5,"column":39}},"5":{"start":{"line":7,"column":0},"end":{"line":7,"column":50}},"6":{"start":{"line":9,"column":0},"end":{"line":9,"column":55}},"7":{"start":{"line":12,"column":0},"end":{"line":14,"column":3}},"8":{"start":{"line":13,"column":2},"end":{"line":13,"column":48}},"9":{"start":{"line":16,"column":0},"end":{"line":16,"column":24}}},"branchMap":{}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/index.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/index.js","s":{"1":1,"2":1,"3":0,"4":0,"5":0,"6":1},"b":{},"f":{"1":0,"2":0,"3":0},"fnMap":{"1":{"name":"(anonymous_1)","line":8,"loc":{"start":{"line":8,"column":9},"end":{"line":8,"column":34}}},"2":{"name":"(anonymous_2)","line":12,"loc":{"start":{"line":12,"column":12},"end":{"line":12,"column":37}}},"3":{"name":"(anonymous_3)","line":17,"loc":{"start":{"line":17,"column":12},"end":{"line":17,"column":37}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},"2":{"start":{"line":3,"column":0},"end":{"line":20,"column":2}},"3":{"start":{"line":9,"column":4},"end":{"line":9,"column":27}},"4":{"start":{"line":14,"column":4},"end":{"line":14,"column":47}},"5":{"start":{"line":18,"column":4},"end":{"line":18,"column":24}},"6":{"start":{"line":22,"column":0},"end":{"line":22,"column":33}}},"branchMap":{}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/customers.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/customers.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1},"b":{},"f":{},"fnMap":{},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":30}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":61}},"4":{"start":{"line":6,"column":0},"end":{"line":6,"column":42}},"5":{"start":{"line":8,"column":0},"end":{"line":8,"column":54}},"6":{"start":{"line":10,"column":0},"end":{"line":10,"column":64}},"7":{"start":{"line":12,"column":0},"end":{"line":12,"column":24}}},"branchMap":{}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/customers.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/customers.js","s":{"1":1,"2":1,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":34}}},"2":{"name":"(anonymous_2)","line":5,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":44}}},"3":{"name":"(anonymous_3)","line":15,"loc":{"start":{"line":15,"column":11},"end":{"line":15,"column":36}}},"4":{"name":"(anonymous_4)","line":16,"loc":{"start":{"line":16,"column":35},"end":{"line":16,"column":61}}},"5":{"name":"(anonymous_5)","line":22,"loc":{"start":{"line":22,"column":30},"end":{"line":22,"column":55}}},"6":{"name":"(anonymous_6)","line":28,"loc":{"start":{"line":28,"column":8},"end":{"line":28,"column":33}}},"7":{"name":"(anonymous_7)","line":30,"loc":{"start":{"line":30,"column":27},"end":{"line":30,"column":54}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}},"2":{"start":{"line":3,"column":0},"end":{"line":41,"column":2}},"3":{"start":{"line":5,"column":4},"end":{"line":13,"column":7}},"4":{"start":{"line":6,"column":6},"end":{"line":12,"column":7}},"5":{"start":{"line":7,"column":8},"end":{"line":7,"column":81}},"6":{"start":{"line":8,"column":8},"end":{"line":8,"column":25}},"7":{"start":{"line":9,"column":8},"end":{"line":9,"column":18}},"8":{"start":{"line":11,"column":8},"end":{"line":11,"column":28}},"9":{"start":{"line":16,"column":6},"end":{"line":26,"column":9}},"10":{"start":{"line":17,"column":8},"end":{"line":25,"column":9}},"11":{"start":{"line":18,"column":10},"end":{"line":18,"column":50}},"12":{"start":{"line":19,"column":10},"end":{"line":19,"column":27}},"13":{"start":{"line":20,"column":10},"end":{"line":20,"column":20}},"14":{"start":{"line":22,"column":10},"end":{"line":24,"column":13}},"15":{"start":{"line":23,"column":12},"end":{"line":23,"column":32}},"16":{"start":{"line":29,"column":4},"end":{"line":29,"column":85}},"17":{"start":{"line":30,"column":4},"end":{"line":38,"column":7}},"18":{"start":{"line":31,"column":6},"end":{"line":37,"column":7}},"19":{"start":{"line":32,"column":8},"end":{"line":32,"column":81}},"20":{"start":{"line":33,"column":8},"end":{"line":33,"column":25}},"21":{"start":{"line":34,"column":8},"end":{"line":34,"column":18}},"22":{"start":{"line":36,"column":8},"end":{"line":36,"column":28}},"23":{"start":{"line":44,"column":0},"end":{"line":44,"column":37}}},"branchMap":{"1":{"line":6,"type":"if","locations":[{"start":{"line":6,"column":6},"end":{"line":6,"column":6}},{"start":{"line":6,"column":6},"end":{"line":6,"column":6}}]},"2":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":8},"end":{"line":17,"column":8}},{"start":{"line":17,"column":8},"end":{"line":17,"column":8}}]},"3":{"line":31,"type":"if","locations":[{"start":{"line":31,"column":6},"end":{"line":31,"column":6}},{"start":{"line":31,"column":6},"end":{"line":31,"column":6}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/customer.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/customer.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":1,"16":0,"17":0,"18":0,"19":0,"20":0,"21":1,"22":0,"23":0,"24":0,"25":0,"26":0,"27":1,"28":0,"29":0,"30":0,"31":0,"32":1,"33":0,"34":0,"35":0,"36":0,"37":0,"38":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},"fnMap":{"1":{"name":"(anonymous_1)","line":5,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":38}}},"2":{"name":"(anonymous_2)","line":21,"loc":{"start":{"line":21,"column":32},"end":{"line":21,"column":60}}},"3":{"name":"(anonymous_3)","line":22,"loc":{"start":{"line":22,"column":39},"end":{"line":22,"column":66}}},"4":{"name":"(anonymous_4)","line":34,"loc":{"start":{"line":34,"column":15},"end":{"line":34,"column":34}}},"5":{"name":"(anonymous_5)","line":35,"loc":{"start":{"line":35,"column":20},"end":{"line":35,"column":47}}},"6":{"name":"(anonymous_6)","line":39,"loc":{"start":{"line":39,"column":35},"end":{"line":39,"column":54}}},"7":{"name":"(anonymous_7)","line":46,"loc":{"start":{"line":46,"column":16},"end":{"line":46,"column":39}}},"8":{"name":"(anonymous_8)","line":47,"loc":{"start":{"line":47,"column":33},"end":{"line":47,"column":59}}},"9":{"name":"(anonymous_9)","line":56,"loc":{"start":{"line":56,"column":16},"end":{"line":56,"column":43}}},"10":{"name":"(anonymous_10)","line":57,"loc":{"start":{"line":57,"column":33},"end":{"line":57,"column":60}}},"11":{"name":"(anonymous_11)","line":61,"loc":{"start":{"line":61,"column":35},"end":{"line":61,"column":54}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":23}},"3":{"start":{"line":5,"column":0},"end":{"line":17,"column":2}},"4":{"start":{"line":6,"column":2},"end":{"line":6,"column":28}},"5":{"start":{"line":7,"column":2},"end":{"line":7,"column":32}},"6":{"start":{"line":8,"column":2},"end":{"line":8,"column":38}},"7":{"start":{"line":9,"column":2},"end":{"line":9,"column":32}},"8":{"start":{"line":10,"column":2},"end":{"line":10,"column":34}},"9":{"start":{"line":11,"column":2},"end":{"line":11,"column":46}},"10":{"start":{"line":12,"column":2},"end":{"line":12,"column":52}},"11":{"start":{"line":13,"column":2},"end":{"line":13,"column":34}},"12":{"start":{"line":14,"column":2},"end":{"line":14,"column":50}},"13":{"start":{"line":15,"column":2},"end":{"line":15,"column":44}},"14":{"start":{"line":16,"column":2},"end":{"line":16,"column":44}},"15":{"start":{"line":21,"column":0},"end":{"line":32,"column":2}},"16":{"start":{"line":22,"column":2},"end":{"line":29,"column":5}},"17":{"start":{"line":23,"column":4},"end":{"line":28,"column":5}},"18":{"start":{"line":24,"column":6},"end":{"line":24,"column":33}},"19":{"start":{"line":27,"column":6},"end":{"line":27,"column":37}},"20":{"start":{"line":31,"column":2},"end":{"line":31,"column":14}},"21":{"start":{"line":34,"column":0},"end":{"line":44,"column":2}},"22":{"start":{"line":35,"column":2},"end":{"line":43,"column":5}},"23":{"start":{"line":36,"column":4},"end":{"line":42,"column":5}},"24":{"start":{"line":37,"column":6},"end":{"line":37,"column":78}},"25":{"start":{"line":39,"column":6},"end":{"line":41,"column":10}},"26":{"start":{"line":40,"column":8},"end":{"line":40,"column":38}},"27":{"start":{"line":46,"column":0},"end":{"line":54,"column":2}},"28":{"start":{"line":47,"column":2},"end":{"line":53,"column":5}},"29":{"start":{"line":48,"column":4},"end":{"line":52,"column":5}},"30":{"start":{"line":49,"column":6},"end":{"line":49,"column":68}},"31":{"start":{"line":51,"column":6},"end":{"line":51,"column":45}},"32":{"start":{"line":56,"column":0},"end":{"line":66,"column":2}},"33":{"start":{"line":57,"column":2},"end":{"line":65,"column":5}},"34":{"start":{"line":58,"column":4},"end":{"line":64,"column":5}},"35":{"start":{"line":59,"column":6},"end":{"line":59,"column":78}},"36":{"start":{"line":61,"column":6},"end":{"line":63,"column":10}},"37":{"start":{"line":62,"column":8},"end":{"line":62,"column":38}},"38":{"start":{"line":68,"column":0},"end":{"line":68,"column":26}}},"branchMap":{"1":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":4},"end":{"line":23,"column":4}},{"start":{"line":23,"column":4},"end":{"line":23,"column":4}}]},"2":{"line":36,"type":"if","locations":[{"start":{"line":36,"column":4},"end":{"line":36,"column":4}},{"start":{"line":36,"column":4},"end":{"line":36,"column":4}}]},"3":{"line":36,"type":"binary-expr","locations":[{"start":{"line":36,"column":7},"end":{"line":36,"column":12}},{"start":{"line":36,"column":16},"end":{"line":36,"column":26}}]},"4":{"line":37,"type":"binary-expr","locations":[{"start":{"line":37,"column":15},"end":{"line":37,"column":20}},{"start":{"line":37,"column":24},"end":{"line":37,"column":65}}]},"5":{"line":48,"type":"if","locations":[{"start":{"line":48,"column":4},"end":{"line":48,"column":4}},{"start":{"line":48,"column":4},"end":{"line":48,"column":4}}]},"6":{"line":48,"type":"binary-expr","locations":[{"start":{"line":48,"column":7},"end":{"line":48,"column":12}},{"start":{"line":48,"column":16},"end":{"line":48,"column":25}}]},"7":{"line":49,"type":"binary-expr","locations":[{"start":{"line":49,"column":15},"end":{"line":49,"column":20}},{"start":{"line":49,"column":24},"end":{"line":49,"column":55}}]},"8":{"line":58,"type":"if","locations":[{"start":{"line":58,"column":4},"end":{"line":58,"column":4}},{"start":{"line":58,"column":4},"end":{"line":58,"column":4}}]},"9":{"line":58,"type":"binary-expr","locations":[{"start":{"line":58,"column":7},"end":{"line":58,"column":12}},{"start":{"line":58,"column":16},"end":{"line":58,"column":26}}]},"10":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":15},"end":{"line":59,"column":20}},{"start":{"line":59,"column":24},"end":{"line":59,"column":65}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/movies.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/movies.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1},"b":{},"f":{},"fnMap":{},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":30}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":56}},"4":{"start":{"line":6,"column":0},"end":{"line":6,"column":40}},"5":{"start":{"line":8,"column":0},"end":{"line":8,"column":55}},"6":{"start":{"line":10,"column":0},"end":{"line":10,"column":56}},"7":{"start":{"line":12,"column":0},"end":{"line":12,"column":24}}},"branchMap":{}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/movies.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/movies.js","s":{"1":1,"2":1,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0},"fnMap":{"1":{"name":"(anonymous_1)","line":5,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":34}}},"2":{"name":"(anonymous_2)","line":6,"loc":{"start":{"line":6,"column":14},"end":{"line":6,"column":39}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":8},"end":{"line":18,"column":33}}},"4":{"name":"(anonymous_4)","line":19,"loc":{"start":{"line":19,"column":64},"end":{"line":19,"column":89}}},"5":{"name":"(anonymous_5)","line":30,"loc":{"start":{"line":30,"column":11},"end":{"line":30,"column":36}}},"6":{"name":"(anonymous_6)","line":31,"loc":{"start":{"line":31,"column":36},"end":{"line":31,"column":61}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":42}},"2":{"start":{"line":4,"column":0},"end":{"line":45,"column":2}},"3":{"start":{"line":6,"column":4},"end":{"line":14,"column":7}},"4":{"start":{"line":7,"column":6},"end":{"line":13,"column":7}},"5":{"start":{"line":8,"column":8},"end":{"line":8,"column":74}},"6":{"start":{"line":9,"column":8},"end":{"line":9,"column":25}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":18}},"8":{"start":{"line":12,"column":8},"end":{"line":12,"column":25}},"9":{"start":{"line":19,"column":4},"end":{"line":27,"column":7}},"10":{"start":{"line":20,"column":6},"end":{"line":26,"column":7}},"11":{"start":{"line":21,"column":8},"end":{"line":21,"column":74}},"12":{"start":{"line":22,"column":8},"end":{"line":22,"column":25}},"13":{"start":{"line":23,"column":8},"end":{"line":23,"column":18}},"14":{"start":{"line":25,"column":8},"end":{"line":25,"column":25}},"15":{"start":{"line":31,"column":4},"end":{"line":42,"column":7}},"16":{"start":{"line":32,"column":6},"end":{"line":41,"column":7}},"17":{"start":{"line":33,"column":8},"end":{"line":33,"column":74}},"18":{"start":{"line":34,"column":8},"end":{"line":34,"column":25}},"19":{"start":{"line":35,"column":8},"end":{"line":35,"column":18}},"20":{"start":{"line":40,"column":8},"end":{"line":40,"column":25}},"21":{"start":{"line":47,"column":0},"end":{"line":47,"column":34}}},"branchMap":{"1":{"line":7,"type":"if","locations":[{"start":{"line":7,"column":6},"end":{"line":7,"column":6}},{"start":{"line":7,"column":6},"end":{"line":7,"column":6}}]},"2":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":6},"end":{"line":20,"column":6}},{"start":{"line":20,"column":6},"end":{"line":20,"column":6}}]},"3":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":6},"end":{"line":32,"column":6}},{"start":{"line":32,"column":6},"end":{"line":32,"column":6}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/rentals.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/rentals.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1},"b":{},"f":{},"fnMap":{},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":30}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":58}},"4":{"start":{"line":6,"column":0},"end":{"line":6,"column":46}},"5":{"start":{"line":8,"column":0},"end":{"line":8,"column":60}},"6":{"start":{"line":10,"column":0},"end":{"line":10,"column":24}}},"branchMap":{}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/rentals.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/rentals.js","s":{"1":1,"2":1,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":1},"b":{"1":[0,0],"2":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":33}}},"2":{"name":"(anonymous_2)","line":5,"loc":{"start":{"line":5,"column":39},"end":{"line":5,"column":62}}},"3":{"name":"(anonymous_3)","line":17,"loc":{"start":{"line":17,"column":12},"end":{"line":17,"column":37}}},"4":{"name":"(anonymous_4)","line":20,"loc":{"start":{"line":20,"column":46},"end":{"line":20,"column":70}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},"2":{"start":{"line":3,"column":0},"end":{"line":30,"column":2}},"3":{"start":{"line":5,"column":4},"end":{"line":14,"column":7}},"4":{"start":{"line":6,"column":6},"end":{"line":13,"column":9}},"5":{"start":{"line":7,"column":8},"end":{"line":7,"column":51}},"6":{"start":{"line":8,"column":8},"end":{"line":8,"column":25}},"7":{"start":{"line":9,"column":8},"end":{"line":9,"column":18}},"8":{"start":{"line":11,"column":10},"end":{"line":11,"column":26}},"9":{"start":{"line":12,"column":10},"end":{"line":12,"column":26}},"10":{"start":{"line":18,"column":4},"end":{"line":18,"column":43}},"11":{"start":{"line":19,"column":4},"end":{"line":19,"column":33}},"12":{"start":{"line":20,"column":4},"end":{"line":28,"column":7}},"13":{"start":{"line":21,"column":6},"end":{"line":27,"column":7}},"14":{"start":{"line":22,"column":8},"end":{"line":22,"column":54}},"15":{"start":{"line":23,"column":8},"end":{"line":23,"column":25}},"16":{"start":{"line":24,"column":8},"end":{"line":24,"column":18}},"17":{"start":{"line":26,"column":8},"end":{"line":26,"column":25}},"18":{"start":{"line":33,"column":0},"end":{"line":33,"column":35}}},"branchMap":{"1":{"line":6,"type":"if","locations":[{"start":{"line":6,"column":6},"end":{"line":6,"column":6}},{"start":{"line":6,"column":6},"end":{"line":6,"column":6}}]},"2":{"line":21,"type":"if","locations":[{"start":{"line":21,"column":6},"end":{"line":21,"column":6}},{"start":{"line":21,"column":6},"end":{"line":21,"column":6}}]}}},"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/rental.js":{"path":"/Users/valerieconklin/C5/projects/VideoStoreAPI/models/rental.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":0,"9":0,"10":0,"11":0,"12":1,"13":0,"14":0,"15":0,"16":0,"17":1,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0},"fnMap":{"1":{"name":"(anonymous_1)","line":12,"loc":{"start":{"line":12,"column":13},"end":{"line":12,"column":34}}},"2":{"name":"(anonymous_2)","line":20,"loc":{"start":{"line":20,"column":19},"end":{"line":20,"column":51}}},"3":{"name":"(anonymous_3)","line":21,"loc":{"start":{"line":21,"column":42},"end":{"line":21,"column":65}}},"4":{"name":"(anonymous_4)","line":30,"loc":{"start":{"line":30,"column":24},"end":{"line":30,"column":63}}},"5":{"name":"(anonymous_5)","line":31,"loc":{"start":{"line":31,"column":26},"end":{"line":31,"column":49}}},"6":{"name":"(anonymous_6)","line":37,"loc":{"start":{"line":37,"column":33},"end":{"line":37,"column":59}}},"7":{"name":"(anonymous_7)","line":50,"loc":{"start":{"line":50,"column":38},"end":{"line":50,"column":62}}},"8":{"name":"(anonymous_8)","line":55,"loc":{"start":{"line":55,"column":80},"end":{"line":55,"column":103}}},"9":{"name":"(anonymous_9)","line":60,"loc":{"start":{"line":60,"column":85},"end":{"line":60,"column":108}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":34}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":40}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":23}},"5":{"start":{"line":6,"column":0},"end":{"line":6,"column":20}},"6":{"start":{"line":7,"column":0},"end":{"line":7,"column":17}},"7":{"start":{"line":12,"column":0},"end":{"line":17,"column":2}},"8":{"start":{"line":13,"column":2},"end":{"line":13,"column":26}},"9":{"start":{"line":14,"column":2},"end":{"line":14,"column":38}},"10":{"start":{"line":15,"column":2},"end":{"line":15,"column":44}},"11":{"start":{"line":16,"column":2},"end":{"line":16,"column":34}},"12":{"start":{"line":20,"column":0},"end":{"line":28,"column":2}},"13":{"start":{"line":21,"column":2},"end":{"line":27,"column":5}},"14":{"start":{"line":22,"column":4},"end":{"line":26,"column":5}},"15":{"start":{"line":23,"column":6},"end":{"line":23,"column":81}},"16":{"start":{"line":25,"column":6},"end":{"line":25,"column":39}},"17":{"start":{"line":30,"column":0},"end":{"line":79,"column":2}},"18":{"start":{"line":31,"column":2},"end":{"line":77,"column":4}},"19":{"start":{"line":32,"column":4},"end":{"line":76,"column":5}},"20":{"start":{"line":33,"column":6},"end":{"line":33,"column":22}},"21":{"start":{"line":34,"column":11},"end":{"line":76,"column":5}},"22":{"start":{"line":35,"column":6},"end":{"line":35,"column":119}},"23":{"start":{"line":37,"column":6},"end":{"line":74,"column":8}},"24":{"start":{"line":38,"column":8},"end":{"line":73,"column":9}},"25":{"start":{"line":39,"column":10},"end":{"line":39,"column":104}},"26":{"start":{"line":41,"column":10},"end":{"line":48,"column":12}},"27":{"start":{"line":50,"column":10},"end":{"line":71,"column":13}},"28":{"start":{"line":51,"column":12},"end":{"line":70,"column":13}},"29":{"start":{"line":52,"column":14},"end":{"line":52,"column":78}},"30":{"start":{"line":54,"column":14},"end":{"line":54,"column":67}},"31":{"start":{"line":55,"column":14},"end":{"line":68,"column":16}},"32":{"start":{"line":56,"column":16},"end":{"line":67,"column":17}},"33":{"start":{"line":57,"column":18},"end":{"line":57,"column":113}},"34":{"start":{"line":59,"column":18},"end":{"line":59,"column":68}},"35":{"start":{"line":60,"column":18},"end":{"line":66,"column":20}},"36":{"start":{"line":61,"column":20},"end":{"line":65,"column":21}},"37":{"start":{"line":62,"column":22},"end":{"line":62,"column":87}},"38":{"start":{"line":64,"column":22},"end":{"line":64,"column":113}},"39":{"start":{"line":81,"column":0},"end":{"line":81,"column":24}}},"branchMap":{"1":{"line":22,"type":"if","locations":[{"start":{"line":22,"column":4},"end":{"line":22,"column":4}},{"start":{"line":22,"column":4},"end":{"line":22,"column":4}}]},"2":{"line":22,"type":"binary-expr","locations":[{"start":{"line":22,"column":7},"end":{"line":22,"column":12}},{"start":{"line":22,"column":16},"end":{"line":22,"column":22}}]},"3":{"line":23,"type":"binary-expr","locations":[{"start":{"line":23,"column":15},"end":{"line":23,"column":20}},{"start":{"line":23,"column":24},"end":{"line":23,"column":68}}]},"4":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":4},"end":{"line":32,"column":4}},{"start":{"line":32,"column":4},"end":{"line":32,"column":4}}]},"5":{"line":32,"type":"binary-expr","locations":[{"start":{"line":32,"column":7},"end":{"line":32,"column":12}},{"start":{"line":32,"column":16},"end":{"line":32,"column":22}}]},"6":{"line":34,"type":"if","locations":[{"start":{"line":34,"column":11},"end":{"line":34,"column":11}},{"start":{"line":34,"column":11},"end":{"line":34,"column":11}}]},"7":{"line":34,"type":"binary-expr","locations":[{"start":{"line":34,"column":15},"end":{"line":34,"column":20}},{"start":{"line":34,"column":24},"end":{"line":34,"column":53}}]},"8":{"line":35,"type":"binary-expr","locations":[{"start":{"line":35,"column":15},"end":{"line":35,"column":20}},{"start":{"line":35,"column":24},"end":{"line":35,"column":107}}]},"9":{"line":38,"type":"if","locations":[{"start":{"line":38,"column":8},"end":{"line":38,"column":8}},{"start":{"line":38,"column":8},"end":{"line":38,"column":8}}]},"10":{"line":38,"type":"binary-expr","locations":[{"start":{"line":38,"column":12},"end":{"line":38,"column":17}},{"start":{"line":38,"column":21},"end":{"line":38,"column":30}},{"start":{"line":38,"column":34},"end":{"line":38,"column":61}}]},"11":{"line":39,"type":"binary-expr","locations":[{"start":{"line":39,"column":19},"end":{"line":39,"column":24}},{"start":{"line":39,"column":28},"end":{"line":39,"column":102}}]},"12":{"line":51,"type":"if","locations":[{"start":{"line":51,"column":12},"end":{"line":51,"column":12}},{"start":{"line":51,"column":12},"end":{"line":51,"column":12}}]},"13":{"line":52,"type":"binary-expr","locations":[{"start":{"line":52,"column":23},"end":{"line":52,"column":28}},{"start":{"line":52,"column":32},"end":{"line":52,"column":77}}]},"14":{"line":56,"type":"if","locations":[{"start":{"line":56,"column":16},"end":{"line":56,"column":16}},{"start":{"line":56,"column":16},"end":{"line":56,"column":16}}]},"15":{"line":57,"type":"binary-expr","locations":[{"start":{"line":57,"column":27},"end":{"line":57,"column":32}},{"start":{"line":57,"column":36},"end":{"line":57,"column":112}}]},"16":{"line":61,"type":"if","locations":[{"start":{"line":61,"column":20},"end":{"line":61,"column":20}},{"start":{"line":61,"column":20},"end":{"line":61,"column":20}}]},"17":{"line":62,"type":"binary-expr","locations":[{"start":{"line":62,"column":31},"end":{"line":62,"column":36}},{"start":{"line":62,"column":40},"end":{"line":62,"column":85}}]}}}} \ No newline at end of file diff --git a/coverage/lcov-report/VideoStoreAPI/app.js.html b/coverage/lcov-report/VideoStoreAPI/app.js.html new file mode 100644 index 000000000..2bb8795fb --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/app.js.html @@ -0,0 +1,293 @@ + + + + Code coverage report for VideoStoreAPI/app.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/ app.js +

+
+
+ 78.95% + Statements + 30/38 +
+
+ 16.67% + Branches + 1/6 +
+
+ 0% + Functions + 0/3 +
+
+ 78.95% + Lines + 30/38 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 + + + + + +  + +  + +  +  + +  + + +  +  + + +  +  +  + + + + + +  +  + + +  + + +  + + +  + + +  +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  + + 
var express = require('express');
+var path = require('path');
+var favicon = require('serve-favicon');
+var logger = require('morgan');
+var cookieParser = require('cookie-parser');
+var bodyParser = require('body-parser');
+ 
+var massive = require("massive")
+ 
+var app = module.exports = express();
+ 
+// database setup
+var connectionString = "postgres://localhost/videostore_api_" + app.get('env');
+ 
+var db = massive.connectSync({connectionString: connectionString});
+app.set('db', db);
+ 
+// view engine setup
+app.set('views', path.join(__dirname, 'views'));
+app.set('view engine', 'ejs');
+ 
+// uncomment after placing your favicon in /public
+//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
+app.use(logger('dev'));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({ extended: false }));
+app.use(cookieParser());
+app.use(express.static(path.join(__dirname, 'public')));
+ 
+//routes
+var indexRoutes = require('./routes/index');
+app.use('/', indexRoutes);
+ 
+var customerRoutes = require('./routes/customers');
+app.use('/customers', customerRoutes);
+ 
+var movieRoutes = require('./routes/movies');
+app.use('/movies', movieRoutes);
+ 
+var rentalRoutes = require('./routes/rentals');
+app.use('/rentals', rentalRoutes);
+ 
+ 
+// catch 404 and forward to error handler
+app.use(function(req, res, next) {
+  var err = new Error('Not Found');
+  err.status = 404;
+  next(err);
+});
+ 
+// error handlers
+ 
+// development error handler
+// will print stacktrace
+Iif (app.get('env') === 'development') {
+  app.use(function(err, req, res, next) {
+    res.status(err.status || 500);
+    res.render('error', {
+      message: err.message,
+      error: err
+    });
+  });
+}
+ 
+// production error handler
+// no stacktraces leaked to user
+app.use(function(err, req, res, next) {
+  res.status(err.status || 500);
+  res.render('error', {
+    message: err.message,
+    error: {}
+  });
+});
+ 
+ 
+module.exports = app;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/customers.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/customers.js.html new file mode 100644 index 000000000..08726ce4f --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/customers.js.html @@ -0,0 +1,197 @@ + + + + Code coverage report for VideoStoreAPI/controllers/customers.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ customers.js +

+
+
+ 13.04% + Statements + 3/23 +
+
+ 0% + Branches + 0/6 +
+
+ 0% + Functions + 0/7 +
+
+ 13.04% + Lines + 3/23 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Customer = require("../models/customer");
+ 
+var CustomersController = {
+  index: function(req, res, next) {
+    Customer.all(function(error, customers) {
+      if(error) {
+        var err = new Error("Error retrieving customer list:\n" + error.message);
+        err.status = 500;
+        next(err);
+      } else {
+        res.json(customers);
+      }
+    });
+  },
+  current: function(req, res, next) {
+      Customer.find(req.params.id, function(error, customer) {
+        if(error) {
+          var err = new Error("No such customer");
+          err.status = 404;
+          next(err);
+        } else {
+          customer.getCurrent(function(error, current) {
+            res.render(current);
+          });
+        }
+      });
+    },
+  sort: function(req, res, next) {
+    var options = {order: req.params.search, limit: req.query.n, offset: req.query.p}
+    Customer.sort(options, function(error, customers) {
+      if(error) {
+        var err = new Error("Error retrieving customer list:\n" + error.message);
+        err.status = 500;
+        next(err);
+      } else {
+        res.json(customers);
+      }
+    });
+  },
+ 
+};
+ 
+ 
+module.exports = CustomersController;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/index.html b/coverage/lcov-report/VideoStoreAPI/controllers/index.html new file mode 100644 index 000000000..9d676fbbc --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/index.html @@ -0,0 +1,132 @@ + + + + Code coverage report for VideoStoreAPI/controllers/ + + + + + + + +
+
+

+ all files VideoStoreAPI/controllers/ +

+
+
+ 17.65% + Statements + 12/68 +
+
+ 0% + Branches + 0/16 +
+
+ 0% + Functions + 0/20 +
+
+ 17.65% + Lines + 12/68 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customers.js
13.04%3/230%0/60%0/713.04%3/23
index.js
50%3/6100%0/00%0/350%3/6
movies.js
14.29%3/210%0/60%0/614.29%3/21
rentals.js
16.67%3/180%0/40%0/416.67%3/18
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/index.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/index.js.html new file mode 100644 index 000000000..2055098bf --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/index.js.html @@ -0,0 +1,131 @@ + + + + Code coverage report for VideoStoreAPI/controllers/index.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ index.js +

+
+
+ 50% + Statements + 3/6 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/3 +
+
+ 50% + Lines + 3/6 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var docs = require('../docs.json');
+ 
+var IndexController = {
+  locals: {
+    documentation: docs
+  },
+ 
+  index: function(req, res, next) {
+    res.json('It works!!');
+  },
+ 
+  docsHTML: function(req, res, next) {
+    // console.log(string_docs);
+    res.render('docs', IndexController.locals);
+  },
+ 
+  docsJSON: function(req, res, next) {
+    res.json(200, docs);
+  }
+};
+ 
+module.exports = IndexController;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/movies.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/movies.js.html new file mode 100644 index 000000000..b692a9dbb --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/movies.js.html @@ -0,0 +1,206 @@ + + + + Code coverage report for VideoStoreAPI/controllers/movies.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ movies.js +

+
+
+ 14.29% + Statements + 3/21 +
+
+ 0% + Branches + 0/6 +
+
+ 0% + Functions + 0/6 +
+
+ 14.29% + Lines + 3/21 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Movie = require("../models/movie.js");
+ 
+ 
+var MoviesController = {
+  index: function(req, res, next) {
+    Movie.all(function (error, result) {
+      if (error) {
+        var err = new Error("Error retrieving movies:\n" + error.message);
+        err.status = 500;
+        next(err);
+      } else {
+        res.json(result);
+      }
+    });
+ 
+  },
+ 
+  sort: function(req, res, next) {
+    Movie.sort(req.params.sort_param, req.query.n, req.query.p, function (error, result) {
+      if (error) {
+        var err = new Error("Error retrieving movies:\n" + error.message);
+        err.status = 500;
+        next(err);
+      } else {
+        res.json(result);
+      }
+    });
+  },
+ 
+  current: function(req, res, next) {
+    Movie.current(req.params.title, function (error, result) {
+      if (error) {
+        var err = new Error("Error retrieving movies:\n" + error.message);
+        err.status = 500;
+        next(err);
+      } else {
+        // if (result.length === 0) {
+        //   res.status(204); //not working for some reason, fix later
+        // }
+        res.json(result);
+      }
+    });
+  }
+ 
+};
+ 
+module.exports = MoviesController;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/rentals.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/rentals.js.html new file mode 100644 index 000000000..0fa8b8c37 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/rentals.js.html @@ -0,0 +1,164 @@ + + + + Code coverage report for VideoStoreAPI/controllers/rentals.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ rentals.js +

+
+
+ 16.67% + Statements + 3/18 +
+
+ 0% + Branches + 0/4 +
+
+ 0% + Functions + 0/4 +
+
+ 16.67% + Lines + 3/18 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Rental = require("../models/rental.js");
+ 
+var RentalsController = {
+  show: function(req, res, next) {
+    Rental.findTitle(req.params.title, function(error, movie) {
+      if(error) {
+        var err = new Error("No such movie title");
+        err.status = 404;
+        next(err);
+      } else {
+          delete movie.id;
+          res.json(movie);
+        };
+    });
+  },
+ 
+  checkOut: function(req, res, next) {
+    var customer_id = req.body.customer_id;
+    var title = req.params.title;
+    Rental.createCheckOut(customer_id, title, function(error, rental) {
+      if(error) {
+        var err = new Error("Rental checkout failed");
+        err.status = 404;
+        next(err);
+      } else {
+        res.json(rental);
+      }
+    });
+  }
+};
+ 
+ 
+module.exports = RentalsController;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/index.html b/coverage/lcov-report/VideoStoreAPI/index.html new file mode 100644 index 000000000..19869dd1b --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/index.html @@ -0,0 +1,93 @@ + + + + Code coverage report for VideoStoreAPI/ + + + + + + + +
+
+

+ all files VideoStoreAPI/ +

+
+
+ 78.95% + Statements + 30/38 +
+
+ 16.67% + Branches + 1/6 +
+
+ 0% + Functions + 0/3 +
+
+ 78.95% + Lines + 30/38 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
app.js
78.95%30/3816.67%1/60%0/378.95%30/38
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/customer.js.html b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html new file mode 100644 index 000000000..32a004c57 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html @@ -0,0 +1,269 @@ + + + + Code coverage report for VideoStoreAPI/models/customer.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ customer.js +

+
+
+ 21.05% + Statements + 8/38 +
+
+ 0% + Branches + 0/20 +
+
+ 0% + Functions + 0/11 +
+
+ 21.05% + Lines + 8/38 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + + 
var app = require("../app");
+var db = app.get("db");
+ 
+// Constructor function
+var Customer = function(customerInfo) {
+  this.id = customerInfo.id;
+  this.name = customerInfo.name;
+  this.address = customerInfo.address;
+  this.city = customerInfo.city;
+  this.state = customerInfo.state;
+  this.postal_code = customerInfo.postal_code;
+  this.account_credit = customerInfo.account_credit;
+  this.phone = customerInfo.phone;
+  this.registered_at = customerInfo.registered_at;
+  this.created_at = customerInfo.created_at;
+  this.updated_at = customerInfo.updated_at;
+};
+ 
+// Instance functions
+ 
+Customer.prototype.getCurrent = function(user_id, callback) {
+  db.customers.find({id: user_id}, {}, function(error, customers) {
+    if(error) {
+      callback(error, undefined);
+    } else {
+      // var rentals = rentals where cutomer id = user_id and status = "checkout"
+      callback(null, result.balance);
+    }
+  });
+ 
+  return this;
+};
+ 
+Customer.all = function(callback) {
+  db.customers.find(function(error, customers) {
+    if(error || !customers) {
+      callback(error || new Error("Could not retrieve customers"), undefined);
+    } else {
+      callback(null, customers.map(function(customer) {
+        return new Customer(customer);
+      }));
+    }
+  });
+};
+ 
+Customer.find = function(id, callback) {
+  db.customers.findOne({id: id}, function(error, customer) {
+    if(error || !customer) {
+      callback(error || new Error("Customer not found"), undefined);
+    } else {
+      callback(null, new Customer(customer));
+    }
+  });
+};
+ 
+Customer.sort = function(options,callback) {
+  db.customers.find({}, options, function(error, customers) {
+    if(error || !customers) {
+      callback(error || new Error("Could not retrieve customers"), undefined);
+    } else {
+      callback(null, customers.map(function(customer) {
+        return new Customer(customer);
+      }));
+    }
+  });
+};
+ 
+module.exports = Customer;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/index.html b/coverage/lcov-report/VideoStoreAPI/models/index.html new file mode 100644 index 000000000..b063fa902 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/index.html @@ -0,0 +1,119 @@ + + + + Code coverage report for VideoStoreAPI/models/ + + + + + + + +
+
+

+ all files VideoStoreAPI/models/ +

+
+
+ 31.93% + Statements + 38/119 +
+
+ 4.71% + Branches + 4/85 +
+
+ 15.15% + Functions + 5/33 +
+
+ 31.62% + Lines + 37/117 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customer.js
21.05%8/380%0/200%0/1121.05%8/38
movie.js
47.62%20/4213.33%4/3038.46%5/1347.5%19/40
rental.js
25.64%10/390%0/350%0/925.64%10/39
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/movie.js.html b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html new file mode 100644 index 000000000..d4efaa613 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html @@ -0,0 +1,383 @@ + + + + Code coverage report for VideoStoreAPI/models/movie.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ movie.js +

+
+
+ 47.62% + Statements + 20/42 +
+
+ 13.33% + Branches + 4/30 +
+
+ 38.46% + Functions + 5/13 +
+
+ 47.5% + Lines + 19/40 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 + +  +  + +100× +100× +100× +100× +100× +100× +  +  +  +  + +  +  +  + +  + +  +  +  + +100× +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + +  +  +  +  + + 
var app = require("../app");
+var db = app.get("db");
+ 
+// Constructor function
+var Movie = function(movieInfo) {
+  this.id = movieInfo.id;
+  this.title = movieInfo.title;
+  this.available_inventory = movieInfo.available_inventory;
+  this.inventory = movieInfo.inventory;
+  this.overview = movieInfo.overview;
+  this.release_date = movieInfo.release_date;
+};
+ 
+ 
+// Instance functions
+Movie.all = function (callback) {
+  // this whole thing immediately gets thrown on the event loop and Movie.all finishes and goes to whatever's next. But .run is not finished yet; it still has to go through the event loop and get executed.
+ 
+  // the callback (second parameter below) is how you deal with the data returned by whatever happened in the first parameter.
+  db.run("SELECT * FROM movies;", function(error, movies) { //the error and result are basically coming from .run()
+    // after_run(error, result);
+    Iif(error || !movies) {
+      //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback.
+      callback(error, undefined);
+    } else {
+      callback(null, movies.map(function(movie) {
+        return new Movie(movie);
+      }));
+    }
+  });
+};
+ 
+// Movie.all(function (error, result){
+  // I can also just put callback(error, result); in the callback for db.run above instead of an if-else statement if I want access to both the error and the result in this function
+ 
+  //but, if I want to modify what the error or result is, I use the if/else in the db.run callback above
+ 
+  // make sure to deal with both errors and results
+ 
+  // return result;
+  // but make it into a hash so we can use it to initialize
+// })
+ 
+Movie.sort = function (field, n, p, callback) {
+  var sort_options = {
+    order: field,
+    limit: n,
+    offset: p
+  };
+  db.movies.find({}, sort_options, function(error, movies) {
+    if (error || !movies) {
+      //in this case error is always true because we're inside the if-statement for error being truthy. so we're passing "true" to the callback.
+      callback(error, undefined);
+    } else {
+      callback(null, movies.map(function(movie) {
+        return new Movie(movie);
+      }));
+    }
+  });
+};
+ 
+Movie.current = function (title, callback) {
+ 
+  db.movies.findOne({title: title}, function(error, movie) {
+    if (error || !movie ) {
+      callback(error || new Error("No movie with that title"), undefined);
+    } else {
+      db.rentals.find({ movie_id: movie.id }, function(error, rentals) {
+        if (error || !rentals) {
+          // console.log(error.message)
+          callback(error || new Error("Movie not currently being rented"), undefined);
+        } else {
+          console.log(rentals);
+          // for each rental, map an array of customer ids
+          var ids_of_customers_renting_movie = rentals.map(function (rental) { return rental.customer_id;})
+ 
+          // handles situations when no rentals exist
+          if (ids_of_customers_renting_movie.length === 0) {
+            callback(null, []);
+          }
+ 
+          // find the customers that have those ids
+          // for (var id of ids_of_customers_renting_movie) {
+          db.customers.find({ id: ids_of_customers_renting_movie }, function(error, customers) {
+            if ( error || !customers ) {
+              callback(error || new Error("No customer matching id"), undefined);
+            } else {
+              callback(null, customers);
+            }
+          });
+ 
+        }
+      });
+    }
+  });
+ 
+ 
+};
+ 
+Eif (app.get('env') === 'test') {
+  Movie.end = function () { db.end() }
+}
+ 
+ 
+ 
+module.exports = Movie;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/rental.js.html b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html new file mode 100644 index 000000000..232b7c55a --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html @@ -0,0 +1,308 @@ + + + + Code coverage report for VideoStoreAPI/models/rental.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ rental.js +

+
+
+ 25.64% + Statements + 10/39 +
+
+ 0% + Branches + 0/35 +
+
+ 0% + Functions + 0/9 +
+
+ 25.64% + Lines + 10/39 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 + + + +  + + +  +  +  +  + +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var app = require("../app");
+var Movie = require("./movie.js");
+var Customer = require("./customer.js");
+var db = app.get("db");
+ 
+var rental_days = 5; // due date is in 5 days
+var rentalFee = 2
+ 
+ 
+ 
+// Constructor function
+var Rental = function(rentalInfo) {
+  this.id = rentalInfo.id;
+  this.movie_id = rentalInfo.movie_id;
+  this.customer_id = rentalInfo.customer_id;
+  this.status = rentalInfo.status; //"returned" and "checkedOut"
+};
+ 
+// show title --> from movies --> overview, release_date, available inventory
+Rental.findTitle = function(movie_title, callback) {
+  db.movies.findOne({title: movie_title}, function(error, movie) {
+    if(error || !movie) {
+      callback(error || new Error("Movie with this title not found"), undefined);
+    } else {
+      callback(null, new Movie(movie));
+    }
+  });
+};
+ 
+Rental.createCheckOut = function(customer_id, title, callback) {
+  Rental.findTitle(title, function(error, movie) {
+    if(error || !movie) {
+      callback(error);
+    } else if (error || movie.available_inventory < 1) {
+      callback(error || new Error("Availability issue: All movies of this title are currently checked out"), undefined)
+    } else {
+      Customer.find(customer_id, function(error, customer) {
+        if (error || !customer || customer.account_credit < 2) {
+          callback(error || new Error("Insufficient Funds: Account Credit balance is less than $2.00"));
+        } else {
+          var rentalInfo = {
+            movie_id: movie.id,
+            customer_id: customer_id,
+            created_at: new Date(),
+            updated_at: new Date(),
+            status: "checked-out",
+            return_date: new Date(new Date().getTime()+(5*24*60*60*1000))
+          };
+ 
+          db.rentals.save(rentalInfo, function(error, rental) {
+            if (error) {
+              callback(error || new Error("Rental was not saved to database"))
+            } else {
+              var new_balance = customer.account_credit - rentalFee
+              db.customers.save({id: customer.id, account_credit: new_balance}, function(error,updated){
+                if (error){
+                  callback(error || new Error("Update Not Successful: Unable to update customer account credit"))
+                } else {
+                  var new_inventory = movie.available_inventory - 1;
+                  db.movies.save({id: movie.id, available_inventory: new_inventory}, function(error, movie) {
+                    if (error) {
+                      callback(error || new Error("Unable to reduce inventory count"));
+                    } else {
+                      callback(null, {rentalInfo: new Rental(rentalInfo), customerInfo: new Customer(customer)});
+                    }
+                  })
+                }
+              })
+ 
+            }
+          });
+ 
+        }
+      })
+ 
+    }
+  })
+ 
+};
+ 
+module.exports = Rental;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/customers.js.html b/coverage/lcov-report/VideoStoreAPI/routes/customers.js.html new file mode 100644 index 000000000..558ef2653 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/customers.js.html @@ -0,0 +1,101 @@ + + + + Code coverage report for VideoStoreAPI/routes/customers.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ customers.js +

+
+
+ 100% + Statements + 7/7 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 0/0 +
+
+ 100% + Lines + 7/7 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 + + +  +  + +  + +  + +  + + 
var express = require('express');
+var router = express.Router();
+var CustomerController = require('../controllers/customers');
+ 
+/* GET home page. */
+router.get('/', CustomerController.index);
+ 
+router.get('/sort/:search?', CustomerController.sort);
+ 
+router.get('/:customer_id/current', CustomerController.current);
+ 
+module.exports = router;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.html b/coverage/lcov-report/VideoStoreAPI/routes/index.html new file mode 100644 index 000000000..7c32d09af --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.html @@ -0,0 +1,132 @@ + + + + Code coverage report for VideoStoreAPI/routes/ + + + + + + + +
+
+

+ all files VideoStoreAPI/routes/ +

+
+
+ 96.55% + Statements + 28/29 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/1 +
+
+ 96.55% + Lines + 28/29 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customers.js
100%7/7100%0/0100%0/0100%7/7
index.js
88.89%8/9100%0/00%0/188.89%8/9
movies.js
100%7/7100%0/0100%0/0100%7/7
rentals.js
100%6/6100%0/0100%0/0100%6/6
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.js.html b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html new file mode 100644 index 000000000..39ff1fcc1 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html @@ -0,0 +1,113 @@ + + + + Code coverage report for VideoStoreAPI/routes/index.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ index.js +

+
+
+ 88.89% + Statements + 8/9 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/1 +
+
+ 88.89% + Lines + 8/9 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 + + +  + +  + +  + +  +  + +  +  +  + + 
var express = require('express');
+var router = express.Router();
+var IndexController = require('../controllers/index.js');
+ 
+router.get('/', IndexController.index);
+ 
+router.get('/api/docs', IndexController.docsHTML);
+ 
+router.get('/api/docs.json', IndexController.docsJSON);
+ 
+/**** just a test ****/
+router.get('/zomg', function(req, res, next) {
+  res.status(200).json({whatevs: 'whatevs!!!'});
+});
+ 
+module.exports = router;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/movies.js.html b/coverage/lcov-report/VideoStoreAPI/routes/movies.js.html new file mode 100644 index 000000000..1769a2ce3 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/movies.js.html @@ -0,0 +1,101 @@ + + + + Code coverage report for VideoStoreAPI/routes/movies.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ movies.js +

+
+
+ 100% + Statements + 7/7 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 0/0 +
+
+ 100% + Lines + 7/7 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 + + +  +  + +  + +  + +  + + 
var express = require('express');
+var router = express.Router();
+var MoviesController = require('../controllers/movies');
+ 
+/* GET home page. */
+router.get('/', MoviesController.index);
+ 
+router.get('/sort/:sort_param', MoviesController.sort);
+ 
+router.get('/:title/current', MoviesController.current);
+ 
+module.exports = router;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/rentals.js.html b/coverage/lcov-report/VideoStoreAPI/routes/rentals.js.html new file mode 100644 index 000000000..f2c5e0334 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/rentals.js.html @@ -0,0 +1,95 @@ + + + + Code coverage report for VideoStoreAPI/routes/rentals.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ rentals.js +

+
+
+ 100% + Statements + 6/6 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 0/0 +
+
+ 100% + Lines + 6/6 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 + + +  +  + +  + +  + + 
var express = require('express');
+var router = express.Router();
+var RentalsController = require('../controllers/rentals');
+ 
+/* GET home page. */
+router.get('/:title', RentalsController.show);
+ 
+router.post('/:title/check-out', RentalsController.checkOut)
+ 
+module.exports = router;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/base.css b/coverage/lcov-report/base.css new file mode 100644 index 000000000..29737bcb0 --- /dev/null +++ b/coverage/lcov-report/base.css @@ -0,0 +1,213 @@ +body, html { + margin:0; padding: 0; + height: 100%; +} +body { + font-family: Helvetica Neue, Helvetica, Arial; + font-size: 14px; + color:#333; +} +.small { font-size: 12px; } +*, *:after, *:before { + -webkit-box-sizing:border-box; + -moz-box-sizing:border-box; + box-sizing:border-box; + } +h1 { font-size: 20px; margin: 0;} +h2 { font-size: 14px; } +pre { + font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; + margin: 0; + padding: 0; + -moz-tab-size: 2; + -o-tab-size: 2; + tab-size: 2; +} +a { color:#0074D9; text-decoration:none; } +a:hover { text-decoration:underline; } +.strong { font-weight: bold; } +.space-top1 { padding: 10px 0 0 0; } +.pad2y { padding: 20px 0; } +.pad1y { padding: 10px 0; } +.pad2x { padding: 0 20px; } +.pad2 { padding: 20px; } +.pad1 { padding: 10px; } +.space-left2 { padding-left:55px; } +.space-right2 { padding-right:20px; } +.center { text-align:center; } +.clearfix { display:block; } +.clearfix:after { + content:''; + display:block; + height:0; + clear:both; + visibility:hidden; + } +.fl { float: left; } +@media only screen and (max-width:640px) { + .col3 { width:100%; max-width:100%; } + .hide-mobile { display:none!important; } +} + +.quiet { + color: #7f7f7f; + color: rgba(0,0,0,0.5); +} +.quiet a { opacity: 0.7; } + +.fraction { + font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; + font-size: 10px; + color: #555; + background: #E8E8E8; + padding: 4px 5px; + border-radius: 3px; + vertical-align: middle; +} + +div.path a:link, div.path a:visited { color: #333; } +table.coverage { + border-collapse: collapse; + margin: 10px 0 0 0; + padding: 0; +} + +table.coverage td { + margin: 0; + padding: 0; + vertical-align: top; +} +table.coverage td.line-count { + text-align: right; + padding: 0 5px 0 20px; +} +table.coverage td.line-coverage { + text-align: right; + padding-right: 10px; + min-width:20px; +} + +table.coverage td span.cline-any { + display: inline-block; + padding: 0 5px; + width: 100%; +} +.missing-if-branch { + display: inline-block; + margin-right: 5px; + border-radius: 3px; + position: relative; + padding: 0 4px; + background: #333; + color: yellow; +} + +.skip-if-branch { + display: none; + margin-right: 10px; + position: relative; + padding: 0 4px; + background: #ccc; + color: white; +} +.missing-if-branch .typ, .skip-if-branch .typ { + color: inherit !important; +} +.coverage-summary { + border-collapse: collapse; + width: 100%; +} +.coverage-summary tr { border-bottom: 1px solid #bbb; } +.keyline-all { border: 1px solid #ddd; } +.coverage-summary td, .coverage-summary th { padding: 10px; } +.coverage-summary tbody { border: 1px solid #bbb; } +.coverage-summary td { border-right: 1px solid #bbb; } +.coverage-summary td:last-child { border-right: none; } +.coverage-summary th { + text-align: left; + font-weight: normal; + white-space: nowrap; +} +.coverage-summary th.file { border-right: none !important; } +.coverage-summary th.pct { } +.coverage-summary th.pic, +.coverage-summary th.abs, +.coverage-summary td.pct, +.coverage-summary td.abs { text-align: right; } +.coverage-summary td.file { white-space: nowrap; } +.coverage-summary td.pic { min-width: 120px !important; } +.coverage-summary tfoot td { } + +.coverage-summary .sorter { + height: 10px; + width: 7px; + display: inline-block; + margin-left: 0.5em; + background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; +} +.coverage-summary .sorted .sorter { + background-position: 0 -20px; +} +.coverage-summary .sorted-desc .sorter { + background-position: 0 -10px; +} +.status-line { height: 10px; } +/* dark red */ +.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } +.low .chart { border:1px solid #C21F39 } +/* medium red */ +.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } +/* light red */ +.low, .cline-no { background:#FCE1E5 } +/* light green */ +.high, .cline-yes { background:rgb(230,245,208) } +/* medium green */ +.cstat-yes { background:rgb(161,215,106) } +/* dark green */ +.status-line.high, .high .cover-fill { background:rgb(77,146,33) } +.high .chart { border:1px solid rgb(77,146,33) } +/* dark yellow (gold) */ +.medium .chart { border:1px solid #f9cd0b; } +.status-line.medium, .medium .cover-fill { background: #f9cd0b; } +/* light yellow */ +.medium { background: #fff4c2; } +/* light gray */ +span.cline-neutral { background: #eaeaea; } + +.cbranch-no { background: yellow !important; color: #111; } + +.cstat-skip { background: #ddd; color: #111; } +.fstat-skip { background: #ddd; color: #111 !important; } +.cbranch-skip { background: #ddd !important; color: #111; } + + +.cover-fill, .cover-empty { + display:inline-block; + height: 12px; +} +.chart { + line-height: 0; +} +.cover-empty { + background: white; +} +.cover-full { + border-right: none !important; +} +pre.prettyprint { + border: none !important; + padding: 0 !important; + margin: 0 !important; +} +.com { color: #999 !important; } +.ignore-none { color: #999; font-weight: normal; } + +.wrapper { + min-height: 100%; + height: auto !important; + height: 100%; + margin: 0 auto -48px; +} +.footer, .push { + height: 48px; +} diff --git a/coverage/lcov-report/index.html b/coverage/lcov-report/index.html new file mode 100644 index 000000000..281ab83b2 --- /dev/null +++ b/coverage/lcov-report/index.html @@ -0,0 +1,132 @@ + + + + Code coverage report for All files + + + + + + + +
+
+

+ / +

+
+
+ 42.52% + Statements + 108/254 +
+
+ 4.67% + Branches + 5/107 +
+
+ 8.77% + Functions + 5/57 +
+
+ 42.46% + Lines + 107/252 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
VideoStoreAPI/
78.95%30/3816.67%1/60%0/378.95%30/38
VideoStoreAPI/controllers/
17.65%12/680%0/160%0/2017.65%12/68
VideoStoreAPI/models/
31.93%38/1194.71%4/8515.15%5/3331.62%37/117
VideoStoreAPI/routes/
96.55%28/29100%0/00%0/196.55%28/29
+
+
+ + + + + + + diff --git a/coverage/lcov-report/prettify.css b/coverage/lcov-report/prettify.css new file mode 100644 index 000000000..b317a7cda --- /dev/null +++ b/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/coverage/lcov-report/prettify.js b/coverage/lcov-report/prettify.js new file mode 100644 index 000000000..ef51e0386 --- /dev/null +++ b/coverage/lcov-report/prettify.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/coverage/lcov-report/sort-arrow-sprite.png b/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function (a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function (a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function () { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i =0 ; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function () { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(cols); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); diff --git a/coverage/lcov.info b/coverage/lcov.info new file mode 100644 index 000000000..6735c4c3b --- /dev/null +++ b/coverage/lcov.info @@ -0,0 +1,581 @@ +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/models/movie.js +FN:5,(anonymous_1) +FN:16,(anonymous_2) +FN:20,(anonymous_3) +FN:26,(anonymous_4) +FN:44,(anonymous_5) +FN:50,(anonymous_6) +FN:55,(anonymous_7) +FN:62,(anonymous_8) +FN:64,(anonymous_9) +FN:68,(anonymous_10) +FN:75,(anonymous_11) +FN:84,(anonymous_12) +FN:101,(anonymous_13) +FNF:13 +FNH:5 +FNDA:100,(anonymous_1) +FNDA:1,(anonymous_2) +FNDA:1,(anonymous_3) +FNDA:100,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +FNDA:0,(anonymous_12) +FNDA:1,(anonymous_13) +DA:1,1 +DA:2,1 +DA:5,1 +DA:6,100 +DA:7,100 +DA:8,100 +DA:9,100 +DA:10,100 +DA:11,100 +DA:16,1 +DA:20,1 +DA:22,1 +DA:24,0 +DA:26,1 +DA:27,100 +DA:44,1 +DA:45,0 +DA:50,0 +DA:51,0 +DA:53,0 +DA:55,0 +DA:56,0 +DA:62,1 +DA:64,0 +DA:65,0 +DA:66,0 +DA:68,0 +DA:69,0 +DA:71,0 +DA:73,0 +DA:75,0 +DA:78,0 +DA:79,0 +DA:84,0 +DA:85,0 +DA:86,0 +DA:88,0 +DA:100,1 +DA:101,1 +DA:106,1 +LF:40 +LH:19 +BRDA:22,1,0,0 +BRDA:22,1,1,1 +BRDA:22,2,0,1 +BRDA:22,2,1,1 +BRDA:51,3,0,0 +BRDA:51,3,1,0 +BRDA:51,4,0,0 +BRDA:51,4,1,0 +BRDA:65,5,0,0 +BRDA:65,5,1,0 +BRDA:65,6,0,0 +BRDA:65,6,1,0 +BRDA:66,7,0,0 +BRDA:66,7,1,0 +BRDA:69,8,0,0 +BRDA:69,8,1,0 +BRDA:69,9,0,0 +BRDA:69,9,1,0 +BRDA:71,10,0,0 +BRDA:71,10,1,0 +BRDA:78,11,0,0 +BRDA:78,11,1,0 +BRDA:85,12,0,0 +BRDA:85,12,1,0 +BRDA:85,13,0,0 +BRDA:85,13,1,0 +BRDA:86,14,0,0 +BRDA:86,14,1,0 +BRDA:100,15,0,1 +BRDA:100,15,1,0 +BRF:30 +BRH:4 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/app.js +FN:45,(anonymous_1) +FN:56,(anonymous_2) +FN:67,(anonymous_3) +FNF:3 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:8,1 +DA:10,1 +DA:13,1 +DA:15,1 +DA:16,1 +DA:19,1 +DA:20,1 +DA:24,1 +DA:25,1 +DA:26,1 +DA:27,1 +DA:28,1 +DA:31,1 +DA:32,1 +DA:34,1 +DA:35,1 +DA:37,1 +DA:38,1 +DA:40,1 +DA:41,1 +DA:45,1 +DA:46,0 +DA:47,0 +DA:48,0 +DA:55,1 +DA:56,0 +DA:57,0 +DA:58,0 +DA:67,1 +DA:68,0 +DA:69,0 +DA:76,1 +LF:38 +LH:30 +BRDA:55,1,0,0 +BRDA:55,1,1,1 +BRDA:57,2,0,0 +BRDA:57,2,1,0 +BRDA:68,3,0,0 +BRDA:68,3,1,0 +BRF:6 +BRH:1 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/index.js +FN:12,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:7,1 +DA:9,1 +DA:12,1 +DA:13,0 +DA:16,1 +LF:9 +LH:8 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/index.js +FN:8,(anonymous_1) +FN:12,(anonymous_2) +FN:17,(anonymous_3) +FNF:3 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +DA:1,1 +DA:3,1 +DA:9,0 +DA:14,0 +DA:18,0 +DA:22,1 +LF:6 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/customers.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:3,1 +DA:6,1 +DA:8,1 +DA:10,1 +DA:12,1 +LF:7 +LH:7 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/customers.js +FN:4,(anonymous_1) +FN:5,(anonymous_2) +FN:15,(anonymous_3) +FN:16,(anonymous_4) +FN:22,(anonymous_5) +FN:28,(anonymous_6) +FN:30,(anonymous_7) +FNF:7 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +DA:1,1 +DA:3,1 +DA:5,0 +DA:6,0 +DA:7,0 +DA:8,0 +DA:9,0 +DA:11,0 +DA:16,0 +DA:17,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:22,0 +DA:23,0 +DA:29,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:36,0 +DA:44,1 +LF:23 +LH:3 +BRDA:6,1,0,0 +BRDA:6,1,1,0 +BRDA:17,2,0,0 +BRDA:17,2,1,0 +BRDA:31,3,0,0 +BRDA:31,3,1,0 +BRF:6 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/models/customer.js +FN:5,(anonymous_1) +FN:21,(anonymous_2) +FN:22,(anonymous_3) +FN:34,(anonymous_4) +FN:35,(anonymous_5) +FN:39,(anonymous_6) +FN:46,(anonymous_7) +FN:47,(anonymous_8) +FN:56,(anonymous_9) +FN:57,(anonymous_10) +FN:61,(anonymous_11) +FNF:11 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +DA:1,1 +DA:2,1 +DA:5,1 +DA:6,0 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:21,1 +DA:22,0 +DA:23,0 +DA:24,0 +DA:27,0 +DA:31,0 +DA:34,1 +DA:35,0 +DA:36,0 +DA:37,0 +DA:39,0 +DA:40,0 +DA:46,1 +DA:47,0 +DA:48,0 +DA:49,0 +DA:51,0 +DA:56,1 +DA:57,0 +DA:58,0 +DA:59,0 +DA:61,0 +DA:62,0 +DA:68,1 +LF:38 +LH:8 +BRDA:23,1,0,0 +BRDA:23,1,1,0 +BRDA:36,2,0,0 +BRDA:36,2,1,0 +BRDA:36,3,0,0 +BRDA:36,3,1,0 +BRDA:37,4,0,0 +BRDA:37,4,1,0 +BRDA:48,5,0,0 +BRDA:48,5,1,0 +BRDA:48,6,0,0 +BRDA:48,6,1,0 +BRDA:49,7,0,0 +BRDA:49,7,1,0 +BRDA:58,8,0,0 +BRDA:58,8,1,0 +BRDA:58,9,0,0 +BRDA:58,9,1,0 +BRDA:59,10,0,0 +BRDA:59,10,1,0 +BRF:20 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/movies.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:3,1 +DA:6,1 +DA:8,1 +DA:10,1 +DA:12,1 +LF:7 +LH:7 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/movies.js +FN:5,(anonymous_1) +FN:6,(anonymous_2) +FN:18,(anonymous_3) +FN:19,(anonymous_4) +FN:30,(anonymous_5) +FN:31,(anonymous_6) +FNF:6 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +DA:1,1 +DA:4,1 +DA:6,0 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:12,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:40,0 +DA:47,1 +LF:21 +LH:3 +BRDA:7,1,0,0 +BRDA:7,1,1,0 +BRDA:20,2,0,0 +BRDA:20,2,1,0 +BRDA:32,3,0,0 +BRDA:32,3,1,0 +BRF:6 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/routes/rentals.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:3,1 +DA:6,1 +DA:8,1 +DA:10,1 +LF:6 +LH:6 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/controllers/rentals.js +FN:4,(anonymous_1) +FN:5,(anonymous_2) +FN:17,(anonymous_3) +FN:20,(anonymous_4) +FNF:4 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +DA:1,1 +DA:3,1 +DA:5,0 +DA:6,0 +DA:7,0 +DA:8,0 +DA:9,0 +DA:11,0 +DA:12,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:26,0 +DA:33,1 +LF:18 +LH:3 +BRDA:6,1,0,0 +BRDA:6,1,1,0 +BRDA:21,2,0,0 +BRDA:21,2,1,0 +BRF:4 +BRH:0 +end_of_record +TN: +SF:/Users/valerieconklin/C5/projects/VideoStoreAPI/models/rental.js +FN:12,(anonymous_1) +FN:20,(anonymous_2) +FN:21,(anonymous_3) +FN:30,(anonymous_4) +FN:31,(anonymous_5) +FN:37,(anonymous_6) +FN:50,(anonymous_7) +FN:55,(anonymous_8) +FN:60,(anonymous_9) +FNF:9 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:6,1 +DA:7,1 +DA:12,1 +DA:13,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:20,1 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:30,1 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:41,0 +DA:50,0 +DA:51,0 +DA:52,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:57,0 +DA:59,0 +DA:60,0 +DA:61,0 +DA:62,0 +DA:64,0 +DA:81,1 +LF:39 +LH:10 +BRDA:22,1,0,0 +BRDA:22,1,1,0 +BRDA:22,2,0,0 +BRDA:22,2,1,0 +BRDA:23,3,0,0 +BRDA:23,3,1,0 +BRDA:32,4,0,0 +BRDA:32,4,1,0 +BRDA:32,5,0,0 +BRDA:32,5,1,0 +BRDA:34,6,0,0 +BRDA:34,6,1,0 +BRDA:34,7,0,0 +BRDA:34,7,1,0 +BRDA:35,8,0,0 +BRDA:35,8,1,0 +BRDA:38,9,0,0 +BRDA:38,9,1,0 +BRDA:38,10,0,0 +BRDA:38,10,1,0 +BRDA:38,10,2,0 +BRDA:39,11,0,0 +BRDA:39,11,1,0 +BRDA:51,12,0,0 +BRDA:51,12,1,0 +BRDA:52,13,0,0 +BRDA:52,13,1,0 +BRDA:56,14,0,0 +BRDA:56,14,1,0 +BRDA:57,15,0,0 +BRDA:57,15,1,0 +BRDA:61,16,0,0 +BRDA:61,16,1,0 +BRDA:62,17,0,0 +BRDA:62,17,1,0 +BRF:35 +BRH:0 +end_of_record diff --git a/models/movie.js b/models/movie.js index a7883c28b..3c0ad042c 100644 --- a/models/movie.js +++ b/models/movie.js @@ -97,6 +97,10 @@ Movie.current = function (title, callback) { }; +if (app.get('env') === 'test') { + Movie.end = function () { db.end() } +} + module.exports = Movie; diff --git a/spec/controllers/rentals.spec.js b/spec/controllers/rentals.spec.js index e69de29bb..5c5a2a083 100644 --- a/spec/controllers/rentals.spec.js +++ b/spec/controllers/rentals.spec.js @@ -0,0 +1,16 @@ +var request = require('request'); +var base_url = "http://localhost:3000/" +var route = "rentals/Jaws" + + +describe("Endpoints under /rentals", function() { + it('responds with a 200 status code', function (done) { + request.get(base_url + route, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }); + + + +}); diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index e69de29bb..f426ad6d9 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -0,0 +1,24 @@ +var Movie = require('../../models/movie.js') + +describe('Movie model', function () { + + afterEach(function () { + Movie.end() + }) + + describe('.all', function () { + + it("returns an array", function (done) { + Movie.all(function(error, result) { + expect(error).toBe(null); + expect(result).toBe(Array); + }) + + done() + }) + }) + + + + +})