-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.test.js
188 lines (181 loc) · 5.15 KB
/
app.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const app = require('./app');
const request = require("supertest");
// Testing the login endpoint
describe("Testing Login", () => {
test("Wrong username should return not found", async () => {
await request(app).post("localhost:5000/api/login")
.send({
username: "wrong",
password: "12398123"
})
.expect((res) => {
res.body.status = 500;
res.body.error = "Username not found."
})
})
test("Wrong password should return not match", async () => {
await request(app).post("localhost:5000/api/login")
.send({
username: "test",
password: "12398123"
})
.expect((res) => {
res.body.status = 500;
res.body.error = "Passwords do not match."
})
})
test("Correct login info returns 200 status", async () => {
await request(app).post("localhost:5000/api/login")
.send({
username: "test",
password: "test"
})
.expect((res) => {
res.body.status = 200
})
})
})
describe("Testing Create Recipe", () => {
test("Adding a recipe to the database", async () => {
await request(app).post("localhost:5000/api/createRecipe")
.send({
name: "Unit Testing Recipe",
desc: "Unit Testing Recipe",
pic: "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png",
country: "Italy",
text: "Unit Testing Recipe",
creator: "625c890a9b12478a46212a3f",
coordinates: [0,0]
})
.expect((res) => {
res.body.status = 200;
res.body.error = ""
})
})
})
describe("Testing Edit Recipe", () => {
test("Editing a recipe", async () => {
await request(app).post("localhost:5000/api/editRecipe")
.send({
name: "Unit Testing Recipe",
desc: "Unit Testing Recipe",
pic: "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png",
text: "Unit Testing Recipe",
recipeID: "6254ff2797bf1f078987ac0e"
})
.expect((res) => {
res.body.status = 200;
res.body.error = ""
})
})
})
describe("Testing User Likes and Favorites", () => {
test("Getting favorites with invalid userID returns error", async () => {
await request(app).post("localhost:5000/api/getFavorites")
.send({
userID: "625c890a9b12478a46212333"
})
.expect((res) => {
res.body.status = 500;
res.body.error = "Invalid UserID"
})
})
test("Getting favorites with valid userID returns 200 status", async () => {
await request(app).post("localhost:5000/api/getFavorites")
.send({
userID: "625c890a9b12478a46212a3f"
})
.expect((res) => {
res.body.status = 200;
})
})
test("Getting likes with invalid userID returns error", async () => {
await request(app).post("localhost:5000/api/getLikes")
.send({
userID: "625c890a9b12478a46212333"
})
.expect((res) => {
res.body.status = 500;
res.body.error = "Invalid UserID"
})
})
test("Getting likes with valid userID returns 200 status", async () => {
await request(app).post("localhost:5000/api/getLikes")
.send({
userID: "625c890a9b12478a46212a3f"
})
.expect((res) => {
res.body.status = 200;
})
})
})
describe("Testing Getting Country Recipes", () => {
test("Getting country recipes with invalid country returns error", async () => {
await request(app).post("localhost:5000/api/getCountryRecipes")
.send({
country: "InvalidCountry"
})
.expect((res) => {
res.body.status = 500;
res.body.error = "Country not found"
})
})
test("Getting country recipes with valid country returns 200 status code", async () => {
await request(app).post("localhost:5000/api/getCountryRecipes")
.send({
country: "Italy"
})
.expect((res) => {
res.body.status = 200;
})
})
})
describe("Testing Edit User", () => {
test("Trying to edit a user with invalid userID returns error", async () => {
await request(app).post("localhost:5000/api/updateUser")
.send({
userID: "625c890a9b12478a46212333",
password: "test",
profilePic: "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png",
email: "[email protected]"
})
.expect((res) => {
res.body.status = 404,
res.body.error = "User does not exist."
})
})
test("Trying to edit a user with valid userID returns 200 status and empty error", async () => {
await request(app).post("localhost:5000/api/updateUser")
.send({
userID: "625c890a9b12478a46212a3f",
password: "test",
profilePic: "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png",
email: "[email protected]"
})
.expect((res) => {
res.body.status = 200,
res.body.error = ""
})
})
})
describe("Testing View Recipe", () => {
test("Trying to view a recipe with an invalid recipeID returns an error", async () => {
await request(app).post("localhost:5000/api/viewRecipe")
.send({
recipeID: "625c8c3b31f81d046773e333"
})
.expect((res) => {
res.body.status = 404,
res.body.error = "Recipe not found"
})
})
test("Trying to view a recipe with a valid recipeID returns a 200 status code", async () => {
await request(app).post("localhost:5000/api/viewRecipe")
.send({
recipeID: "625c8c3b31f81d046773ecf3"
})
.expect((res) => {
res.body.status = 200
})
})
})