@@ -30,6 +30,7 @@ describe('fileDownloader', () => {
30
30
expect ( result ) . toBeInstanceOf ( Blob ) ;
31
31
expect ( result ) . toEqual ( mockBlob ) ;
32
32
expect ( mockAxiosInstance . get ) . toHaveBeenCalledWith ( url , {
33
+ method : 'GET' ,
33
34
responseType : 'blob' ,
34
35
responseReturn : 'body' ,
35
36
} ) ;
@@ -51,6 +52,7 @@ describe('fileDownloader', () => {
51
52
expect ( result ) . toEqual ( mockBlob ) ;
52
53
expect ( mockAxiosInstance . get ) . toHaveBeenCalledWith ( url , {
53
54
...customConfig ,
55
+ method : 'GET' ,
54
56
responseType : 'blob' ,
55
57
responseReturn : 'body' ,
56
58
} ) ;
@@ -84,3 +86,72 @@ describe('fileDownloader', () => {
84
86
) ;
85
87
} ) ;
86
88
} ) ;
89
+
90
+ describe ( 'fileDownloader use other method' , ( ) => {
91
+ let fileDownloader : FileDownloader ;
92
+
93
+ it ( 'should call request using get' , async ( ) => {
94
+ const url = 'https://example.com/file' ;
95
+ const mockBlob = new Blob ( [ 'file content' ] , { type : 'text/plain' } ) ;
96
+ const mockResponse : Blob = mockBlob ;
97
+
98
+ const mockAxiosInstance = {
99
+ request : vi . fn ( ) ,
100
+ } as any ;
101
+
102
+ fileDownloader = new FileDownloader ( mockAxiosInstance ) ;
103
+
104
+ mockAxiosInstance . request . mockResolvedValueOnce ( mockResponse ) ;
105
+
106
+ const result = await fileDownloader . download ( url ) ;
107
+
108
+ expect ( result ) . toBeInstanceOf ( Blob ) ;
109
+ expect ( result ) . toEqual ( mockBlob ) ;
110
+ expect ( mockAxiosInstance . request ) . toHaveBeenCalledWith ( url , {
111
+ method : 'GET' ,
112
+ responseType : 'blob' ,
113
+ responseReturn : 'body' ,
114
+ } ) ;
115
+ } ) ;
116
+
117
+ it ( 'should call post' , async ( ) => {
118
+ const url = 'https://example.com/file' ;
119
+
120
+ const mockAxiosInstance = {
121
+ post : vi . fn ( ) ,
122
+ } as any ;
123
+
124
+ fileDownloader = new FileDownloader ( mockAxiosInstance ) ;
125
+
126
+ const customConfig : AxiosRequestConfig = {
127
+ method : 'POST' ,
128
+ data : { name : 'aa' } ,
129
+ } ;
130
+
131
+ await fileDownloader . download ( url , customConfig ) ;
132
+
133
+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith (
134
+ url ,
135
+ { name : 'aa' } ,
136
+ {
137
+ method : 'POST' ,
138
+ responseType : 'blob' ,
139
+ responseReturn : 'body' ,
140
+ } ,
141
+ ) ;
142
+ } ) ;
143
+
144
+ it ( 'should handle errors gracefully' , async ( ) => {
145
+ const url = 'https://example.com/file' ;
146
+ const mockAxiosInstance = {
147
+ post : vi . fn ( ) ,
148
+ } as any ;
149
+
150
+ fileDownloader = new FileDownloader ( mockAxiosInstance ) ;
151
+ await expect ( ( ) =>
152
+ fileDownloader . download ( url , { method : 'postt' } ) ,
153
+ ) . rejects . toThrow (
154
+ 'RequestClient does not support method "POSTT". Please ensure the method is properly implemented in your RequestClient instance.' ,
155
+ ) ;
156
+ } ) ;
157
+ } ) ;
0 commit comments