Skip to content

Commit

Permalink
fix: throws when fetching object without id (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd authored Mar 17, 2021
1 parent ead0d9d commit ef4cc3e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ module.exports = function(AV) {
* completes.
*/
fetch(fetchOptions, options) {
if (!this.id) {
throw new Error('Cannot fetch unsaved file');
}
var request = AVRequest(
'files',
null,
Expand Down
3 changes: 3 additions & 0 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,9 @@ module.exports = function(AV) {
* completes.
*/
fetch: function(fetchOptions = {}, options) {
if (!this.id) {
throw new Error('Cannot fetch unsaved object');
}
var self = this;
var request = _request(
'classes',
Expand Down
4 changes: 4 additions & 0 deletions test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ describe('File', function() {
.fetch()
.then(file => (this.file = file));
});
it('should throws when objectId is empty', () => {
const file = new AV.File('filename', { base64: 'dGVzdA==' });
expect(file.fetch).throwError();
});
it('should retrieve all data', function() {
var file = this.file;
expect(file).to.be.a(AV.File);
Expand Down
4 changes: 4 additions & 0 deletions test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ describe('Objects', function() {
expect(score.createdAt).to.be.a(Date);
expect(score.id).to.be.eql(gameScore.id);
}));
it('should throws when objectId is empty', () => {
const object = new AV.Object('GameScore');
expect(object.fetch).throwError();
});
it('fetch should remove deleted keys', () => {
const getFakedScore = () =>
AV.parseJSON(
Expand Down

0 comments on commit ef4cc3e

Please sign in to comment.