@@ -524,8 +524,9 @@ describe('Api/Upload/Uploaders/S3', () => {
524524 } ) ;
525525
526526 const firstPartOffset = 0 ;
527- const firstPartMetadata = testFile . getPartMetadata ( 0 , INTELLIGENT_CHUNK_SIZE ) ;
528- const firstPartChunk = await testFile . getChunkByMetadata ( firstPartMetadata , firstPartOffset , chunkSize ) ;
527+ const { partsCount, chunkSize : dynamicPartSize } = testFile . getPartsCount ( INTELLIGENT_CHUNK_SIZE , true ) ;
528+ const firstPartMetadata = testFile . getPartMetadata ( 0 , dynamicPartSize ) ;
529+ const firstPartChunk = await testFile . getChunkByMetadata ( firstPartMetadata , firstPartOffset , dynamicPartSize ) ;
529530
530531 expect ( mockUpload ) . toHaveBeenCalledWith ( {
531532 md5 : firstPartChunk . md5 ,
@@ -544,26 +545,84 @@ describe('Api/Upload/Uploaders/S3', () => {
544545
545546 expect ( mockPut ) . toHaveBeenCalledWith ( '/fakes3' , expect . any ( Object ) ) ;
546547
547- const secondPartOffset = chunkSize ;
548- const firstPartSecondChunk = await testFile . getChunkByMetadata ( firstPartMetadata , secondPartOffset , chunkSize ) ;
548+ expect ( mockPut ) . toHaveBeenCalledWith ( '/fakes3' , expect . any ( Object ) ) ;
549+
550+ expect ( mockCommit ) . toHaveBeenCalledWith ( {
551+ apikey : testApikey ,
552+ part : 1 ,
553+ size : testFile . size ,
554+ region : mockRegion ,
555+ uri : mockedUri ,
556+ upload_id : mockUploadId ,
557+ store : {
558+ location : DEFAULT_STORE_LOCATION ,
559+ } ,
560+ } ) ;
561+
562+ expect ( mockComplete ) . toHaveBeenCalledWith ( {
563+ apikey : testApikey ,
564+ filename : testFile . name ,
565+ mimetype : testFile . mimetype ,
566+ size : testFile . size ,
567+ region : mockRegion ,
568+ upload_id : mockUploadId ,
569+ store : {
570+ location : DEFAULT_STORE_LOCATION ,
571+ } ,
572+ fii : true ,
573+ uri : mockedUri ,
574+ } ) ;
575+ } ) ;
576+
577+ it ( 'should upload file' , async ( ) => {
578+ const chunkSize = 1024 * 1024 ;
579+
580+ const u = new S3Uploader ( { } ) ;
581+ u . setUrl ( testHost ) ;
582+ u . setApikey ( testApikey ) ;
583+ u . setUploadMode ( UploadMode . INTELLIGENT ) ;
584+ u . setIntelligentChunkSize ( chunkSize ) ;
585+ u . addFile ( getSmallTestFile ( ) ) ;
586+
587+ const res = await u . execute ( ) ;
588+ expect ( res [ 0 ] . handle ) . toEqual ( 'test_handle' ) ;
589+
590+ const testFile = getSmallTestFile ( ) ;
591+ expect ( mockStart ) . toHaveBeenCalledWith ( {
592+ filename : testFile . name ,
593+ mimetype : testFile . mimetype ,
594+ size : testFile . size ,
595+ store : {
596+ location : DEFAULT_STORE_LOCATION ,
597+ } ,
598+ apikey : testApikey ,
599+ fii : true ,
600+ } ) ;
601+
602+ const firstPartOffset = 0 ;
603+ const { partsCount, chunkSize : dynamicPartSize } = testFile . getPartsCount ( INTELLIGENT_CHUNK_SIZE , true ) ;
604+ const firstPartMetadata = testFile . getPartMetadata ( 0 , dynamicPartSize ) ;
605+ const firstPartChunk = await testFile . getChunkByMetadata ( firstPartMetadata , firstPartOffset , dynamicPartSize ) ;
549606
550607 expect ( mockUpload ) . toHaveBeenCalledWith ( {
551- md5 : firstPartSecondChunk . md5 ,
552- size : firstPartSecondChunk . size ,
608+ md5 : firstPartChunk . md5 ,
609+ size : firstPartChunk . size ,
553610 apikey : testApikey ,
554611 region : mockRegion ,
555612 store : {
556613 location : DEFAULT_STORE_LOCATION ,
557614 } ,
558615 uri : mockedUri ,
559616 upload_id : mockUploadId ,
560- offset : secondPartOffset ,
617+ offset : firstPartOffset ,
561618 fii : true ,
562619 part : 1 ,
563620 } ) ;
564621
565622 expect ( mockPut ) . toHaveBeenCalledWith ( '/fakes3' , expect . any ( Object ) ) ;
566623
624+ expect ( mockPut ) . toHaveBeenCalledWith ( '/fakes3' , expect . any ( Object ) ) ;
625+
567626 expect ( mockCommit ) . toHaveBeenCalledWith ( {
568627 apikey : testApikey ,
569628 part : 1 ,
@@ -623,8 +682,9 @@ describe('Api/Upload/Uploaders/S3', () => {
623682 expect ( res [ 0 ] . status ) . toEqual ( 'test_status' ) ;
624683
625684 const testFile = getSmallTestFile ( ) ;
626- const firstPartMetadata = testFile . getPartMetadata ( 0 , INTELLIGENT_CHUNK_SIZE ) ;
627- const firstPartChunk = await testFile . getChunkByMetadata ( firstPartMetadata , 0 , INTELLIGENT_CHUNK_SIZE ) ;
685+ const { partsCount, chunkSize : dynamicPartSize } = testFile . getPartsCount ( INTELLIGENT_CHUNK_SIZE , true ) ;
686+ const firstPartMetadata = testFile . getPartMetadata ( 0 , dynamicPartSize ) ;
687+ const firstPartChunk = await testFile . getChunkByMetadata ( firstPartMetadata , 0 , dynamicPartSize ) ;
628688
629689 // this request will be aborted but called on mock upload
630690 expect ( mockUpload ) . toHaveBeenNthCalledWith ( 1 , {
@@ -643,8 +703,10 @@ describe('Api/Upload/Uploaders/S3', () => {
643703 } ) ;
644704
645705 // split part size by a half and retry request (thats give us 2 chunks so 2 upload requests needed)
646- const chunkSize = Math . min ( INTELLIGENT_CHUNK_SIZE , testFile . size ) / 2 ;
647- const chunk1 = await testFile . getChunkByMetadata ( firstPartMetadata , 0 , chunkSize ) ;
706+ let { chunkSize } = testFile . getPartsCount ( INTELLIGENT_CHUNK_SIZE , true ) ;
707+ chunkSize = chunkSize / 2 ;
708+ const updatedFirstPartMetaData = testFile . getPartMetadata ( 0 , chunkSize ) ;
709+ const chunk1 = await testFile . getChunkByMetadata ( updatedFirstPartMetaData , 0 , chunkSize ) ;
648710
649711 expect ( mockUpload ) . toHaveBeenNthCalledWith ( 2 , {
650712 md5 : chunk1 . md5 ,
0 commit comments