File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,12 @@ const fetchTasks = async (req, res) => {
142
142
143
143
if ( queryString !== undefined ) {
144
144
const searchParams = parseSearchQuery ( queryString ) ;
145
+ if ( ! searchParams . searchTerm ) {
146
+ return res . status ( 404 ) . json ( {
147
+ message : "No tasks found." ,
148
+ tasks : [ ] ,
149
+ } ) ;
150
+ }
145
151
const filterTasks = await tasks . fetchTasks ( searchParams . searchTerm ) ;
146
152
const tasksWithRdsAssigneeInfo = await fetchTasksWithRdsAssigneeInfo ( filterTasks ) ;
147
153
if ( tasksWithRdsAssigneeInfo . length === 0 ) {
Original file line number Diff line number Diff line change @@ -293,6 +293,23 @@ describe("Tasks", function () {
293
293
return done ( err ) ;
294
294
}
295
295
296
+ expect ( res ) . to . have . status ( 404 ) ;
297
+ expect ( res . body ) . to . be . a ( "object" ) ;
298
+ expect ( res . body . message ) . to . equal ( "No tasks found." ) ;
299
+ expect ( res . body . tasks ) . to . be . a ( "array" ) ;
300
+ expect ( res . body . tasks ) . to . have . lengthOf ( 0 ) ;
301
+ return done ( ) ;
302
+ } ) ;
303
+ } ) ;
304
+ it ( "Should return no task found when there is no searchterm" , function ( done ) {
305
+ chai
306
+ . request ( app )
307
+ . get ( `/tasks?q=searchTerm:` )
308
+ . end ( ( err , res ) => {
309
+ if ( err ) {
310
+ return done ( err ) ;
311
+ }
312
+
296
313
expect ( res ) . to . have . status ( 404 ) ;
297
314
expect ( res . body ) . to . be . a ( "object" ) ;
298
315
expect ( res . body . message ) . to . equal ( "No tasks found." ) ;
You can’t perform that action at this time.
0 commit comments