diff --git a/server/app/routes/user/meal-generator.js b/server/app/routes/user/meal-generator.js index cfa9da80..07079914 100644 --- a/server/app/routes/user/meal-generator.js +++ b/server/app/routes/user/meal-generator.js @@ -8,7 +8,7 @@ module.exports = { //maybe this is a user prefs instance method?? getMeals: function(recipe, userId){ //get list of 10 associated meals given the first recipe - let mealPlan = recipe.mealsWithSimilarIngredients; + let mealPlan = recipe.mealsWithSimilarIngredients || [recipe.id]; //Filter that list by user restrictions return UserPref.findOne({ where: { diff --git a/server/env/testing.js b/server/env/testing.js index 35f3e2ce..ce96e844 100644 --- a/server/env/testing.js +++ b/server/env/testing.js @@ -1,5 +1,5 @@ module.exports = { - DATABASE_URL: 'postgres://localhost:5432/dishd', + DATABASE_URL: 'postgres://localhost:5432/dishdtest', SESSION_SECRET: 'Optimus Prime is my real dad', TWITTER: { consumerKey: 'INSERT_TWITTER_CONSUMER_KEY_HERE', diff --git a/tests/server/models/recipe-tests.js b/tests/server/models/recipe-tests.js index c7889c4c..9860a44a 100644 --- a/tests/server/models/recipe-tests.js +++ b/tests/server/models/recipe-tests.js @@ -5,11 +5,12 @@ var Sequelize = require('sequelize'); var db = require('../../../server/db'); +var User = db.model('user'); var Recipe = db.model('recipe'); var Ingredient = db.model('ingredient'); var Promise = require('bluebird'); -xdescribe('Recipe model', function () { +describe('Recipe model', function () { beforeEach('Sync DB', function () { return db.sync({force: true}); @@ -28,7 +29,7 @@ xdescribe('Recipe model', function () { var recipes = [ {title: "Chocolate Cake", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ @@ -38,7 +39,7 @@ xdescribe('Recipe model', function () { }, {title: "Chocolate Chip Cookies", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ @@ -48,7 +49,7 @@ xdescribe('Recipe model', function () { }, {title: "Chicken Nuggets", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ @@ -92,7 +93,7 @@ xdescribe('Recipe model', function () { var recipes = [ {title: "Chocolate Cake", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ @@ -102,7 +103,7 @@ xdescribe('Recipe model', function () { }, {title: "Chocolate Chip Cookies", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ @@ -112,12 +113,12 @@ xdescribe('Recipe model', function () { }, {title: "Chicken Nuggets", instructions: 'make it!', - image:'img.jpg', + image: 'img.jpg', preparationMinutes: 10, cookingMinutes: 10, extendedIngredients: [ - {name: 'chicken', id: 400}, - {name: 'nuggets', id: 323} + {name: 'chicken', id: 4}, + {name: 'nuggets', id: 5} ] } @@ -166,12 +167,17 @@ xdescribe('Recipe model', function () { }); }); - it('should return an array of recipes with the same ingredients', function () { + it('should return an array of recipe id with the same ingredients', function () { return createRecipe().then(function (rec) { return rec.getMealsWithSimilarIngredients(1) .then(function(result){ expect(result).to.be.an('array'); - expect(result[0].title).to.be.equals('Chocolate Chip Cookies'); + return Recipe.findOne({ + where: {id: result[0]} + }); + }) + .then(function(resultRecipe){ + expect(resultRecipe.title).to.be.equals('Chocolate Chip Cookies'); }); }); }); @@ -180,11 +186,8 @@ xdescribe('Recipe model', function () { describe('randomRecipes', function () { var fakeUser = { - getAllOkayRecipes: function(){ - return new Promise(function(resolve){ - return recipes; - }) - } + email: 'chocolover@choco.com', + password: 'choco' } var recipes = [ @@ -231,11 +234,14 @@ xdescribe('Recipe model', function () { it('should return an array of the correct length', function () { return createRecipes().then(function (rec) { - // return Recipe.randomRecipes(fakeUser, 2) - // .then(function(result){ - // expect(result).to.be.an('array'); - // // expect(result[0].title).to.be.equals('Chocolate Chip Cookies'); - // }) + User.create(fakeUser) + .then(function(user){ + return Recipe.randomRecipes(user.id, 2); + }) + .then(function(result){ + expect(result).to.be.an('array'); + expect(result).to.be.have.length(2); + }) }); }); diff --git a/tests/server/models/user-test.js b/tests/server/models/user-test.js index 10849610..21b38f4c 100644 --- a/tests/server/models/user-test.js +++ b/tests/server/models/user-test.js @@ -7,7 +7,7 @@ var db = require('../../../server/db'); var User = db.model('user'); -xdescribe('User model', function () { +describe('User model', function () { beforeEach('Sync DB', function () { return db.sync({ force: true }); diff --git a/tests/server/routes/meal-test.js b/tests/server/routes/meal-test.js index 74ef1e13..f6d21ef0 100644 --- a/tests/server/routes/meal-test.js +++ b/tests/server/routes/meal-test.js @@ -8,7 +8,7 @@ var Recipe = db.model('recipe'); var supertest = require('supertest'); -xdescribe('Meal Plan Route', function () { +describe('Meal Plan Route', function () { var app, User; @@ -29,15 +29,134 @@ xdescribe('Meal Plan Route', function () { guestAgent = supertest.agent(app); }); - it('should get an array of 10 recipes as a response', function (done) { - guestAgent.get('/api/users/1/meals') + beforeEach('Seed recipes', function(){ + + var recipes = [ + {title: "Chocolate Cake", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'sugar', id: 2} + ] + }, + {title: "Chocolate Chip Cookies", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'flour', id: 3} + ] + }, + {title: "Chicken Nuggets", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chicken', id: 400}, + {name: 'nuggets', id: 323} + ] + }, + {title: "Chocolate Cake2", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'sugar', id: 2} + ] + }, + {title: "Chocolate Chip Cookies2", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'flour', id: 3} + ] + }, + {title: "Chicken Nuggets2", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chicken', id: 400}, + {name: 'nuggets', id: 323} + ] + }, + {title: "Chocolate Cake3", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'sugar', id: 2} + ] + }, + {title: "Chocolate Chip Cookies3", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chocolate', id: 1}, + {name: 'flour', id: 3} + ] + }, + {title: "Chicken Nuggets3", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chicken', id: 400}, + {name: 'nuggets', id: 323} + ] + }, + {title: "Chicken Nuggets4", + instructions: 'make it!', + image: 'img.jpg', + preparationMinutes: 10, + cookingMinutes: 10, + extendedIngredients: [ + {name: 'chicken', id: 400}, + {name: 'nuggets', id: 323} + ] + } + ]; + + let recipePromises = []; + recipes.forEach(function(recipe){ + recipePromises.push(Recipe.create(recipe)); + }); + + return Promise.all(recipePromises); + + + }); + + + // need to make a user. + // need to put recipes in the db for this to work + it('should get an array of 10 recipes as a response if a user has no meal plans', function(done) { + return guestAgent.get('/api/users/1/meals') .expect(200) - .end(function (err, response) { - if (err) return done(err); - expect(response.body).to.be.an('array'); - expect(response.body).to.have.length(10); - done(); - }); + .end(function(err, response) { + if (err) return console.log(err); + // console.log(response.body); + expect(response.body).to.be.an('array'); + expect(response.body).to.have.length(10); + done(); + }); }); }); diff --git a/tests/server/routes/members-only-test.js b/tests/server/routes/members-only-test.js index 009c9dd7..5d6dce63 100644 --- a/tests/server/routes/members-only-test.js +++ b/tests/server/routes/members-only-test.js @@ -7,7 +7,7 @@ var db = require('../../../server/db'); var supertest = require('supertest'); -xdescribe('Members Route', function () { +describe('Members Route', function () { var app, User; diff --git a/tests/server/routes/signup-tests.js b/tests/server/routes/signup-tests.js index 112fb890..88807a6a 100644 --- a/tests/server/routes/signup-tests.js +++ b/tests/server/routes/signup-tests.js @@ -7,7 +7,7 @@ var db = require('../../../server/db'); var supertest = require('supertest'); -xdescribe('Signup Route', function () { +describe('Signup Route', function () { var app, User; diff --git a/tests/server/routes/user-test.js b/tests/server/routes/user-test.js index 240d1de1..d3258d4e 100644 --- a/tests/server/routes/user-test.js +++ b/tests/server/routes/user-test.js @@ -5,7 +5,7 @@ var db = require('../../../server/db'); var supertest = require('supertest'); -xdescribe('User Route', function () { +describe('User Route', function () { var app, User; var fakeUser = {