Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/MongoTransform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,20 @@ describe('parseObjectToMongoObjectForCreate', () => {
done();
});

it('untransforms a null expiresAt to null, not epoch (#7576)', () => {
const output = transform.mongoObjectToParseObject('Document', { expiresAt: null }, {
fields: { expiresAt: { type: 'Date' } },
});
expect(output.expiresAt).toBeNull();
});

it('untransforms a null lastUsed to null, not epoch (#7576)', () => {
const output = transform.mongoObjectToParseObject('Document', { lastUsed: null }, {
fields: { lastUsed: { type: 'Date' } },
});
expect(output.lastUsed).toBeNull();
});

it('object with undefined nested values', () => {
const input = {
_id: 'vQHyinCW1l',
Expand Down
7 changes: 5 additions & 2 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,14 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
break;
case 'expiresAt':
case '_expiresAt':
restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key]));
// A cleared date is stored as null; keep it null instead of coercing to epoch (#7576)
restObject['expiresAt'] =
mongoObject[key] === null ? null : Parse._encode(new Date(mongoObject[key]));
break;
case 'lastUsed':
case '_last_used':
restObject['lastUsed'] = Parse._encode(new Date(mongoObject[key])).iso;
restObject['lastUsed'] =
mongoObject[key] === null ? null : Parse._encode(new Date(mongoObject[key])).iso;
break;
case 'timesUsed':
case 'times_used':
Expand Down
Loading