@@ -62,15 +62,15 @@ describe("MatrixHttpApi", () => {
62
62
it ( "should fall back to `fetch` where xhr is unavailable" , async ( ) => {
63
63
globalThis . XMLHttpRequest = undefined ! ;
64
64
const fetchFn = jest . fn ( ) . mockResolvedValue ( { ok : true , json : jest . fn ( ) . mockResolvedValue ( { } ) } ) ;
65
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, fetchFn } ) ;
65
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, fetchFn, onlyData : true } ) ;
66
66
upload = api . uploadContent ( { } as File ) ;
67
67
await upload ;
68
68
expect ( fetchFn ) . toHaveBeenCalled ( ) ;
69
69
} ) ;
70
70
71
71
it ( "should prefer xhr where available" , ( ) => {
72
72
const fetchFn = jest . fn ( ) . mockResolvedValue ( { ok : true } ) ;
73
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, fetchFn } ) ;
73
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, fetchFn, onlyData : true } ) ;
74
74
upload = api . uploadContent ( { } as File ) ;
75
75
expect ( fetchFn ) . not . toHaveBeenCalled ( ) ;
76
76
expect ( xhr . open ) . toHaveBeenCalled ( ) ;
@@ -82,6 +82,7 @@ describe("MatrixHttpApi", () => {
82
82
prefix,
83
83
accessToken : "token" ,
84
84
useAuthorizationHeader : false ,
85
+ onlyData : true ,
85
86
} ) ;
86
87
upload = api . uploadContent ( { } as File ) ;
87
88
expect ( xhr . open ) . toHaveBeenCalledWith (
@@ -96,14 +97,15 @@ describe("MatrixHttpApi", () => {
96
97
baseUrl,
97
98
prefix,
98
99
accessToken : "token" ,
100
+ onlyData : true ,
99
101
} ) ;
100
102
upload = api . uploadContent ( { } as File ) ;
101
103
expect ( xhr . open ) . toHaveBeenCalledWith ( Method . Post , baseUrl . toLowerCase ( ) + "/_matrix/media/v3/upload" ) ;
102
104
expect ( xhr . setRequestHeader ) . toHaveBeenCalledWith ( "Authorization" , "Bearer token" ) ;
103
105
} ) ;
104
106
105
107
it ( "should include filename by default" , ( ) => {
106
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
108
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
107
109
upload = api . uploadContent ( { } as File , { name : "name" } ) ;
108
110
expect ( xhr . open ) . toHaveBeenCalledWith (
109
111
Method . Post ,
@@ -112,21 +114,21 @@ describe("MatrixHttpApi", () => {
112
114
} ) ;
113
115
114
116
it ( "should allow not sending the filename" , ( ) => {
115
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
117
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
116
118
upload = api . uploadContent ( { } as File , { name : "name" , includeFilename : false } ) ;
117
119
expect ( xhr . open ) . toHaveBeenCalledWith ( Method . Post , baseUrl . toLowerCase ( ) + "/_matrix/media/v3/upload" ) ;
118
120
} ) ;
119
121
120
122
it ( "should abort xhr when the upload is aborted" , ( ) => {
121
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
123
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
122
124
upload = api . uploadContent ( { } as File ) ;
123
125
api . cancelUpload ( upload ) ;
124
126
expect ( xhr . abort ) . toHaveBeenCalled ( ) ;
125
127
return expect ( upload ) . rejects . toThrow ( "Aborted" ) ;
126
128
} ) ;
127
129
128
130
it ( "should timeout if no progress in 30s" , ( ) => {
129
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
131
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
130
132
upload = api . uploadContent ( { } as File ) ;
131
133
jest . advanceTimersByTime ( 25000 ) ;
132
134
// @ts -ignore
@@ -138,7 +140,7 @@ describe("MatrixHttpApi", () => {
138
140
} ) ;
139
141
140
142
it ( "should call progressHandler" , ( ) => {
141
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
143
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
142
144
const progressHandler = jest . fn ( ) ;
143
145
upload = api . uploadContent ( { } as File , { progressHandler } ) ;
144
146
const progressEvent = new Event ( "progress" ) as ProgressEvent ;
@@ -154,7 +156,7 @@ describe("MatrixHttpApi", () => {
154
156
} ) ;
155
157
156
158
it ( "should error when no response body" , ( ) => {
157
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
159
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
158
160
upload = api . uploadContent ( { } as File ) ;
159
161
160
162
xhr . readyState = DONE ;
@@ -167,7 +169,7 @@ describe("MatrixHttpApi", () => {
167
169
} ) ;
168
170
169
171
it ( "should error on a 400-code" , ( ) => {
170
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
172
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
171
173
upload = api . uploadContent ( { } as File ) ;
172
174
173
175
xhr . readyState = DONE ;
@@ -184,7 +186,7 @@ describe("MatrixHttpApi", () => {
184
186
} ) ;
185
187
186
188
it ( "should return response on successful upload" , ( ) => {
187
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
189
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
188
190
upload = api . uploadContent ( { } as File ) ;
189
191
190
192
xhr . readyState = DONE ;
@@ -198,14 +200,14 @@ describe("MatrixHttpApi", () => {
198
200
} ) ;
199
201
200
202
it ( "should abort xhr when calling `cancelUpload`" , ( ) => {
201
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
203
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
202
204
upload = api . uploadContent ( { } as File ) ;
203
205
expect ( api . cancelUpload ( upload ) ) . toBeTruthy ( ) ;
204
206
expect ( xhr . abort ) . toHaveBeenCalled ( ) ;
205
207
} ) ;
206
208
207
209
it ( "should return false when `cancelUpload` is called but unsuccessful" , async ( ) => {
208
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
210
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
209
211
upload = api . uploadContent ( { } as File ) ;
210
212
211
213
xhr . readyState = DONE ;
@@ -220,15 +222,20 @@ describe("MatrixHttpApi", () => {
220
222
} ) ;
221
223
222
224
it ( "should return active uploads in `getCurrentUploads`" , ( ) => {
223
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix } ) ;
225
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, onlyData : true } ) ;
224
226
upload = api . uploadContent ( { } as File ) ;
225
227
expect ( api . getCurrentUploads ( ) . find ( ( u ) => u . promise === upload ) ) . toBeTruthy ( ) ;
226
228
api . cancelUpload ( upload ) ;
227
229
expect ( api . getCurrentUploads ( ) . find ( ( u ) => u . promise === upload ) ) . toBeFalsy ( ) ;
228
230
} ) ;
229
231
230
232
it ( "should return expected object from `getContentUri`" , ( ) => {
231
- const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , { baseUrl, prefix, accessToken : "token" } ) ;
233
+ const api = new MatrixHttpApi ( new TypedEventEmitter < any , any > ( ) , {
234
+ baseUrl,
235
+ prefix,
236
+ accessToken : "token" ,
237
+ onlyData : true ,
238
+ } ) ;
232
239
expect ( api . getContentUri ( ) ) . toMatchSnapshot ( ) ;
233
240
} ) ;
234
241
} ) ;
0 commit comments