Skip to content

Commit 06f34cd

Browse files
committed
PER-10200 Web app display error on multi part uploads
Fix response from multi part upload
1 parent 17d6225 commit 06f34cd

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/app/core/services/upload/uploader.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ class MockApiService {
1010
public static gotPresigned: boolean = false;
1111
public static registeredRecord: RecordVO = null;
1212
public static registeredDestination: string = null;
13+
public static multipartRegistered: {
14+
record: RecordVO;
15+
uploadId: string;
16+
key: string;
17+
eTags: string[];
18+
} = null;
1319
public static reset() {
1420
MockApiService.gotPresigned = false;
1521
MockApiService.registeredRecord = null;
1622
MockApiService.registeredDestination = null;
23+
MockApiService.multipartRegistered = null;
1724
}
1825
public record = {
1926
async registerRecord(record: RecordVO, url: string) {
@@ -53,6 +60,30 @@ class MockApiService {
5360
],
5461
});
5562
},
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+
},
5687
};
5788
}
5889

@@ -97,4 +128,35 @@ describe('Uploader', () => {
97128
expect(MockApiService.registeredRecord.parentFolderId).toBe(1);
98129
expect(MockApiService.registeredDestination).toBe('testurl');
99130
});
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+
});
100162
});

src/app/core/services/upload/uploader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { HttpClient, HttpEvent, HttpEventType } from '@angular/common/http';
33
import { Injectable } from '@angular/core';
44
import { ApiService } from '@shared/services/api/api.service';
55
import { EventService } from '@shared/services/event/event.service';
6+
import { RecordVO } from '@models/index';
67
import { UploadItem } from './uploadItem';
78

89
const buildForm = (fields: object, file: File) => {
@@ -132,7 +133,7 @@ export class Uploader {
132133
eTags,
133134
);
134135

135-
const record = response.getRecordVO();
136+
const record = response as unknown as RecordVO;
136137

137138
this.event.dispatch({
138139
action: 'submit',

0 commit comments

Comments
 (0)