@@ -20,193 +20,195 @@ import { ReferenceCompat } from '../../src/reference';
20
20
import { StorageServiceCompat } from '../../src/service' ;
21
21
import { makeTestCompatStorage , fakeApp , fakeStorage } from '../utils' ;
22
22
import firebase from '@firebase/app-compat' ;
23
- import { StorageReference , getStorage , FirebaseStorage } from '@firebase/storage' ;
23
+ import {
24
+ StorageReference ,
25
+ getStorage ,
26
+ FirebaseStorage
27
+ } from '@firebase/storage' ;
24
28
import { fake } from 'sinon' ;
25
29
import { FirebaseApp } from '@firebase/app-types' ;
26
30
import { Reference } from '@firebase/storage-types' ;
27
31
28
32
describe ( 'Firebase Storage > Reference' , ( ) => {
29
- let testCompatApp : FirebaseApp ;
30
- let testModularStorage : FirebaseStorage ;
31
- let service : StorageServiceCompat ;
32
- before ( ( ) => {
33
- testCompatApp = firebase . initializeApp ( { } ) ;
34
- testModularStorage = getStorage ( testCompatApp ) ;
35
- service = makeTestCompatStorage ( testCompatApp , testModularStorage ) ;
36
- } ) ;
33
+ let testCompatApp : FirebaseApp ;
34
+ let testModularStorage : FirebaseStorage ;
35
+ let service : StorageServiceCompat ;
36
+ before ( ( ) => {
37
+ testCompatApp = firebase . initializeApp ( { } ) ;
38
+ testModularStorage = getStorage ( testCompatApp ) ;
39
+ service = makeTestCompatStorage ( testCompatApp , testModularStorage ) ;
40
+ } ) ;
37
41
38
- after ( ( ) => {
39
- return testCompatApp . delete ( ) ;
40
- } ) ;
41
- describe ( 'toString' , ( ) => {
42
- it ( "delegates to the modular Reference.toString()" , ( ) => {
43
- const fakeToString = fake . returns ( 'test123' ) ;
44
- const ref = new ReferenceCompat ( {
45
- toString : fakeToString
46
- } as unknown as StorageReference , makeTestCompatStorage ( fakeApp , fakeStorage ) ) ;
42
+ after ( ( ) => {
43
+ return testCompatApp . delete ( ) ;
44
+ } ) ;
45
+ describe ( 'toString' , ( ) => {
46
+ it ( 'delegates to the modular Reference.toString()' , ( ) => {
47
+ const fakeToString = fake . returns ( 'test123' ) ;
48
+ const ref = new ReferenceCompat (
49
+ {
50
+ toString : fakeToString
51
+ } as unknown as StorageReference ,
52
+ makeTestCompatStorage ( fakeApp , fakeStorage )
53
+ ) ;
47
54
48
- expect ( ref . toString ( ) ) . to . equal ( 'test123' ) ;
49
- expect ( fakeToString ) . to . have . been . calledOnceWithExactly ( ) ;
50
- } ) ;
55
+ expect ( ref . toString ( ) ) . to . equal ( 'test123' ) ;
56
+ expect ( fakeToString ) . to . have . been . calledOnceWithExactly ( ) ;
51
57
} ) ;
58
+ } ) ;
52
59
53
- describe ( 'parent' , ( ) => {
54
- it ( 'Returns null at root' , ( ) => {
55
- const root = service . refFromURL ( 'gs://test-bucket' ) ;
56
- expect ( root . parent ) . to . be . null ;
57
- } ) ;
58
- it ( 'Returns root one level down' , ( ) => {
59
- const child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
60
- expect ( child . parent ! . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
61
- } ) ;
62
- it ( 'Works correctly with empty levels' , ( ) => {
63
- const s = service . refFromURL ( 'gs://test-bucket/a///' ) ;
64
- expect ( s . parent ! . toString ( ) ) . to . equal ( 'gs://test-bucket/a/' ) ;
65
- } ) ;
60
+ describe ( 'parent' , ( ) => {
61
+ it ( 'Returns null at root' , ( ) => {
62
+ const root = service . refFromURL ( 'gs://test-bucket' ) ;
63
+ expect ( root . parent ) . to . be . null ;
64
+ } ) ;
65
+ it ( 'Returns root one level down' , ( ) => {
66
+ const child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
67
+ expect ( child . parent ! . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
66
68
} ) ;
69
+ it ( 'Works correctly with empty levels' , ( ) => {
70
+ const s = service . refFromURL ( 'gs://test-bucket/a///' ) ;
71
+ expect ( s . parent ! . toString ( ) ) . to . equal ( 'gs://test-bucket/a/' ) ;
72
+ } ) ;
73
+ } ) ;
67
74
68
- describe ( 'root' , ( ) => {
69
- it ( 'Returns self at root' , ( ) => {
70
- const root = service . refFromURL ( 'gs://test-bucket' ) ;
71
- expect ( root . root . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
72
- } ) ;
75
+ describe ( 'root' , ( ) => {
76
+ it ( 'Returns self at root' , ( ) => {
77
+ const root = service . refFromURL ( 'gs://test-bucket' ) ;
78
+ expect ( root . root . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
79
+ } ) ;
73
80
74
- it ( 'Returns root multiple levels down' , ( ) => {
75
- const s = service . refFromURL ( 'gs://test-bucket/a/b/c/d' ) ;
76
- expect ( s . root . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
77
- } ) ;
81
+ it ( 'Returns root multiple levels down' , ( ) => {
82
+ const s = service . refFromURL ( 'gs://test-bucket/a/b/c/d' ) ;
83
+ expect ( s . root . toString ( ) ) . to . equal ( 'gs://test-bucket/' ) ;
78
84
} ) ;
85
+ } ) ;
79
86
80
- describe ( 'bucket' , ( ) => {
81
- it ( 'Returns bucket name' , ( ) => {
82
- const root = service . refFromURL ( 'gs://test-bucket' ) ;
83
- expect ( root . bucket ) . to . equal ( 'test-bucket' ) ;
84
- } ) ;
87
+ describe ( 'bucket' , ( ) => {
88
+ it ( 'Returns bucket name' , ( ) => {
89
+ const root = service . refFromURL ( 'gs://test-bucket' ) ;
90
+ expect ( root . bucket ) . to . equal ( 'test-bucket' ) ;
85
91
} ) ;
92
+ } ) ;
86
93
87
- describe ( 'fullPath' , ( ) => {
88
- it ( 'Returns full path without leading slash' , ( ) => {
89
- const s = service . refFromURL ( 'gs://test-bucket/full/path' ) ;
90
- expect ( s . fullPath ) . to . equal ( 'full/path' ) ;
91
- } ) ;
94
+ describe ( 'fullPath' , ( ) => {
95
+ it ( 'Returns full path without leading slash' , ( ) => {
96
+ const s = service . refFromURL ( 'gs://test-bucket/full/path' ) ;
97
+ expect ( s . fullPath ) . to . equal ( 'full/path' ) ;
92
98
} ) ;
99
+ } ) ;
93
100
94
- describe ( 'name' , ( ) => {
95
- it ( 'Works at top level' , ( ) => {
96
- const s = service . refFromURL ( 'gs://test-bucket/toplevel.txt' ) ;
97
- expect ( s . name ) . to . equal ( 'toplevel.txt' ) ;
98
- } ) ;
101
+ describe ( 'name' , ( ) => {
102
+ it ( 'Works at top level' , ( ) => {
103
+ const s = service . refFromURL ( 'gs://test-bucket/toplevel.txt' ) ;
104
+ expect ( s . name ) . to . equal ( 'toplevel.txt' ) ;
105
+ } ) ;
99
106
100
- it ( 'Works at not the top level' , ( ) => {
101
- const s = service . refFromURL ( 'gs://test-bucket/not/toplevel.txt' ) ;
102
- expect ( 'toplevel.txt' ) . to . equal ( s . name ) ;
103
- } ) ;
107
+ it ( 'Works at not the top level' , ( ) => {
108
+ const s = service . refFromURL ( 'gs://test-bucket/not/toplevel.txt' ) ;
109
+ expect ( 'toplevel.txt' ) . to . equal ( s . name ) ;
104
110
} ) ;
111
+ } ) ;
105
112
106
- describe ( 'child' , ( ) => {
107
- let root : Reference ;
108
- before ( ( ) => {
109
- root = service . refFromURL ( 'gs://test-bucket' ) ;
110
- } ) ;
111
- it ( 'works with a simple string' , ( ) => {
112
- expect ( root . child ( 'a' ) . toString ( ) ) . to . equal ( 'gs://test-bucket/a' ) ;
113
- } ) ;
114
- it ( 'drops a trailing slash' , ( ) => {
115
- expect ( root . child ( 'ab/' ) . toString ( ) ) . to . equal ( 'gs://test-bucket/ab' ) ;
116
- } ) ;
117
- it ( 'compresses repeated slashes' , ( ) => {
118
- expect ( root . child ( '//a///b/////' ) . toString ( ) ) . to . equal (
119
- 'gs://test-bucket/a/b'
120
- ) ;
121
- } ) ;
122
- it ( 'works chained multiple times with leading slashes' , ( ) => {
123
- expect (
124
- root . child ( 'a' ) . child ( '/b' ) . child ( 'c' ) . child ( 'd/e' ) . toString ( )
125
- ) . to . equal ( 'gs://test-bucket/a/b/c/d/e' ) ;
126
- } ) ;
113
+ describe ( 'child' , ( ) => {
114
+ let root : Reference ;
115
+ before ( ( ) => {
116
+ root = service . refFromURL ( 'gs://test-bucket' ) ;
117
+ } ) ;
118
+ it ( 'works with a simple string' , ( ) => {
119
+ expect ( root . child ( 'a' ) . toString ( ) ) . to . equal ( 'gs://test-bucket/a' ) ;
120
+ } ) ;
121
+ it ( 'drops a trailing slash' , ( ) => {
122
+ expect ( root . child ( 'ab/' ) . toString ( ) ) . to . equal ( 'gs://test-bucket/ab' ) ;
123
+ } ) ;
124
+ it ( 'compresses repeated slashes' , ( ) => {
125
+ expect ( root . child ( '//a///b/////' ) . toString ( ) ) . to . equal (
126
+ 'gs://test-bucket/a/b'
127
+ ) ;
128
+ } ) ;
129
+ it ( 'works chained multiple times with leading slashes' , ( ) => {
130
+ expect (
131
+ root . child ( 'a' ) . child ( '/b' ) . child ( 'c' ) . child ( 'd/e' ) . toString ( )
132
+ ) . to . equal ( 'gs://test-bucket/a/b/c/d/e' ) ;
127
133
} ) ;
134
+ } ) ;
128
135
129
- describe ( 'putString' , ( ) => {
130
- let child : Reference ;
131
- before ( ( ) => {
132
- child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
133
- } ) ;
134
- it ( 'Uses metadata.contentType for RAW format' , ( ) => {
135
- // Regression test for b/30989476
136
- const task = child . putString ( 'hello' , 'raw' , {
137
- contentType : 'lol/wut'
138
- } ) ;
139
- expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'lol/wut' ) ;
140
- task . cancel ( ) ;
141
- } ) ;
142
- it ( 'Uses embedded content type in DATA_URL format' , ( ) => {
143
- const task = child . putString (
144
- 'data:lol/wat;base64,aaaa' ,
145
- 'data_url'
146
- ) ;
147
- expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'lol/wat' ) ;
148
- task . cancel ( ) ;
149
- } ) ;
150
- it ( 'Lets metadata.contentType override embedded content type in DATA_URL format' , ( ) => {
151
- const task = child . putString (
152
- 'data:ignore/me;base64,aaaa' ,
153
- 'data_url' ,
154
- { contentType : 'tomato/soup' }
155
- ) ;
156
- expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'tomato/soup' ) ;
157
- task . cancel ( ) ;
158
- } ) ;
136
+ describe ( 'putString' , ( ) => {
137
+ let child : Reference ;
138
+ before ( ( ) => {
139
+ child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
140
+ } ) ;
141
+ it ( 'Uses metadata.contentType for RAW format' , ( ) => {
142
+ // Regression test for b/30989476
143
+ const task = child . putString ( 'hello' , 'raw' , {
144
+ contentType : 'lol/wut'
145
+ } ) ;
146
+ expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'lol/wut' ) ;
147
+ task . cancel ( ) ;
148
+ } ) ;
149
+ it ( 'Uses embedded content type in DATA_URL format' , ( ) => {
150
+ const task = child . putString ( 'data:lol/wat;base64,aaaa' , 'data_url' ) ;
151
+ expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'lol/wat' ) ;
152
+ task . cancel ( ) ;
159
153
} ) ;
154
+ it ( 'Lets metadata.contentType override embedded content type in DATA_URL format' , ( ) => {
155
+ const task = child . putString ( 'data:ignore/me;base64,aaaa' , 'data_url' , {
156
+ contentType : 'tomato/soup'
157
+ } ) ;
158
+ expect ( task . snapshot . metadata ! . contentType ) . to . equal ( 'tomato/soup' ) ;
159
+ task . cancel ( ) ;
160
+ } ) ;
161
+ } ) ;
160
162
161
- describe ( 'Argument verification' , ( ) => {
162
- describe ( 'list' , ( ) => {
163
- it ( 'throws on invalid maxResults' , async ( ) => {
164
- const child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
165
- await expect ( child . list ( { maxResults : 0 } ) ) . to . be . rejectedWith (
166
- 'storage/invalid-argument'
167
- ) ;
168
- await expect ( child . list ( { maxResults : - 4 } ) ) . to . be . rejectedWith (
169
- 'storage/invalid-argument'
170
- ) ;
171
- await expect ( child . list ( { maxResults : 1001 } ) ) . to . be . rejectedWith (
172
- 'storage/invalid-argument'
173
- ) ;
174
- } ) ;
175
- } ) ;
163
+ describe ( 'Argument verification' , ( ) => {
164
+ describe ( 'list' , ( ) => {
165
+ it ( 'throws on invalid maxResults' , async ( ) => {
166
+ const child = service . refFromURL ( 'gs://test-bucket/hello' ) ;
167
+ await expect ( child . list ( { maxResults : 0 } ) ) . to . be . rejectedWith (
168
+ 'storage/invalid-argument'
169
+ ) ;
170
+ await expect ( child . list ( { maxResults : - 4 } ) ) . to . be . rejectedWith (
171
+ 'storage/invalid-argument'
172
+ ) ;
173
+ await expect ( child . list ( { maxResults : 1001 } ) ) . to . be . rejectedWith (
174
+ 'storage/invalid-argument'
175
+ ) ;
176
+ } ) ;
176
177
} ) ;
178
+ } ) ;
177
179
178
- describe ( 'root operations' , ( ) => {
179
- let root : Reference ;
180
- before ( ( ) => {
181
- root = service . refFromURL ( 'gs://test-bucket' ) ;
182
- } ) ;
183
- it ( 'put throws' , ( ) => {
184
- expect ( ( ) => root . put ( new Uint8Array ( ) ) ) . to . throw (
185
- 'storage/invalid-root-operation'
186
- ) ;
187
- } ) ;
188
- it ( 'putString throws' , ( ) => {
189
- expect ( ( ) => root . putString ( 'raw' , 'raw' ) ) . to . throw (
190
- 'storage/invalid-root-operation'
191
- ) ;
192
- } ) ;
193
- it ( 'delete throws' , ( ) => {
194
- expect ( ( ) => root . delete ( ) ) . to . throw ( 'storage/invalid-root-operation' ) ;
195
- } ) ;
196
- it ( 'getMetadata throws' , async ( ) => {
197
- await expect ( root . getMetadata ( ) ) . to . be . rejectedWith (
198
- 'storage/invalid-root-operation'
199
- ) ;
200
- } ) ;
201
- it ( 'updateMetadata throws' , async ( ) => {
202
- await expect ( root . updateMetadata ( { } ) ) . to . be . rejectedWith (
203
- 'storage/invalid-root-operation'
204
- ) ;
205
- } ) ;
206
- it ( 'getDownloadURL throws' , async ( ) => {
207
- await expect ( root . getDownloadURL ( ) ) . to . be . rejectedWith (
208
- 'storage/invalid-root-operation'
209
- ) ;
210
- } ) ;
180
+ describe ( 'root operations' , ( ) => {
181
+ let root : Reference ;
182
+ before ( ( ) => {
183
+ root = service . refFromURL ( 'gs://test-bucket' ) ;
184
+ } ) ;
185
+ it ( 'put throws' , ( ) => {
186
+ expect ( ( ) => root . put ( new Uint8Array ( ) ) ) . to . throw (
187
+ 'storage/invalid-root-operation'
188
+ ) ;
189
+ } ) ;
190
+ it ( 'putString throws' , ( ) => {
191
+ expect ( ( ) => root . putString ( 'raw' , 'raw' ) ) . to . throw (
192
+ 'storage/invalid-root-operation'
193
+ ) ;
194
+ } ) ;
195
+ it ( 'delete throws' , ( ) => {
196
+ expect ( ( ) => root . delete ( ) ) . to . throw ( 'storage/invalid-root-operation' ) ;
197
+ } ) ;
198
+ it ( 'getMetadata throws' , async ( ) => {
199
+ await expect ( root . getMetadata ( ) ) . to . be . rejectedWith (
200
+ 'storage/invalid-root-operation'
201
+ ) ;
202
+ } ) ;
203
+ it ( 'updateMetadata throws' , async ( ) => {
204
+ await expect ( root . updateMetadata ( { } ) ) . to . be . rejectedWith (
205
+ 'storage/invalid-root-operation'
206
+ ) ;
207
+ } ) ;
208
+ it ( 'getDownloadURL throws' , async ( ) => {
209
+ await expect ( root . getDownloadURL ( ) ) . to . be . rejectedWith (
210
+ 'storage/invalid-root-operation'
211
+ ) ;
211
212
} ) ;
213
+ } ) ;
212
214
} ) ;
0 commit comments