Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 47651585
authored
Sep 19, 2024
by
Vben
Committed by
GitHub
Sep 19, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perf: the request client upload function supports more parameters (#4439)
1 parent
161820db
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
8 deletions
packages/effects/request/src/request-client/modules/uploader.test.ts
packages/effects/request/src/request-client/modules/uploader.ts
packages/effects/request/src/request-client/request-client.test.ts
packages/effects/request/src/request-client/modules/uploader.test.ts
View file @
4765158
...
...
@@ -34,7 +34,7 @@ describe('fileUploader', () => {
mockAxiosInstance
.
post
as
unknown
as
ReturnType
<
typeof
vi
.
fn
>
).
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
<
typeof
vi
.
fn
>
).
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
<
typeof
vi
.
fn
>
).
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
<
typeof
vi
.
fn
>
).
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'
,
);
});
...
...
packages/effects/request/src/request-client/modules/uploader.ts
View file @
4765158
...
...
@@ -11,11 +11,14 @@ class FileUploader {
public
async
upload
(
url
:
string
,
file
:
Blob
|
File
,
data
:
{
file
:
Blob
|
File
}
&
Record
<
string
,
any
>
,
config
?:
AxiosRequestConfig
,
):
Promise
<
AxiosResponse
>
{
const
formData
=
new
FormData
();
formData
.
append
(
'file'
,
file
);
Object
.
entries
(
data
).
forEach
(([
key
,
value
])
=>
{
formData
.
append
(
key
,
value
);
});
const
finalConfig
:
AxiosRequestConfig
=
{
...
config
,
...
...
packages/effects/request/src/request-client/request-client.test.ts
View file @
4765158
...
...
@@ -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'
});
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment