/
meal-test.js
163 lines (144 loc) · 4.23 KB
/
meal-test.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Instantiate all models
var expect = require('chai').expect;
var Sequelize = require('sequelize');
var db = require('../../../server/db');
var Recipe = db.model('recipe');
var supertest = require('supertest');
describe('Meal Plan Route', function () {
var app, User;
beforeEach('Sync DB', function () {
return db.sync();
});
beforeEach('Create app', function () {
app = require('../../../server/app')(db);
User = db.model('user');
});
describe('get meal plan route', function () {
var guestAgent;
beforeEach('Create guest agent', function () {
guestAgent = supertest.agent(app);
});
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 console.log(err);
// console.log(response.body);
expect(response.body).to.be.an('array');
expect(response.body).to.have.length(10);
done();
});
});
});
});