Skip to content

Commit

Permalink
Tests brought back in. (#102)
Browse files Browse the repository at this point in the history
* Fixed an off by one error in seeding the mealplan

* Changed tests to use a testing database

* Losts of tests up and runnning.
  • Loading branch information
verasveras authored and johannaperez committed Oct 17, 2016
1 parent 9dcc517 commit e919ec2
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 36 deletions.
2 changes: 1 addition & 1 deletion server/app/routes/user/meal-generator.js
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion 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',
Expand Down
48 changes: 27 additions & 21 deletions tests/server/models/recipe-tests.js
Expand Up @@ -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});
Expand All @@ -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: [
Expand All @@ -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: [
Expand All @@ -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: [
Expand Down Expand Up @@ -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: [
Expand All @@ -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: [
Expand All @@ -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}
]
}

Expand Down Expand Up @@ -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');
});
});
});
Expand All @@ -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 = [
Expand Down Expand Up @@ -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);
})
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/server/models/user-test.js
Expand Up @@ -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 });
Expand Down
137 changes: 128 additions & 9 deletions tests/server/routes/meal-test.js
Expand Up @@ -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;

Expand All @@ -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();
});
});

});
Expand Down
2 changes: 1 addition & 1 deletion tests/server/routes/members-only-test.js
Expand Up @@ -7,7 +7,7 @@ var db = require('../../../server/db');

var supertest = require('supertest');

xdescribe('Members Route', function () {
describe('Members Route', function () {

var app, User;

Expand Down
2 changes: 1 addition & 1 deletion tests/server/routes/signup-tests.js
Expand Up @@ -7,7 +7,7 @@ var db = require('../../../server/db');

var supertest = require('supertest');

xdescribe('Signup Route', function () {
describe('Signup Route', function () {

var app, User;

Expand Down
2 changes: 1 addition & 1 deletion tests/server/routes/user-test.js
Expand Up @@ -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 = {
Expand Down

0 comments on commit e919ec2

Please sign in to comment.