@@ -97,7 +97,9 @@ describe("Test Question API", () => {
97
97
98
98
const res = await request . post ( "/api/create" ) . send ( newQuestion ) ;
99
99
expect ( res . statusCode ) . toBe ( 400 ) ;
100
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
100
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
101
+ "Category must contain only non-empty strings"
102
+ ) ;
101
103
expect ( res . body . errors [ 0 ] . path ) . toBe ( "category" ) ;
102
104
} ) ;
103
105
@@ -172,7 +174,9 @@ describe("Test Question API", () => {
172
174
173
175
const res = await request . post ( "/api/create" ) . send ( newQuestion ) ;
174
176
expect ( res . statusCode ) . toBe ( 400 ) ;
175
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
177
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
178
+ "Category must contain only non-empty strings"
179
+ ) ;
176
180
expect ( res . body . errors [ 0 ] . path ) . toBe ( "category" ) ;
177
181
} ) ;
178
182
@@ -187,7 +191,9 @@ describe("Test Question API", () => {
187
191
188
192
const res = await request . post ( "/api/create" ) . send ( newQuestion ) ;
189
193
expect ( res . statusCode ) . toBe ( 400 ) ;
190
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
194
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
195
+ "Category must contain only non-empty strings"
196
+ ) ;
191
197
expect ( res . body . errors [ 0 ] . path ) . toBe ( "category" ) ;
192
198
} ) ;
193
199
@@ -202,7 +208,9 @@ describe("Test Question API", () => {
202
208
203
209
const res = await request . post ( "/api/create" ) . send ( newQuestion ) ;
204
210
expect ( res . statusCode ) . toBe ( 400 ) ;
205
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
211
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
212
+ "Category must contain only non-empty strings"
213
+ ) ;
206
214
expect ( res . body . errors [ 0 ] . path ) . toBe ( "category" ) ;
207
215
} ) ;
208
216
@@ -227,10 +235,13 @@ describe("Test Get All", () => {
227
235
// Get all with questions
228
236
test ( "GET /api/all - should retrieve all questions" , async ( ) => {
229
237
const res = await request . get ( "/api/all" ) . send ( ) ;
230
- const sampleQuestion = res . body [ 0 ] ;
238
+ const sampleQuestion = res . body . questions [ 0 ] ;
231
239
expect ( res . statusCode ) . toBe ( 200 ) ;
232
- expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
233
- expect ( res . body . length ) . toBe ( 1 ) ;
240
+ expect ( Array . isArray ( res . body . questions ) ) . toBe ( true ) ;
241
+ expect ( res . body . questions . length ) . toBe ( 1 ) ;
242
+ expect ( res . body . currentPage ) . toBe ( 1 ) ;
243
+ expect ( res . body . totalPages ) . toBe ( 1 ) ;
244
+ expect ( res . body . totalQuestions ) . toBe ( 1 ) ;
234
245
expect ( sampleQuestion ) . toHaveProperty ( "title" , "Sample Question" ) ;
235
246
expect ( sampleQuestion ) . toHaveProperty (
236
247
"description" ,
@@ -326,7 +337,7 @@ describe("Test Update", () => {
326
337
// Update with invalid category
327
338
test ( "POST - empty category" , async ( ) => {
328
339
const updateQuestion = {
329
- category : [ ]
340
+ category : [ ] ,
330
341
} ;
331
342
const questionId = 1090 ;
332
343
const res = await request
@@ -347,7 +358,9 @@ describe("Test Update", () => {
347
358
. post ( `/api/${ questionId } /update` )
348
359
. send ( updateQuestion ) ;
349
360
expect ( res . statusCode ) . toBe ( 400 ) ;
350
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
361
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
362
+ "Category must contain only non-empty strings"
363
+ ) ;
351
364
} ) ;
352
365
353
366
// Update with invalid category
@@ -362,7 +375,9 @@ describe("Test Update", () => {
362
375
. post ( `/api/${ questionId } /update` )
363
376
. send ( updateQuestion ) ;
364
377
expect ( res . statusCode ) . toBe ( 400 ) ;
365
- expect ( res . body . errors [ 0 ] . msg ) . toBe ( "Category must contain only non-empty strings" ) ;
378
+ expect ( res . body . errors [ 0 ] . msg ) . toBe (
379
+ "Category must contain only non-empty strings"
380
+ ) ;
366
381
} ) ;
367
382
368
383
// Negative id
0 commit comments