@@ -10,10 +10,17 @@ class MockApiService {
10
10
public static gotPresigned : boolean = false ;
11
11
public static registeredRecord : RecordVO = null ;
12
12
public static registeredDestination : string = null ;
13
+ public static multipartRegistered : {
14
+ record : RecordVO ;
15
+ uploadId : string ;
16
+ key : string ;
17
+ eTags : string [ ] ;
18
+ } = null ;
13
19
public static reset ( ) {
14
20
MockApiService . gotPresigned = false ;
15
21
MockApiService . registeredRecord = null ;
16
22
MockApiService . registeredDestination = null ;
23
+ MockApiService . multipartRegistered = null ;
17
24
}
18
25
public record = {
19
26
async registerRecord ( record : RecordVO , url : string ) {
@@ -53,6 +60,30 @@ class MockApiService {
53
60
] ,
54
61
} ) ;
55
62
} ,
63
+
64
+ async getMultipartUploadURLs ( size : number ) {
65
+ const partSize = 10 * 1024 * 1024 ;
66
+ const partCount = Math . ceil ( size / partSize ) ;
67
+ return {
68
+ urls : Array ( partCount )
69
+ . fill ( null )
70
+ . map ( ( _ , i ) => `multipart-url-${ i } ` ) ,
71
+ uploadId : 'test-upload-id' ,
72
+ key : 'test-file-key' ,
73
+ } ;
74
+ } ,
75
+ async registerMultipartRecord (
76
+ record : RecordVO ,
77
+ uploadId : string ,
78
+ key : string ,
79
+ eTags : string [ ] ,
80
+ ) {
81
+ MockApiService . multipartRegistered = { record, uploadId, key, eTags } ;
82
+ return new RecordVO ( {
83
+ displayName : 'multipart.txt' ,
84
+ parentFolderId : record . parentFolderId ,
85
+ } ) ;
86
+ } ,
56
87
} ;
57
88
}
58
89
@@ -97,4 +128,35 @@ describe('Uploader', () => {
97
128
expect ( MockApiService . registeredRecord . parentFolderId ) . toBe ( 1 ) ;
98
129
expect ( MockApiService . registeredDestination ) . toBe ( 'testurl' ) ;
99
130
} ) ;
131
+
132
+ it ( 'can do a multipart upload using MockApiService' , async ( ) => {
133
+ const file = new File ( [ new Uint8Array ( 200 * 1024 * 1024 ) ] , 'multipart.txt' ) ;
134
+ const uploadItem = new UploadItem (
135
+ file ,
136
+ new FolderVO ( { folderId : 2 , folder_linkId : 2 } ) ,
137
+ ) ;
138
+
139
+ const progressSpy = jasmine . createSpy ( ) ;
140
+
141
+ spyOn < any > ( uploader , 'uploadToMultipartUrl' ) . and . callFake (
142
+ async (
143
+ _url : string ,
144
+ _item : UploadItem ,
145
+ _pointer : number ,
146
+ eTags : string [ ] ,
147
+ ) => {
148
+ eTags . push ( 'etag-mock' ) ;
149
+ } ,
150
+ ) ;
151
+
152
+ const result = await ( uploader as any ) . uploadMultipart (
153
+ uploadItem ,
154
+ progressSpy ,
155
+ ) ;
156
+
157
+ expect ( MockApiService . multipartRegistered . record . parentFolderId ) . toBe ( 2 ) ;
158
+ expect ( MockApiService . multipartRegistered . eTags . length ) . toBe ( 20 ) ;
159
+ expect ( progressSpy ) . toHaveBeenCalled ( ) ;
160
+ expect ( result . displayName ) . toBe ( 'multipart.txt' ) ;
161
+ } ) ;
100
162
} ) ;
0 commit comments