@@ -55,6 +55,31 @@ function makeStorage(url: string): Reference {
55
55
return new Reference ( service , url ) ;
56
56
}
57
57
58
+ function withFakeSend (
59
+ testFn : ( text : string ) => void ,
60
+ resolveFn : ( ) => void
61
+ ) : Reference {
62
+ function newSend (
63
+ xhrio : TestingXhrIo ,
64
+ url : string ,
65
+ method : string ,
66
+ body ?: ArrayBufferView | Blob | string | null ,
67
+ headers ?: Headers
68
+ ) : void {
69
+ ( body as Blob ) . text ( ) . then ( text => {
70
+ testFn ( text ) ;
71
+ xhrio . abort ( ) ;
72
+ resolveFn ( ) ;
73
+ } ) ;
74
+ }
75
+ const service = makeFakeService (
76
+ testShared . fakeApp ,
77
+ testShared . fakeAuthProvider ,
78
+ newSend
79
+ ) ;
80
+ return ref ( service , 'gs://test-bucket' ) ;
81
+ }
82
+
58
83
describe ( 'Firebase Storage > Reference' , ( ) => {
59
84
const root = makeStorage ( 'gs://test-bucket/' ) ;
60
85
const child = makeStorage ( 'gs://test-bucket/hello' ) ;
@@ -227,55 +252,44 @@ describe('Firebase Storage > Reference', () => {
227
252
} ) ;
228
253
229
254
describe ( 'uploadString' , ( ) => {
230
- it ( 'Uses metadata.contentType for RAW format' , async ( ) => {
255
+ it ( 'Uses metadata.contentType for RAW format' , done => {
231
256
// Regression test for b/30989476
232
- const snapshot = await uploadString ( child , 'hello' , StringFormat . RAW , {
257
+ const root = withFakeSend ( ( text : string ) => {
258
+ expect ( text ) . to . include ( '"contentType":"lol/wut"' ) ;
259
+ } , done ) ;
260
+ uploadString ( ref ( root , 'test' ) , 'hello' , StringFormat . RAW , {
233
261
contentType : 'lol/wut'
234
262
} as Metadata ) ;
235
- expect ( snapshot . metadata . contentType ) . to . equal ( 'lol/wut' ) ;
236
- } ) ;
237
- // it('Uses embedded content type in DATA_URL format', async () => {
238
- // const snapshot = await uploadString(
239
- // child,
240
- // 'data:lol/wat;base64,aaaa',
241
- // StringFormat.DATA_URL
242
- // );
243
- // expect(snapshot.metadata.contentType).to.equal('lol/wat');
244
- // });
245
- // it('Lets metadata.contentType override embedded content type in DATA_URL format', async () => {
246
- // const snapshot = await uploadString(
247
- // child,
248
- // 'data:ignore/me;base64,aaaa',
249
- // StringFormat.DATA_URL,
250
- // { contentType: 'tomato/soup' } as Metadata
251
- // );
252
- // expect(snapshot.metadata.contentType).to.equal('tomato/soup');
253
- // });
263
+ } ) ;
264
+ it ( 'Uses embedded content type in DATA_URL format' , done => {
265
+ const root = withFakeSend ( ( text : string ) => {
266
+ expect ( text ) . to . include ( '"contentType":"lol/wat"' ) ;
267
+ } , done ) ;
268
+ uploadString (
269
+ ref ( root , 'test' ) ,
270
+ 'data:lol/wat;base64,aaaa' ,
271
+ StringFormat . DATA_URL
272
+ ) ;
273
+ } ) ;
274
+ it ( 'Lets metadata.contentType override embedded content type in DATA_URL format' , done => {
275
+ const root = withFakeSend ( ( text : string ) => {
276
+ expect ( text ) . to . include ( '"contentType":"tomato/soup"' ) ;
277
+ } , done ) ;
278
+ uploadString (
279
+ ref ( root , 'test' ) ,
280
+ 'data:ignore/me;base64,aaaa' ,
281
+ StringFormat . DATA_URL ,
282
+ { contentType : 'tomato/soup' } as Metadata
283
+ ) ;
284
+ } ) ;
254
285
} ) ;
255
286
256
- describe . only ( 'uploadBytes' , ( ) => {
257
- it ( 'Uses metadata.contentType' , async ( ) => {
258
- function newSend (
259
- xhrio : TestingXhrIo ,
260
- url : string ,
261
- method : string ,
262
- body ?: ArrayBufferView | Blob | string | null ,
263
- headers ?: Headers
264
- ) : void {
265
- console . log ( body ) ;
266
- expect ( headers ) . to . not . be . undefined ;
267
- expect ( headers ! [ 'Authorization' ] ) . to . equal (
268
- 'Firebase ' + testShared . authToken
269
- ) ;
270
- }
271
- const service = makeFakeService (
272
- testShared . fakeApp ,
273
- testShared . fakeAuthProvider ,
274
- newSend
275
- ) ;
276
- const reference = ref ( service , 'gs://test-bucket' ) ;
277
- // Regression test for b/30989476
278
- await uploadBytes ( ref ( reference , 'hello' ) , new Blob ( ) , {
287
+ describe ( 'uploadBytes' , ( ) => {
288
+ it ( 'Uses metadata.contentType' , done => {
289
+ const root = withFakeSend ( ( text : string ) => {
290
+ expect ( text ) . to . include ( '"contentType":"lol/wut"' ) ;
291
+ } , done ) ;
292
+ uploadBytes ( ref ( root , 'hello' ) , new Blob ( ) , {
279
293
contentType : 'lol/wut'
280
294
} as Metadata ) ;
281
295
} ) ;
@@ -303,13 +317,13 @@ describe('Firebase Storage > Reference', () => {
303
317
'storage/invalid-root-operation'
304
318
) ;
305
319
} ) ;
306
- it ( 'uploadString throws' , ( ) => {
307
- expect ( ( ) =>
320
+ it ( 'uploadString throws' , async ( ) => {
321
+ await expect (
308
322
uploadString ( root , 'raw' , StringFormat . RAW )
309
323
) . to . be . rejectedWith ( 'storage/invalid-root-operation' ) ;
310
324
} ) ;
311
- it ( 'uploadBytes throws' , ( ) => {
312
- expect ( ( ) => uploadBytes ( root , new Blob ( [ 'a' ] ) ) ) . to . be . rejectedWith (
325
+ it ( 'uploadBytes throws' , async ( ) => {
326
+ await expect ( uploadBytes ( root , new Blob ( [ 'a' ] ) ) ) . to . be . rejectedWith (
313
327
'storage/invalid-root-operation'
314
328
) ;
315
329
} ) ;
0 commit comments