Skip to content

Commit e5b1d50

Browse files
committed
Merge pull request #500 from flovilmart/hooks-API
Adds Hooks API
2 parents a7262da + 3c61415 commit e5b1d50

26 files changed

+1163
-149
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ node_modules
3232
# WebStorm/IntelliJ
3333
.idea
3434

35+
# visual studio code
36+
.vscode
37+
3538
# Babel.js
3639
lib/
40+
41+
# cache folder
42+
.cache

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ The standalone Parse Server can be configured using [environment variables](#con
6767

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

70+
To get more help for running the parse-server standalone, you can run:
71+
72+
`$ npm start -- --help`
73+
74+
The standalone API server supports loading a configuration file in JSON format:
75+
76+
`$ npm start -- path/to/your/config.json`
77+
78+
The default port is 1337, to use a different port set the `--port` option:
79+
80+
`$ npm start -- --port=8080 path/to/your/config.json`
81+
82+
Please refer to the [configuration section](#configuration) or help;
83+
7084
You can also install Parse Server globally:
7185

7286
`$ npm install -g parse-server`

spec/HTTPRequest.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var httpRequest = require("../src/httpRequest"),
1+
var httpRequest = require("../src/cloud-code/httpRequest"),
22
bodyParser = require('body-parser'),
33
express = require("express");
44

spec/ParseACL.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ describe('Parse.ACL', () => {
786786
equal(results.length, 1);
787787
var result = results[0];
788788
ok(result);
789-
equal(result.id, object.id);
789+
if (!result) {
790+
fail("should have result");
791+
} else {
792+
equal(result.id, object.id);
793+
}
790794
done();
791795
}
792796
});

spec/ParseAPI.spec.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ describe('miscellaneous', function() {
275275
var objAgain = new Parse.Object('BeforeDeleteFail', {objectId: id});
276276
return objAgain.fetch();
277277
}).then((objAgain) => {
278-
expect(objAgain.get('foo')).toEqual('bar');
278+
if (objAgain) {
279+
expect(objAgain.get('foo')).toEqual('bar');
280+
} else {
281+
fail("unable to fetch the object ", id);
282+
}
279283
done();
280284
}, (error) => {
281285
// We should have been able to fetch the object again
@@ -351,6 +355,11 @@ describe('miscellaneous', function() {
351355
it('test cloud function return types', function(done) {
352356
Parse.Cloud.run('foo').then((result) => {
353357
expect(result.object instanceof Parse.Object).toBeTruthy();
358+
if (!result.object) {
359+
fail("Unable to run foo");
360+
done();
361+
return;
362+
}
354363
expect(result.object.className).toEqual('Foo');
355364
expect(result.object.get('x')).toEqual(2);
356365
var bar = result.object.get('relation');
@@ -381,23 +390,25 @@ describe('miscellaneous', function() {
381390
expect(results.length).toEqual(1);
382391
expect(results[0]['foo']).toEqual('bar');
383392
done();
384-
});
393+
}).fail( err => {
394+
fail(err);
395+
done();
396+
})
385397
});
386398

387399
describe('beforeSave', () => {
388400
beforeEach(done => {
389401
// Make sure the required mock for all tests is unset.
390-
delete Parse.Cloud.Triggers.beforeSave.GameScore;
402+
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
391403
done();
392404
});
393-
394405
afterEach(done => {
395406
// Make sure the required mock for all tests is unset.
396-
delete Parse.Cloud.Triggers.beforeSave.GameScore;
407+
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
397408
done();
398-
});
399-
400-
it('object is set on create and update', done => {
409+
});
410+
411+
it('object is set on create and update', done => {
401412
let triggerTime = 0;
402413
// Register a mock beforeSave hook
403414
Parse.Cloud.beforeSave('GameScore', (req, res) => {
@@ -610,8 +621,8 @@ describe('miscellaneous', function() {
610621
}).then(function() {
611622
// Make sure the checking has been triggered
612623
expect(triggerTime).toBe(2);
613-
// Clear mock afterSave
614-
delete Parse.Cloud.Triggers.afterSave.GameScore;
624+
// Clear mock beforeSave
625+
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
615626
done();
616627
}, function(error) {
617628
fail(error);
@@ -663,9 +674,10 @@ describe('miscellaneous', function() {
663674
// Make sure the checking has been triggered
664675
expect(triggerTime).toBe(2);
665676
// Clear mock afterSave
666-
delete Parse.Cloud.Triggers.afterSave.GameScore;
677+
Parse.Cloud._removeHook("Triggers", "afterSave", "GameScore");
667678
done();
668679
}, function(error) {
680+
console.error(error);
669681
fail(error);
670682
done();
671683
});
@@ -678,12 +690,12 @@ describe('miscellaneous', function() {
678690
});
679691
Parse.Cloud.run('willFail').then((s) => {
680692
fail('Should not have succeeded.');
681-
delete Parse.Cloud.Functions['willFail'];
693+
Parse.Cloud._removeHook("Functions", "willFail");
682694
done();
683695
}, (e) => {
684696
expect(e.code).toEqual(141);
685697
expect(e.message).toEqual('noway');
686-
delete Parse.Cloud.Functions['willFail'];
698+
Parse.Cloud._removeHook("Functions", "willFail");
687699
done();
688700
});
689701
});
@@ -712,7 +724,7 @@ describe('miscellaneous', function() {
712724
// Make sure query string params override body params
713725
expect(res.other).toEqual('2');
714726
expect(res.foo).toEqual("bar");
715-
delete Parse.Cloud.Functions['echoParams'];
727+
Parse.Cloud._removeHook("Functions",'echoParams');
716728
done();
717729
});
718730
});
@@ -726,7 +738,7 @@ describe('miscellaneous', function() {
726738
});
727739

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

745757
Parse.Cloud.run('functionWithParameterValidationFailure', {"success":500}).then((s) => {
746758
fail('Validation should not have succeeded');
747-
delete Parse.Cloud.Functions['functionWithParameterValidationFailure'];
759+
Parse.Cloud._removeHook("Functions", "functionWithParameterValidationFailure");
748760
done();
749761
}, (e) => {
750762
expect(e.code).toEqual(141);

0 commit comments

Comments
 (0)