@@ -285,6 +285,23 @@ describe('testing POST object via multipart upload', () => {
285
285
)
286
286
} )
287
287
288
+ test ( 'return 400 when uploading to object with no file name' , async ( ) => {
289
+ const form = new FormData ( )
290
+ form . append ( 'file' , fs . createReadStream ( `./src/test/assets/sadcat.jpg` ) )
291
+ const headers = Object . assign ( { } , form . getHeaders ( ) , {
292
+ authorization : `Bearer ${ anonKey } ` ,
293
+ } )
294
+
295
+ const response = await app ( ) . inject ( {
296
+ method : 'POST' ,
297
+ url : '/object/bucket4/' ,
298
+ headers,
299
+ payload : form ,
300
+ } )
301
+ expect ( response . statusCode ) . toBe ( 400 )
302
+ expect ( S3Backend . prototype . uploadObject ) . not . toHaveBeenCalled ( )
303
+ } )
304
+
288
305
test ( 'should not add row to database if upload fails' , async ( ) => {
289
306
// Mock S3 upload failure.
290
307
jest . spyOn ( S3Backend . prototype , 'uploadObject' ) . mockRejectedValue (
@@ -496,6 +513,27 @@ describe('testing POST object via binary upload', () => {
496
513
)
497
514
} )
498
515
516
+ test ( 'return 400 when uploading to object with no file name' , async ( ) => {
517
+ const path = './src/test/assets/sadcat.jpg'
518
+ const { size } = fs . statSync ( path )
519
+
520
+ const headers = {
521
+ authorization : `Bearer ${ anonKey } ` ,
522
+ 'Content-Length' : size ,
523
+ 'Content-Type' : 'image/jpeg' ,
524
+ 'x-upsert' : 'true' ,
525
+ }
526
+
527
+ const response = await app ( ) . inject ( {
528
+ method : 'POST' ,
529
+ url : '/object/bucket4/' ,
530
+ headers,
531
+ payload : fs . createReadStream ( path ) ,
532
+ } )
533
+ expect ( response . statusCode ) . toBe ( 400 )
534
+ expect ( S3Backend . prototype . uploadObject ) . not . toHaveBeenCalled ( )
535
+ } )
536
+
499
537
test ( 'should not add row to database if upload fails' , async ( ) => {
500
538
// Mock S3 upload failure.
501
539
jest . spyOn ( S3Backend . prototype , 'uploadObject' ) . mockRejectedValue (
0 commit comments