@@ -78,56 +78,48 @@ describe('files', function() {
7878
7979
8080 describe ( 'Saving array' , function ( ) {
81- it ( 'should be saved' , function ( done ) {
82- setTimeout ( function ( ) {
83- var bytes = [ 0xBE , 0xEF , 0xCA , 0xFE ] ;
81+ it ( 'should be saved' , function ( ) {
82+ var bytes = [ 108 , 101 , 97 , 110 , 99 , 108 , 111 , 117 , 100 ] ;
8483 var file = new AV . File ( 'myfile.txt' , bytes ) ;
85- file . save ( ) . then ( function ( ) {
86- expect ( file . size ( ) ) . to . be ( 4 ) ;
84+ return file . save ( ) . then ( function ( ) {
85+ expect ( file . size ( ) ) . to . be ( 9 ) ;
8786 expect ( file . ownerId ( ) ) . to . be . ok ( ) ;
8887 expect ( file . id ) . to . be . ok ( ) ;
89- file . destroy ( ) . then ( function ( ) {
90- done ( ) ;
91- } , function ( error ) {
92- done ( error ) ;
88+ return new AV . Promise ( function ( resolve , reject ) {
89+ request ( file . url ( ) ) . end ( function ( err , res ) {
90+ if ( err ) {
91+ return reject ( err ) ;
92+ }
93+ resolve ( res ) ;
94+ } ) ;
9395 } ) ;
94- } , function ( error ) {
95- done ( error ) ;
96+ } ) . then ( function ( res ) {
97+ expect ( res . text ) . to . be ( 'leancloud' ) ;
98+ return file . destroy ( ) ;
9699 } ) ;
97- } , 1000 ) ;
98100 } ) ;
99101 } ) ;
100102
101103 describe ( 'Saving file with object' , function ( ) {
102- it ( 'should be saved' , function ( done ) {
103- var bytes = [ 0xBE , 0xEF , 0xCA , 0xFE ] ;
104+ it ( 'should be saved' , function ( ) {
105+ var bytes = [ 108 , 101 , 97 , 110 , 99 , 108 , 111 , 117 , 100 ] ;
104106 var file = new AV . File ( 'myfile.txt' , bytes ) ;
105- file . save ( ) . then ( function ( ) {
107+ return file . save ( ) . then ( function ( ) {
106108 var jobApplication = new AV . Object ( 'JobApplication' ) ;
107109 jobApplication . set ( 'applicantName' , 'Joe Smith' ) ;
108110 jobApplication . set ( 'applicantResumeFile' , file ) ;
109- jobApplication . save ( ) . then ( function ( result ) {
111+ return jobApplication . save ( ) . then ( function ( result ) {
110112 expect ( result . id ) . to . be . ok ( ) ;
111113 var query = new AV . Query ( 'JobApplication' ) ;
112- query . get ( result . id ) . then ( function ( ja ) {
114+ return query . get ( result . id ) . then ( function ( ja ) {
113115 expect ( ja . id ) . to . be . ok ( ) ;
114116 var arf = ja . get ( 'applicantResumeFile' ) ;
115117 expect ( arf ) . to . be . ok ( ) ;
116- expect ( arf . size ( ) ) . to . be ( 4 ) ;
118+ expect ( arf . size ( ) ) . to . be ( 9 ) ;
117119 expect ( arf . ownerId ( ) ) . to . be . ok ( ) ;
118- file . destroy ( ) . then ( function ( ) {
119- done ( ) ;
120- } , function ( error ) {
121- done ( error ) ;
122- } ) ;
123- } ) . catch ( function ( error ) {
124- done ( error ) ;
120+ return file . destroy ( ) ;
125121 } ) ;
126- } , function ( obj , error ) {
127- done ( error ) ;
128122 } ) ;
129- } , function ( error ) {
130- done ( error ) ;
131123 } ) ;
132124 } ) ;
133125 } ) ;
0 commit comments