Skip to content

Adds Hooks API #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2016
Merged
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ node_modules
# WebStorm/IntelliJ
.idea

# visual studio code
.vscode

# Babel.js
lib/

# cache folder
.cache
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ The standalone Parse Server can be configured using [environment variables](#con

Please refer to the [configuration section](#configuration) or help;

To get more help for running the parse-server standalone, you can run:

`$ npm start -- --help`

The standalone API server supports loading a configuration file in JSON format:

`$ npm start -- path/to/your/config.json`

The default port is 1337, to use a different port set the `--port` option:

`$ npm start -- --port=8080 path/to/your/config.json`

Please refer to the [configuration section](#configuration) or help;

You can also install Parse Server globally:

`$ npm install -g parse-server`
Expand Down
2 changes: 1 addition & 1 deletion spec/HTTPRequest.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var httpRequest = require("../src/httpRequest"),
var httpRequest = require("../src/cloud-code/httpRequest"),
bodyParser = require('body-parser'),
express = require("express");

Expand Down
6 changes: 5 additions & 1 deletion spec/ParseACL.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ describe('Parse.ACL', () => {
equal(results.length, 1);
var result = results[0];
ok(result);
equal(result.id, object.id);
if (!result) {
fail("should have result");
} else {
equal(result.id, object.id);
}
done();
}
});
Expand Down
44 changes: 28 additions & 16 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ describe('miscellaneous', function() {
var objAgain = new Parse.Object('BeforeDeleteFail', {objectId: id});
return objAgain.fetch();
}).then((objAgain) => {
expect(objAgain.get('foo')).toEqual('bar');
if (objAgain) {
expect(objAgain.get('foo')).toEqual('bar');
} else {
fail("unable to fetch the object ", id);
}
done();
}, (error) => {
// We should have been able to fetch the object again
Expand Down Expand Up @@ -351,6 +355,11 @@ describe('miscellaneous', function() {
it('test cloud function return types', function(done) {
Parse.Cloud.run('foo').then((result) => {
expect(result.object instanceof Parse.Object).toBeTruthy();
if (!result.object) {
fail("Unable to run foo");
done();
return;
}
expect(result.object.className).toEqual('Foo');
expect(result.object.get('x')).toEqual(2);
var bar = result.object.get('relation');
Expand Down Expand Up @@ -381,23 +390,25 @@ describe('miscellaneous', function() {
expect(results.length).toEqual(1);
expect(results[0]['foo']).toEqual('bar');
done();
});
}).fail( err => {
fail(err);
done();
})
});

describe('beforeSave', () => {
beforeEach(done => {
// Make sure the required mock for all tests is unset.
delete Parse.Cloud.Triggers.beforeSave.GameScore;
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
done();
});

afterEach(done => {
// Make sure the required mock for all tests is unset.
delete Parse.Cloud.Triggers.beforeSave.GameScore;
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
done();
});

it('object is set on create and update', done => {
});
it('object is set on create and update', done => {
let triggerTime = 0;
// Register a mock beforeSave hook
Parse.Cloud.beforeSave('GameScore', (req, res) => {
Expand Down Expand Up @@ -610,8 +621,8 @@ describe('miscellaneous', function() {
}).then(function() {
// Make sure the checking has been triggered
expect(triggerTime).toBe(2);
// Clear mock afterSave
delete Parse.Cloud.Triggers.afterSave.GameScore;
// Clear mock beforeSave
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
done();
}, function(error) {
fail(error);
Expand Down Expand Up @@ -663,9 +674,10 @@ describe('miscellaneous', function() {
// Make sure the checking has been triggered
expect(triggerTime).toBe(2);
// Clear mock afterSave
delete Parse.Cloud.Triggers.afterSave.GameScore;
Parse.Cloud._removeHook("Triggers", "afterSave", "GameScore");
done();
}, function(error) {
console.error(error);
fail(error);
done();
});
Expand All @@ -678,12 +690,12 @@ describe('miscellaneous', function() {
});
Parse.Cloud.run('willFail').then((s) => {
fail('Should not have succeeded.');
delete Parse.Cloud.Functions['willFail'];
Parse.Cloud._removeHook("Functions", "willFail");
done();
}, (e) => {
expect(e.code).toEqual(141);
expect(e.message).toEqual('noway');
delete Parse.Cloud.Functions['willFail'];
Parse.Cloud._removeHook("Functions", "willFail");
done();
});
});
Expand Down Expand Up @@ -712,7 +724,7 @@ describe('miscellaneous', function() {
// Make sure query string params override body params
expect(res.other).toEqual('2');
expect(res.foo).toEqual("bar");
delete Parse.Cloud.Functions['echoParams'];
Parse.Cloud._removeHook("Functions",'echoParams');
done();
});
});
Expand All @@ -726,7 +738,7 @@ describe('miscellaneous', function() {
});

Parse.Cloud.run('functionWithParameterValidation', {"success":100}).then((s) => {
delete Parse.Cloud.Functions['functionWithParameterValidation'];
Parse.Cloud._removeHook("Functions", "functionWithParameterValidation");
done();
}, (e) => {
fail('Validation should not have failed.');
Expand All @@ -744,7 +756,7 @@ describe('miscellaneous', function() {

Parse.Cloud.run('functionWithParameterValidationFailure', {"success":500}).then((s) => {
fail('Validation should not have succeeded');
delete Parse.Cloud.Functions['functionWithParameterValidationFailure'];
Parse.Cloud._removeHook("Functions", "functionWithParameterValidationFailure");
done();
}, (e) => {
expect(e.code).toEqual(141);
Expand Down
Loading