Merge pull request #587 from ParsePlatform/nlutsenko.cc.test
Do not pass objectId, updatedAt, createdAt to beforeSave hooks on object create.
This commit is contained in:
@@ -390,15 +390,19 @@ describe('miscellaneous', function() {
|
|||||||
var object = req.object;
|
var object = req.object;
|
||||||
expect(object instanceof Parse.Object).toBeTruthy();
|
expect(object instanceof Parse.Object).toBeTruthy();
|
||||||
expect(object.get('fooAgain')).toEqual('barAgain');
|
expect(object.get('fooAgain')).toEqual('barAgain');
|
||||||
expect(object.id).not.toBeUndefined();
|
|
||||||
expect(object.createdAt).not.toBeUndefined();
|
|
||||||
expect(object.updatedAt).not.toBeUndefined();
|
|
||||||
if (triggerTime == 0) {
|
if (triggerTime == 0) {
|
||||||
// Create
|
// Create
|
||||||
expect(object.get('foo')).toEqual('bar');
|
expect(object.get('foo')).toEqual('bar');
|
||||||
|
// No objectId/createdAt/updatedAt
|
||||||
|
expect(object.id).toBeUndefined();
|
||||||
|
expect(object.createdAt).toBeUndefined();
|
||||||
|
expect(object.updatedAt).toBeUndefined();
|
||||||
} else if (triggerTime == 1) {
|
} else if (triggerTime == 1) {
|
||||||
// Update
|
// Update
|
||||||
expect(object.get('foo')).toEqual('baz');
|
expect(object.get('foo')).toEqual('baz');
|
||||||
|
expect(object.id).not.toBeUndefined();
|
||||||
|
expect(object.createdAt).not.toBeUndefined();
|
||||||
|
expect(object.updatedAt).not.toBeUndefined();
|
||||||
} else {
|
} else {
|
||||||
res.error();
|
res.error();
|
||||||
}
|
}
|
||||||
@@ -431,10 +435,10 @@ describe('miscellaneous', function() {
|
|||||||
Parse.Cloud.afterSave('GameScore', function(req, res) {
|
Parse.Cloud.afterSave('GameScore', function(req, res) {
|
||||||
var object = req.object;
|
var object = req.object;
|
||||||
expect(object instanceof Parse.Object).toBeTruthy();
|
expect(object instanceof Parse.Object).toBeTruthy();
|
||||||
expect(object.get('fooAgain')).toEqual('barAgain');
|
|
||||||
expect(object.id).not.toBeUndefined();
|
expect(object.id).not.toBeUndefined();
|
||||||
expect(object.createdAt).not.toBeUndefined();
|
expect(object.createdAt).not.toBeUndefined();
|
||||||
expect(object.updatedAt).not.toBeUndefined();
|
expect(object.updatedAt).not.toBeUndefined();
|
||||||
|
expect(object.get('fooAgain')).toEqual('barAgain');
|
||||||
if (triggerTime == 0) {
|
if (triggerTime == 0) {
|
||||||
// Create
|
// Create
|
||||||
expect(object.get('foo')).toEqual('bar');
|
expect(object.get('foo')).toEqual('bar');
|
||||||
@@ -474,17 +478,21 @@ describe('miscellaneous', function() {
|
|||||||
var object = req.object;
|
var object = req.object;
|
||||||
expect(object instanceof Parse.Object).toBeTruthy();
|
expect(object instanceof Parse.Object).toBeTruthy();
|
||||||
expect(object.get('fooAgain')).toEqual('barAgain');
|
expect(object.get('fooAgain')).toEqual('barAgain');
|
||||||
expect(object.id).not.toBeUndefined();
|
|
||||||
expect(object.createdAt).not.toBeUndefined();
|
|
||||||
expect(object.updatedAt).not.toBeUndefined();
|
|
||||||
var originalObject = req.original;
|
var originalObject = req.original;
|
||||||
if (triggerTime == 0) {
|
if (triggerTime == 0) {
|
||||||
|
// No id/createdAt/updatedAt
|
||||||
|
expect(object.id).toBeUndefined();
|
||||||
|
expect(object.createdAt).toBeUndefined();
|
||||||
|
expect(object.updatedAt).toBeUndefined();
|
||||||
// Create
|
// Create
|
||||||
expect(object.get('foo')).toEqual('bar');
|
expect(object.get('foo')).toEqual('bar');
|
||||||
// Check the originalObject is undefined
|
// Check the originalObject is undefined
|
||||||
expect(originalObject).toBeUndefined();
|
expect(originalObject).toBeUndefined();
|
||||||
} else if (triggerTime == 1) {
|
} else if (triggerTime == 1) {
|
||||||
// Update
|
// Update
|
||||||
|
expect(object.id).not.toBeUndefined();
|
||||||
|
expect(object.createdAt).not.toBeUndefined();
|
||||||
|
expect(object.updatedAt).not.toBeUndefined();
|
||||||
expect(object.get('foo')).toEqual('baz');
|
expect(object.get('foo')).toEqual('baz');
|
||||||
// Check the originalObject
|
// Check the originalObject
|
||||||
expect(originalObject instanceof Parse.Object).toBeTruthy();
|
expect(originalObject instanceof Parse.Object).toBeTruthy();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var ParseServer = require('../src/index').ParseServer;
|
|||||||
var DatabaseAdapter = require('../src/DatabaseAdapter');
|
var DatabaseAdapter = require('../src/DatabaseAdapter');
|
||||||
|
|
||||||
var databaseURI = process.env.DATABASE_URI;
|
var databaseURI = process.env.DATABASE_URI;
|
||||||
var cloudMain = process.env.CLOUD_CODE_MAIN || './cloud/main.js';
|
var cloudMain = process.env.CLOUD_CODE_MAIN || '../spec/cloud/main.js';
|
||||||
var port = 8378;
|
var port = 8378;
|
||||||
|
|
||||||
// Default server configuration for tests.
|
// Default server configuration for tests.
|
||||||
|
|||||||
@@ -50,15 +50,6 @@ function RestWrite(config, auth, className, query, data, originalData) {
|
|||||||
|
|
||||||
// The timestamp we'll use for this whole operation
|
// The timestamp we'll use for this whole operation
|
||||||
this.updatedAt = Parse._encode(new Date()).iso;
|
this.updatedAt = Parse._encode(new Date()).iso;
|
||||||
|
|
||||||
if (this.data) {
|
|
||||||
// Add default fields
|
|
||||||
this.data.updatedAt = this.updatedAt;
|
|
||||||
if (!this.query) {
|
|
||||||
this.data.createdAt = this.updatedAt;
|
|
||||||
this.data.objectId = cryptoUtils.newObjectId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A convenient method to perform all the steps of processing the
|
// A convenient method to perform all the steps of processing the
|
||||||
@@ -76,6 +67,8 @@ RestWrite.prototype.execute = function() {
|
|||||||
return this.handleSession();
|
return this.handleSession();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return this.runBeforeTrigger();
|
return this.runBeforeTrigger();
|
||||||
|
}).then(() => {
|
||||||
|
return this.setRequiredFieldsIfNeeded();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return this.validateAuthData();
|
return this.validateAuthData();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
@@ -99,7 +92,7 @@ RestWrite.prototype.getUserAndRoleACL = function() {
|
|||||||
|
|
||||||
this.runOptions.acl = ['*'];
|
this.runOptions.acl = ['*'];
|
||||||
|
|
||||||
if( this.auth.user ){
|
if (this.auth.user) {
|
||||||
return this.auth.getUserRoles().then((roles) => {
|
return this.auth.getUserRoles().then((roles) => {
|
||||||
roles.push(this.auth.user.id);
|
roles.push(this.auth.user.id);
|
||||||
this.runOptions.acl = this.runOptions.acl.concat(roles);
|
this.runOptions.acl = this.runOptions.acl.concat(roles);
|
||||||
@@ -146,6 +139,18 @@ RestWrite.prototype.runBeforeTrigger = function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RestWrite.prototype.setRequiredFieldsIfNeeded = function() {
|
||||||
|
if (this.data) {
|
||||||
|
// Add default fields
|
||||||
|
this.data.updatedAt = this.updatedAt;
|
||||||
|
if (!this.query) {
|
||||||
|
this.data.createdAt = this.updatedAt;
|
||||||
|
this.data.objectId = cryptoUtils.newObjectId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
// Transforms auth data for a user object.
|
// Transforms auth data for a user object.
|
||||||
// Does nothing if this isn't a user object.
|
// Does nothing if this isn't a user object.
|
||||||
// Returns a promise for when we're done if it can't finish this tick.
|
// Returns a promise for when we're done if it can't finish this tick.
|
||||||
|
|||||||
Reference in New Issue
Block a user