File tree Expand file tree Collapse file tree 4 files changed +14
-0
lines changed
Expand file tree Collapse file tree 4 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -619,6 +619,9 @@ module.exports = function(AV) {
619619 * completes.
620620 */
621621 fetch ( fetchOptions , options ) {
622+ if ( ! this . id ) {
623+ throw new Error ( 'Cannot fetch unsaved file' ) ;
624+ }
622625 var request = AVRequest (
623626 'files' ,
624627 null ,
Original file line number Diff line number Diff line change @@ -946,6 +946,9 @@ module.exports = function(AV) {
946946 * completes.
947947 */
948948 fetch : function ( fetchOptions = { } , options ) {
949+ if ( ! this . id ) {
950+ throw new Error ( 'Cannot fetch unsaved object' ) ;
951+ }
949952 var self = this ;
950953 var request = _request (
951954 'classes' ,
Original file line number Diff line number Diff line change @@ -188,6 +188,10 @@ describe('File', function() {
188188 . fetch ( )
189189 . then ( file => ( this . file = file ) ) ;
190190 } ) ;
191+ it ( 'should throws when objectId is empty' , ( ) => {
192+ const file = new AV . File ( 'filename' , { base64 : 'dGVzdA==' } ) ;
193+ expect ( file . fetch ) . throwError ( ) ;
194+ } ) ;
191195 it ( 'should retrieve all data' , function ( ) {
192196 var file = this . file ;
193197 expect ( file ) . to . be . a ( AV . File ) ;
Original file line number Diff line number Diff line change @@ -447,6 +447,10 @@ describe('Objects', function() {
447447 expect ( score . createdAt ) . to . be . a ( Date ) ;
448448 expect ( score . id ) . to . be . eql ( gameScore . id ) ;
449449 } ) ) ;
450+ it ( 'should throws when objectId is empty' , ( ) => {
451+ const object = new AV . Object ( 'GameScore' ) ;
452+ expect ( object . fetch ) . throwError ( ) ;
453+ } ) ;
450454 it ( 'fetch should remove deleted keys' , ( ) => {
451455 const getFakedScore = ( ) =>
452456 AV . parseJSON (
You can’t perform that action at this time.
0 commit comments