@@ -33,6 +33,13 @@ describe('$firebaseStorage', function () {
3333 expect ( storage ) . not . toBe ( null ) ;
3434 } ) ;
3535
36+ it ( 'should throw error given a non-reference' , ( ) => {
37+ function errorWrapper ( ) {
38+ var storage = $firebaseStorage ( null ) ;
39+ }
40+ expect ( errorWrapper ) . toThrow ( ) ;
41+ } ) ;
42+
3643 describe ( '$firebaseStorage.utils' , function ( ) {
3744
3845 describe ( '_unwrapStorageSnapshot' , function ( ) {
@@ -45,32 +52,74 @@ describe('$firebaseStorage', function () {
4552 ref : { } ,
4653 state : { } ,
4754 task : { } ,
48- totalBytes : 0
55+ totalBytes : 0 ,
56+ randomAttr : 'rando' , // gets removed
57+ anotherRando : 'woooo' // gets removed
4958 } ;
5059 var unwrapped = $firebaseStorage . utils . _unwrapStorageSnapshot ( mockSnapshot ) ;
51- expect ( mockSnapshot ) . toEqual ( unwrapped ) ;
60+ expect ( unwrapped ) . toEqual ( {
61+ bytesTransferred : 0 ,
62+ downloadURL : 'url' ,
63+ metadata : { } ,
64+ ref : { } ,
65+ state : { } ,
66+ task : { } ,
67+ totalBytes : 0
68+ } ) ;
69+ } ) ;
70+
71+ } ) ;
72+
73+ describe ( '_isStorageRef' , function ( ) {
74+
75+ it ( 'should determine a storage ref' , function ( ) {
76+ var ref = firebase . storage ( ) . ref ( 'thing' ) ;
77+ var isTrue = $firebaseStorage . utils . _isStorageRef ( ref ) ;
78+ var isFalse = $firebaseStorage . utils . _isStorageRef ( true ) ;
79+ expect ( isTrue ) . toEqual ( true ) ;
80+ expect ( isFalse ) . toEqual ( false ) ;
81+ } ) ;
82+
83+ } ) ;
84+
85+ describe ( '_assertStorageRef' , function ( ) {
86+ it ( 'should not throw an error if a storage ref is passed' , function ( ) {
87+ var ref = firebase . storage ( ) . ref ( 'thing' ) ;
88+ function errorWrapper ( ) {
89+ $firebaseStorage . utils . _assertStorageRef ( ref ) ;
90+ }
91+ expect ( errorWrapper ) . not . toThrow ( ) ;
5292 } ) ;
5393
94+ it ( 'should throw an error if a storage ref is passed' , function ( ) {
95+ function errorWrapper ( ) {
96+ $firebaseStorage . utils . _assertStorageRef ( null ) ;
97+ }
98+ expect ( errorWrapper ) . toThrow ( ) ;
99+ } ) ;
54100 } ) ;
55101
56- describe ( '_$put' , function ( ) {
102+ } ) ;
103+
104+ describe ( '$firebaseStorage' , function ( ) {
105+
106+ describe ( '$put' , function ( ) {
57107
58108 function setupPutTests ( file , mockTask ) {
59109 var ref = firebase . storage ( ) . ref ( 'thing' ) ;
60110 var task = null ;
61- var digestFn = $firebaseUtils . compile ;
111+ var storage = $firebaseStorage ( ref ) ;
62112 // If a MockTask is provided use it as the
63113 // return value of the spy on put
64114 if ( mockTask ) {
65115 spyOn ( ref , 'put' ) . and . returnValue ( mockTask ) ;
66116 } else {
67117 spyOn ( ref , 'put' ) ;
68118 }
69- task = $firebaseStorage . utils . _ $put( ref , file , digestFn ) ;
119+ task = storage . $put ( file ) ;
70120 return {
71121 ref : ref ,
72- task : task ,
73- digestFn : digestFn
122+ task : task
74123 } ;
75124 }
76125
@@ -152,57 +201,6 @@ describe('$firebaseStorage', function () {
152201
153202 } ) ;
154203
155- describe ( '_isStorageRef' , function ( ) {
156-
157- it ( 'should determine a storage ref' , function ( ) {
158- var ref = firebase . storage ( ) . ref ( 'thing' ) ;
159- var isTrue = $firebaseStorage . utils . _isStorageRef ( ref ) ;
160- var isFalse = $firebaseStorage . utils . _isStorageRef ( true ) ;
161- expect ( isTrue ) . toEqual ( true ) ;
162- expect ( isFalse ) . toEqual ( false ) ;
163- } ) ;
164-
165- } ) ;
166-
167- describe ( '_assertStorageRef' , function ( ) {
168- it ( 'should not throw an error if a storage ref is passed' , function ( ) {
169- var ref = firebase . storage ( ) . ref ( 'thing' ) ;
170- function errorWrapper ( ) {
171- $firebaseStorage . utils . _assertStorageRef ( ref ) ;
172- }
173- expect ( errorWrapper ) . not . toThrow ( ) ;
174- } ) ;
175-
176- it ( 'should throw an error if a storage ref is passed' , function ( ) {
177- function errorWrapper ( ) {
178- $firebaseStorage . utils . _assertStorageRef ( null ) ;
179- }
180- expect ( errorWrapper ) . toThrow ( ) ;
181- } ) ;
182- } ) ;
183-
184- } ) ;
185-
186- describe ( '$firebaseStorage' , function ( ) {
187-
188- describe ( '$put' , function ( ) {
189-
190- it ( 'should call the _$put method' , function ( ) {
191- // test that $firebaseStorage.utils._$put is called with
192- // - storageRef, file, $firebaseUtils.compile, $q
193- var ref = firebase . storage ( ) . ref ( 'thing' ) ;
194- var storage = $firebaseStorage ( ref ) ;
195- var fakePromise = $q ( function ( resolve , reject ) {
196- resolve ( 'file' ) ;
197- } ) ;
198- spyOn ( ref , 'put' ) ;
199- spyOn ( $firebaseStorage . utils , '_$put' ) . and . returnValue ( fakePromise ) ;
200- storage . $put ( 'file' ) ; // don't ever call this with a string IRL
201- expect ( $firebaseStorage . utils . _$put ) . toHaveBeenCalledWith ( ref , 'file' , $firebaseUtils . compile ) ;
202- } )
203-
204- } ) ;
205-
206204 describe ( '$getDownloadURL' , function ( ) {
207205 it ( 'should call the ref getDownloadURL method' , function ( ) {
208206 var ref = firebase . storage ( ) . ref ( 'thing' ) ;
@@ -215,12 +213,8 @@ describe('$firebaseStorage', function () {
215213
216214 describe ( '$delete' , function ( ) {
217215 it ( 'should call the storage ref delete method' , function ( ) {
218- // test that $firebaseStorage.$delete() calls storageRef.delete()
219216 var ref = firebase . storage ( ) . ref ( 'thing' ) ;
220217 var storage = $firebaseStorage ( ref ) ;
221- var fakePromise = $q ( function ( resolve , reject ) {
222- resolve ( ) ;
223- } ) ;
224218 spyOn ( ref , 'delete' ) ;
225219 storage . $delete ( ) ;
226220 expect ( ref . delete ) . toHaveBeenCalled ( ) ;
0 commit comments