@@ -123,7 +123,7 @@ describe('File', function() {
123123 } ) ;
124124 } ) ;
125125
126- describe ( 'Fetch ' , function ( ) {
126+ describe ( '#fetch ' , function ( ) {
127127 var fileId = '52f9dd5ae4b019816c865985' ;
128128 it ( 'createWithoutData() should return a File' , function ( ) {
129129 var file = AV . File . createWithoutData ( fileId ) ;
@@ -136,16 +136,32 @@ describe('File', function() {
136136 file . save ( ) ;
137137 } ) . to . throwError ( / F i l e a l r e a d y s a v e d \. / ) ;
138138 } ) ;
139- it ( 'fetch() should retrieve all data' , function ( ) {
140- var file = AV . File . createWithoutData ( fileId ) ;
141- return file . fetch ( ) . then ( function ( file ) {
139+ describe ( 'fetch' , ( ) => {
140+ before ( function ( ) {
141+ return AV . File . createWithoutData ( fileId )
142+ . fetch ( )
143+ . then ( file => this . file = file ) ;
144+ } )
145+ it ( 'should retrieve all data' , function ( ) {
146+ var file = this . file ;
142147 expect ( file ) . to . be . a ( AV . File ) ;
143148 expect ( file . id ) . to . be ( fileId ) ;
144149 expect ( file . name ( ) ) . to . be ( 'myfile.txt' ) ;
145150 expect ( file . get ( 'mime_type' ) ) . to . be ( 'text/plain' ) ;
146151 expect ( typeof file . url ( ) ) . to . be ( 'string' ) ;
147152 } ) ;
148- } ) ;
153+ it ( 'decode and encode' , function ( ) {
154+ const json = this . file . toJSON ( ) ;
155+ // backward compatible check
156+ json . should . have . properties ( [ '__type' , 'id' , 'name' , 'url' ] ) ;
157+ const file = AV . _decode ( json ) ;
158+ expect ( file ) . to . be . a ( AV . File ) ;
159+ expect ( file . id ) . to . be ( fileId ) ;
160+ expect ( file . name ( ) ) . to . be ( 'myfile.txt' ) ;
161+ expect ( file . get ( 'mime_type' ) ) . to . be ( 'text/plain' ) ;
162+ expect ( typeof file . url ( ) ) . to . be ( 'string' ) ;
163+ } ) ;
164+ } )
149165 } ) ;
150166
151167 describe ( 'File get and set' , function ( ) {
0 commit comments