@@ -2,8 +2,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
2
3
3
import 'whatwg-fetch'
4
4
import nock from 'nock'
5
- import Core from '@uppy/core'
6
- import AwsS3Multipart , { type AwsBody } from './index.js'
5
+ import Core , { type UppyFile } from '@uppy/core'
6
+ import AwsS3Multipart , {
7
+ type AwsBody ,
8
+ type AwsS3MultipartOptions ,
9
+ } from './index.js'
7
10
8
11
const KB = 1024
9
12
const MB = KB * KB
@@ -21,6 +24,92 @@ describe('AwsS3Multipart', () => {
21
24
expect ( pluginNames ) . toContain ( 'AwsS3Multipart' )
22
25
} )
23
26
27
+ describe ( 'defaultOptions' , ( ) => {
28
+ let opts : Partial < AwsS3MultipartOptions < any , any > >
29
+
30
+ beforeEach ( ( ) => {
31
+ const core = new Core < any , AwsBody > ( ) . use ( AwsS3Multipart )
32
+ const awsS3Multipart = core . getPlugin ( 'AwsS3Multipart' ) as any
33
+ opts = awsS3Multipart . opts
34
+ } )
35
+
36
+ it ( 'allowedMetaFields is true' , ( ) => {
37
+ expect ( opts . allowedMetaFields ) . toBe ( true )
38
+ } )
39
+
40
+ it ( 'limit is 6' , ( ) => {
41
+ expect ( opts . limit ) . toBe ( 6 )
42
+ } )
43
+
44
+ it ( 'getTemporarySecurityCredentials is false' , ( ) => {
45
+ expect ( opts . getTemporarySecurityCredentials ) . toBe ( false )
46
+ } )
47
+
48
+ describe ( 'shouldUseMultipart' , ( ) => {
49
+ const MULTIPART_THRESHOLD = 100 * MB
50
+
51
+ let shouldUseMultipart : ( file : UppyFile < any , AwsBody > ) => boolean
52
+
53
+ beforeEach ( ( ) => {
54
+ shouldUseMultipart = opts . shouldUseMultipart as (
55
+ file : UppyFile < any , AwsBody > ,
56
+ ) => boolean
57
+ } )
58
+
59
+ const createFile = ( size : number ) : UppyFile < any , any > => ( {
60
+ size,
61
+ data : new Blob ( ) ,
62
+ extension : '' ,
63
+ id : '' ,
64
+ isRemote : false ,
65
+ isGhost : false ,
66
+ meta : undefined ,
67
+ progress : {
68
+ percentage : 0 ,
69
+ bytesUploaded : 0 ,
70
+ bytesTotal : size ,
71
+ uploadComplete : false ,
72
+ uploadStarted : 0 ,
73
+ } ,
74
+ type : '' ,
75
+ } )
76
+
77
+ it ( 'returns true for files larger than 100MB' , ( ) => {
78
+ const file = createFile ( MULTIPART_THRESHOLD + 1 )
79
+ expect ( shouldUseMultipart ( file ) ) . toBe ( true )
80
+ } )
81
+
82
+ it ( 'returns false for files exactly 100MB' , ( ) => {
83
+ const file = createFile ( MULTIPART_THRESHOLD )
84
+ expect ( shouldUseMultipart ( file ) ) . toBe ( false )
85
+ } )
86
+
87
+ it ( 'returns false for files smaller than 100MB' , ( ) => {
88
+ const file = createFile ( MULTIPART_THRESHOLD - 1 )
89
+ expect ( shouldUseMultipart ( file ) ) . toBe ( false )
90
+ } )
91
+
92
+ it ( 'returns true for large files (~70GB)' , ( ) => {
93
+ const file = createFile ( 70 * 1024 * MB )
94
+ expect ( shouldUseMultipart ( file ) ) . toBe ( true )
95
+ } )
96
+
97
+ it ( 'returns true for very large files (~400GB)' , ( ) => {
98
+ const file = createFile ( 400 * 1024 * MB )
99
+ expect ( shouldUseMultipart ( file ) ) . toBe ( true )
100
+ } )
101
+
102
+ it ( 'returns false for files with size 0' , ( ) => {
103
+ const file = createFile ( 0 )
104
+ expect ( shouldUseMultipart ( file ) ) . toBe ( false )
105
+ } )
106
+ } )
107
+
108
+ it ( 'retryDelays is [0, 1000, 3000, 5000]' , ( ) => {
109
+ expect ( opts . retryDelays ) . toEqual ( [ 0 , 1000 , 3000 , 5000 ] )
110
+ } )
111
+ } )
112
+
24
113
describe ( 'companionUrl assertion' , ( ) => {
25
114
it ( 'Throws an error for main functions if configured without companionUrl' , ( ) => {
26
115
const core = new Core ( ) . use ( AwsS3Multipart )
0 commit comments