Skip to content

Commit 1bcf59d

Browse files
authored
fix(User): ensure _mergeMagicFields returns data (#493)
1 parent 1f74896 commit 1bcf59d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ module.exports = function(AV) {
10331033
output[key] = AV._parseDate(output[key]);
10341034
}
10351035
});
1036-
if (!output.updatedAt) {
1036+
if (output.createdAt && !output.updatedAt) {
10371037
output.updatedAt = output.createdAt;
10381038
}
10391039
return output;

src/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = function(AV) {
4747
this._sessionToken = attrs.sessionToken;
4848
delete attrs.sessionToken;
4949
}
50-
AV.User.__super__._mergeMagicFields.call(this, attrs);
50+
return AV.User.__super__._mergeMagicFields.call(this, attrs);
5151
},
5252

5353
/**

test/object.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ describe('Objects', function(){
107107
parsedGameScore.get('score').should.eql(gameScore.get('score'));
108108
});
109109

110+
it('toJSON and parse (User)', () => {
111+
const user = new AV.Object.createWithoutData('_User', 'objectId');
112+
user.set('id', 'id');
113+
user.set('score', 20);
114+
const json = user.toJSON();
115+
json.objectId.should.eql(user.id);
116+
json.score.should.eql(user.get('score'));
117+
const parsedUser = new AV.User(json, { parse: true });
118+
parsedUser.id.should.eql(user.id);
119+
parsedUser.get('id').should.eql(user.get('id'));
120+
parsedUser.get('score').should.eql(user.get('score'));
121+
});
122+
110123
it('toJSON for nested objects', () => {
111124
const id = 'fakeObjectId';
112125
const a = AV.Object.createWithoutData('A', id, true);

0 commit comments

Comments
 (0)