@@ -62,15 +62,15 @@ describe("MatrixHttpApi", () => {
6262 it ( "should fall back to `fetch` where xhr is unavailable" , async ( ) => {
6363 globalThis . XMLHttpRequest = undefined ! ;
6464 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 } ) ;
6666 upload = api . uploadContent ( { } as File ) ;
6767 await upload ;
6868 expect ( fetchFn ) . toHaveBeenCalled ( ) ;
6969 } ) ;
7070
7171 it ( "should prefer xhr where available" , ( ) => {
7272 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 } ) ;
7474 upload = api . uploadContent ( { } as File ) ;
7575 expect ( fetchFn ) . not . toHaveBeenCalled ( ) ;
7676 expect ( xhr . open ) . toHaveBeenCalled ( ) ;
@@ -82,6 +82,7 @@ describe("MatrixHttpApi", () => {
8282 prefix,
8383 accessToken : "token" ,
8484 useAuthorizationHeader : false ,
85+ onlyData : true ,
8586 } ) ;
8687 upload = api . uploadContent ( { } as File ) ;
8788 expect ( xhr . open ) . toHaveBeenCalledWith (
@@ -96,14 +97,15 @@ describe("MatrixHttpApi", () => {
9697 baseUrl,
9798 prefix,
9899 accessToken : "token" ,
100+ onlyData : true ,
99101 } ) ;
100102 upload = api . uploadContent ( { } as File ) ;
101103 expect ( xhr . open ) . toHaveBeenCalledWith ( Method . Post , baseUrl . toLowerCase ( ) + "/_matrix/media/v3/upload" ) ;
102104 expect ( xhr . setRequestHeader ) . toHaveBeenCalledWith ( "Authorization" , "Bearer token" ) ;
103105 } ) ;
104106
105107 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 } ) ;
107109 upload = api . uploadContent ( { } as File , { name : "name" } ) ;
108110 expect ( xhr . open ) . toHaveBeenCalledWith (
109111 Method . Post ,
@@ -112,21 +114,21 @@ describe("MatrixHttpApi", () => {
112114 } ) ;
113115
114116 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 } ) ;
116118 upload = api . uploadContent ( { } as File , { name : "name" , includeFilename : false } ) ;
117119 expect ( xhr . open ) . toHaveBeenCalledWith ( Method . Post , baseUrl . toLowerCase ( ) + "/_matrix/media/v3/upload" ) ;
118120 } ) ;
119121
120122 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 } ) ;
122124 upload = api . uploadContent ( { } as File ) ;
123125 api . cancelUpload ( upload ) ;
124126 expect ( xhr . abort ) . toHaveBeenCalled ( ) ;
125127 return expect ( upload ) . rejects . toThrow ( "Aborted" ) ;
126128 } ) ;
127129
128130 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 } ) ;
130132 upload = api . uploadContent ( { } as File ) ;
131133 jest . advanceTimersByTime ( 25000 ) ;
132134 // @ts -ignore
@@ -138,7 +140,7 @@ describe("MatrixHttpApi", () => {
138140 } ) ;
139141
140142 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 } ) ;
142144 const progressHandler = jest . fn ( ) ;
143145 upload = api . uploadContent ( { } as File , { progressHandler } ) ;
144146 const progressEvent = new Event ( "progress" ) as ProgressEvent ;
@@ -154,7 +156,7 @@ describe("MatrixHttpApi", () => {
154156 } ) ;
155157
156158 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 } ) ;
158160 upload = api . uploadContent ( { } as File ) ;
159161
160162 xhr . readyState = DONE ;
@@ -167,7 +169,7 @@ describe("MatrixHttpApi", () => {
167169 } ) ;
168170
169171 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 } ) ;
171173 upload = api . uploadContent ( { } as File ) ;
172174
173175 xhr . readyState = DONE ;
@@ -184,7 +186,7 @@ describe("MatrixHttpApi", () => {
184186 } ) ;
185187
186188 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 } ) ;
188190 upload = api . uploadContent ( { } as File ) ;
189191
190192 xhr . readyState = DONE ;
@@ -198,14 +200,14 @@ describe("MatrixHttpApi", () => {
198200 } ) ;
199201
200202 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 } ) ;
202204 upload = api . uploadContent ( { } as File ) ;
203205 expect ( api . cancelUpload ( upload ) ) . toBeTruthy ( ) ;
204206 expect ( xhr . abort ) . toHaveBeenCalled ( ) ;
205207 } ) ;
206208
207209 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 } ) ;
209211 upload = api . uploadContent ( { } as File ) ;
210212
211213 xhr . readyState = DONE ;
@@ -220,15 +222,20 @@ describe("MatrixHttpApi", () => {
220222 } ) ;
221223
222224 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 } ) ;
224226 upload = api . uploadContent ( { } as File ) ;
225227 expect ( api . getCurrentUploads ( ) . find ( ( u ) => u . promise === upload ) ) . toBeTruthy ( ) ;
226228 api . cancelUpload ( upload ) ;
227229 expect ( api . getCurrentUploads ( ) . find ( ( u ) => u . promise === upload ) ) . toBeFalsy ( ) ;
228230 } ) ;
229231
230232 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+ } ) ;
232239 expect ( api . getContentUri ( ) ) . toMatchSnapshot ( ) ;
233240 } ) ;
234241} ) ;
0 commit comments