diff --git a/packages/effects/request/src/request-client/modules/uploader.test.ts b/packages/effects/request/src/request-client/modules/uploader.test.ts index 7c4eb5e6..83066562 100644 --- a/packages/effects/request/src/request-client/modules/uploader.test.ts +++ b/packages/effects/request/src/request-client/modules/uploader.test.ts @@ -34,7 +34,7 @@ describe('fileUploader', () => { mockAxiosInstance.post as unknown as ReturnType ).mockResolvedValueOnce(mockResponse); - const result = await fileUploader.upload(url, file); + const result = await fileUploader.upload(url, { file }); expect(result).toEqual(mockResponse); expect(mockAxiosInstance.post).toHaveBeenCalledWith( url, @@ -66,7 +66,7 @@ describe('fileUploader', () => { headers: { 'Custom-Header': 'value' }, }; - const result = await fileUploader.upload(url, file, customConfig); + const result = await fileUploader.upload(url, { file }, customConfig); expect(result).toEqual(mockResponse); expect(mockAxiosInstance.post).toHaveBeenCalledWith( url, @@ -87,7 +87,7 @@ describe('fileUploader', () => { mockAxiosInstance.post as unknown as ReturnType ).mockRejectedValueOnce(new Error('Network Error')); - await expect(fileUploader.upload(url, file)).rejects.toThrow( + await expect(fileUploader.upload(url, { file })).rejects.toThrow( 'Network Error', ); }); @@ -99,7 +99,7 @@ describe('fileUploader', () => { mockAxiosInstance.post as unknown as ReturnType ).mockRejectedValueOnce(new Error('Request failed with status code 404')); - await expect(fileUploader.upload(url, file)).rejects.toThrow( + await expect(fileUploader.upload(url, { file })).rejects.toThrow( 'Request failed with status code 404', ); }); @@ -111,7 +111,7 @@ describe('fileUploader', () => { mockAxiosInstance.post as unknown as ReturnType ).mockRejectedValueOnce(new Error('Request failed with status code 404')); - await expect(fileUploader.upload(url, file)).rejects.toThrow( + await expect(fileUploader.upload(url, { file })).rejects.toThrow( 'Request failed with status code 404', ); }); diff --git a/packages/effects/request/src/request-client/modules/uploader.ts b/packages/effects/request/src/request-client/modules/uploader.ts index 4b4737b7..e9a9f602 100644 --- a/packages/effects/request/src/request-client/modules/uploader.ts +++ b/packages/effects/request/src/request-client/modules/uploader.ts @@ -11,11 +11,14 @@ class FileUploader { public async upload( url: string, - file: Blob | File, + data: { file: Blob | File } & Record, config?: AxiosRequestConfig, ): Promise { const formData = new FormData(); - formData.append('file', file); + + Object.entries(data).forEach(([key, value]) => { + formData.append(key, value); + }); const finalConfig: AxiosRequestConfig = { ...config, diff --git a/packages/effects/request/src/request-client/request-client.test.ts b/packages/effects/request/src/request-client/request-client.test.ts index 601c523b..2d94525e 100644 --- a/packages/effects/request/src/request-client/request-client.test.ts +++ b/packages/effects/request/src/request-client/request-client.test.ts @@ -79,7 +79,9 @@ describe('requestClient', () => { : [400, { error: 'Bad Request' }]; }); - const response = await requestClient.upload('/test/upload', fileData); + const response = await requestClient.upload('/test/upload', { + file: fileData, + }); expect(response.data).toEqual({ data: 'file uploaded' }); });