@@ -30,7 +30,6 @@ afterAll(async () => {
30
30
} ) ;
31
31
32
32
33
-
34
33
describe ( 'Server endpoint tests' , ( ) => {
35
34
it ( 'should pass this test request' , async ( ) => {
36
35
const response = await request ( app ) . get ( '/test' ) ;
@@ -103,7 +102,7 @@ describe('Server endpoint tests', () => {
103
102
. set ( 'Content-Type' , 'application/json' )
104
103
. send ( { _id, userId } )
105
104
. expect ( 200 )
106
- . then ( ( res ) => expect ( res . body . _id ) . toBe ( _id ) ) ; // @Denton might want to check more of these fields
105
+ . then ( ( res ) => expect ( res . body . _id ) . toBe ( _id ) ) ;
107
106
} ) ;
108
107
} ) ;
109
108
} ) ;
@@ -118,7 +117,6 @@ describe('Server endpoint tests', () => {
118
117
. set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
119
118
. set ( 'Accept' , 'application/json' )
120
119
. send ( projectToSave )
121
-
122
120
const _id : String = projObj . body . _id ;
123
121
const project : String = projObj . body . project ;
124
122
const comments : String = projObj . body . comments ;
@@ -136,19 +134,56 @@ describe('Server endpoint tests', () => {
136
134
expect ( res . body . published ) . toBe ( true ) ;
137
135
} ) ;
138
136
} ) ;
137
+ it ( 'responds with status of 500 and error if userId and cookie ssid do not match' , async ( ) => {
138
+ const projObj : Response = await request ( app ) . post ( '/getProjects' ) . set ( 'Accept' , 'application/json' ) . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] ) . send ( { userId : projectToSave . userId } ) ;
139
+ const _id : String = projObj . body [ 0 ] . _id ;
140
+ const project : String = projObj . body [ 0 ] . project ;
141
+ const comments : String = projObj . body [ 0 ] . comments ;
142
+ const username : String = projObj . body [ 0 ] . username ;
143
+ const name : String = projObj . body [ 0 ] . name ;
144
+ const userId : String = "ERROR" ;
145
+ return request ( app )
146
+ . post ( '/publishProject' )
147
+ . set ( 'Content-Type' , 'application/json' )
148
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
149
+ . send ( { _id, project, comments, userId, username, name } ) //_id, project, comments, userId, username, name
150
+ . expect ( 500 )
151
+ . then ( ( res ) => {
152
+ expect ( res . body . err ) . not . toBeNull ( )
153
+ } ) ;
154
+ } ) ;
155
+ it ( 'responds with status of 500 and error if _id was not a valid mongo ObjectId' , async ( ) => {
156
+ const projObj : Response = await request ( app ) . post ( '/getProjects' ) . set ( 'Accept' , 'application/json' ) . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] ) . send ( { userId : projectToSave . userId } ) ;
157
+ const _id : String = 'ERROR' ;
158
+ const project : String = projObj . body [ 0 ] . project ;
159
+ const comments : String = projObj . body [ 0 ] . comments ;
160
+ const username : String = user . username ;
161
+ const name : String = projObj . body [ 0 ] . name ;
162
+ const userId : String = user . userId ;
163
+
164
+ return request ( app )
165
+ . post ( '/publishProject' )
166
+ . set ( 'Content-Type' , 'application/json' )
167
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
168
+ . send ( { _id, project, comments, userId, username, name } ) //_id, project, comments, userId, username, name
169
+ . expect ( 200 )
170
+ . then ( ( res ) => {
171
+ expect ( res . body . _id ) . not . toEqual ( _id )
172
+ } ) ;
173
+ } ) ;
139
174
} ) ;
140
175
} ) ;
141
176
142
177
//test getMarketplaceProjects endpoint
143
178
describe ( '/getMarketplaceProjects' , ( ) => { //most recent project should be the one from publishProject
179
+
144
180
describe ( 'GET' , ( ) => {
145
181
it ( 'responds with status of 200 and json object equal to unpublished project' , async ( ) => {
146
182
return request ( app )
147
183
. get ( '/getMarketplaceProjects' )
148
184
. set ( 'Content-Type' , 'application/json' )
149
185
. expect ( 200 )
150
186
. then ( ( res ) => {
151
-
152
187
expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
153
188
expect ( res . body [ 0 ] . _id ) . toBeTruthy ;
154
189
} ) ;
@@ -164,13 +199,7 @@ describe('Server endpoint tests', () => {
164
199
const projObj = await request ( app )
165
200
. get ( '/getMarketplaceProjects' )
166
201
. set ( 'Content-Type' , 'application/json' )
167
- console . log ( projObj . body )
168
- // const _id: String = projObj.body._id;
169
- // const project: String = projObj.body.project;
170
- // const comments: String = projObj.body.comments;
171
- // const username: String = projObj.body.username;
172
- // const name: String = projObj.body.name;
173
- // const userId: String = user.userId;
202
+
174
203
return request ( app )
175
204
. get ( `/cloneProject/${ projObj . body [ 0 ] . _id } ` )
176
205
. set ( 'Cookie' , [ `ssid=${ user . userId } ` ] ) // Set the cookie
@@ -181,6 +210,21 @@ describe('Server endpoint tests', () => {
181
210
expect ( res . body . username ) . toBe ( user . username ) ;
182
211
} ) ;
183
212
} ) ;
213
+ it ( 'responds with status of 500 and error' , async ( ) => {
214
+
215
+ const projObj = await request ( app )
216
+ . get ( '/getMarketplaceProjects' )
217
+ . set ( 'Content-Type' , 'application/json' )
218
+
219
+ return request ( app )
220
+ . get ( `/cloneProject/${ projObj . body [ 0 ] . _id } ` )
221
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] ) // Set the cookie
222
+ . query ( { username : [ ] } )
223
+ . expect ( 500 )
224
+ . then ( ( res ) => {
225
+ expect ( res . body . err ) . not . toBeNull ( )
226
+ } ) ;
227
+ } ) ;
184
228
} ) ;
185
229
} ) ;
186
230
@@ -195,12 +239,51 @@ describe('Server endpoint tests', () => {
195
239
. patch ( '/unpublishProject' )
196
240
. set ( 'Content-Type' , 'application/json' )
197
241
. set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
198
- . send ( { _id, userId } ) //_id, project, comments, userId, username, name
242
+ . send ( { _id, userId } )
199
243
. expect ( 200 )
200
244
. then ( ( res ) => {
201
245
expect ( res . body . _id ) . toBe ( _id )
202
246
expect ( res . body . published ) . toBe ( false ) ;
203
- } ) ; // @Denton might want to check more of these fields
247
+ } ) ;
248
+ } ) ;
249
+ it ( 'responds with status of 500 and error if userId and cookie ssid do not match' , async ( ) => {
250
+ const projObj : Response = await request ( app ) . post ( '/getProjects' ) . set ( 'Accept' , 'application/json' ) . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] ) . send ( { userId : projectToSave . userId } ) ;
251
+ const _id : String = projObj . body [ 0 ] . _id ;
252
+ const project : String = projObj . body [ 0 ] . project ;
253
+ const comments : String = projObj . body [ 0 ] . comments ;
254
+ const username : String = projObj . body [ 0 ] . username ;
255
+ const name : String = projObj . body [ 0 ] . name ;
256
+ let userId : String = user . userId ;
257
+ await request ( app ) //publishing a project first
258
+ . post ( '/publishProject' )
259
+ . set ( 'Content-Type' , 'application/json' )
260
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
261
+ . send ( { _id, project, comments, userId, username, name } )
262
+
263
+
264
+ userId = "ERROR" ;
265
+ return request ( app )
266
+ . patch ( '/unpublishProject' )
267
+ . set ( 'Content-Type' , 'application/json' )
268
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
269
+ . send ( { _id, userId } )
270
+ . expect ( 500 )
271
+ . then ( ( res ) => {
272
+ expect ( res . body . err ) . not . toBeNull ( )
273
+ } ) ;
274
+ } ) ;
275
+ it ( 'responds with status of 500 and error if _id was not a string' , async ( ) => {
276
+ const userId : String = user . userId ;
277
+
278
+ return request ( app )
279
+ . patch ( '/unpublishProject' )
280
+ . set ( 'Content-Type' , 'application/json' )
281
+ . set ( 'Cookie' , [ `ssid=${ user . userId } ` ] )
282
+ . send ( { userId } )
283
+ . expect ( 500 )
284
+ . then ( ( res ) => {
285
+ expect ( res . body . err ) . not . toBeNull ( )
286
+ } ) ;
204
287
} ) ;
205
288
} ) ;
206
289
} ) ;
0 commit comments