-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathmain.js
70 lines (61 loc) · 1.97 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* global Parse */
Parse.Cloud.define("bar", function(request) {
if (request.params.key2 === "value1") {
return 'Foo';
} else {
throw "bad stuff happened";
}
});
Parse.Cloud.define('TestFetchFromLocalDatastore', function (request) {
const object = new Parse.Object('Item');
object.id = request.params.id;
object.set('foo', 'changed');
return object.save();
});
Parse.Cloud.define('UpdateUser', function (request) {
const user = new Parse.User();
user.id = request.params.id;
user.set('foo', 'changed');
return user.save(null, { useMasterKey: true });
});
Parse.Cloud.define('CloudFunctionIdempotency', function () {
const object = new Parse.Object('IdempotencyItem');
return object.save(null, { useMasterKey: true });
});
Parse.Cloud.define('CloudFunctionUndefined', function() {
return undefined;
});
Parse.Cloud.job('CloudJob1', function() {
return {
status: 'cloud job completed'
};
});
Parse.Cloud.job('CloudJob2', function() {
return new Promise((resolve) => {
setTimeout(function() {
resolve({
status: 'cloud job completed'
})
}, 1000);
});
});
Parse.Cloud.job('CloudJobFailing', function() {
throw 'cloud job failed';
});
//ugly patch. Should not stay here, but I don't know how to test changes in Cloud Code otherwise
//parse-server uses the published parse SDK version, but we want to test the patched version via cloud code
const PatchedParse = require('../../node').Parse;
//FunctionsRouter.js 104 calls Parse._encode directly, so it must be patched.
Parse._encode = PatchedParse._encode;
//Parse.Object calls encode, so it must be patched.
Parse.Object = PatchedParse.Object;
Parse.Cloud.define('getUnsavedObject', function(){
const parent = new Parse.Object("Unsaved");
const child = new Parse.Object("secondUnsaved");
const childOfChild = new Parse.Object("thirdUnsaved");
child.set("foz", "baz");
child.set("child", childOfChild);
parent.set("foo", "bar");
parent.set("child", child);
return parent;
});