forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseCloudTest.js
125 lines (111 loc) · 3.74 KB
/
ParseCloudTest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
const assert = require('assert');
const clear = require('./clear');
const Parse = require('../../node');
describe('Parse Cloud', () => {
beforeAll((done) => {
Parse.initialize('integration', null, 'notsosecret');
Parse.CoreManager.set('SERVER_URL', 'http://localhost:1337/parse');
Parse.Storage._clear();
clear().then(() => { done() }, () => { done() });
});
it('run function', (done) => {
const params = { key1: 'value2', key2: 'value1' };
Parse.Cloud.run('bar', params).then((result) => {
assert.equal('Foo', result);
done();
}).catch(done.fail);
});
it('run function with user', (done) => {
const params = { key1: 'value2', key2: 'value1' };
const user = new Parse.User();
user.setUsername('someuser');
user.setPassword('somepassword');
user.signUp().then(() => {
return Parse.Cloud.run('bar', params);
}).then((resp) => {
assert.equal('Foo', resp);
return user.destroy({ useMasterKey: true });
}).then(() => {
done();
}).catch(done.fail);
});
it('run function failed', (done) => {
const params = { key1: 'value1', key2: 'value2' };
Parse.Cloud.run('bar', params).then(done.fail).catch((error) => {
assert.equal(error.code, Parse.Error.SCRIPT_FAILED);
done();
});
});
it('run function name fail', (done) => {
const params = { key1: 'value1' };
Parse.Cloud.run('unknown_function', params).then(done.fail).catch((error) => {
assert.equal(error.message, 'Invalid function: "unknown_function"');
done();
});
});
it('run function with geopoint params does not fail', (done) => {
const params = { key1: new Parse.GeoPoint(50, 50) };
Parse.Cloud.run('unknown_function', params).then(null).catch((error) => {
assert.equal(error.message, 'Invalid function: "unknown_function"');
done();
});
});
it('run function with object params fail', (done) => {
const object = new Parse.Object('TestClass');
const params = { key1: object };
try {
Parse.Cloud.run('bar', params);
} catch (e) {
assert.equal(e, 'Error: Parse Objects not allowed here');
done();
}
});
it('run job', (done) => {
const params = { startedBy: 'Monty Python' };
Parse.Cloud.startJob('CloudJob1', params).then((jobStatusId) => {
return Parse.Cloud.getJobStatus(jobStatusId);
}).then((jobStatus) => {
assert.equal(jobStatus.get('status'), 'succeeded');
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
done();
});
});
it('run long job', (done) => {
Parse.Cloud.startJob('CloudJob2').then((jobStatusId) => {
return Parse.Cloud.getJobStatus(jobStatusId);
}).then((jobStatus) => {
assert.equal(jobStatus.get('status'), 'running');
done();
});
});
it('run bad job', (done) => {
Parse.Cloud.startJob('bad_job').then(null).catch((error) => {
assert.equal(error.code, Parse.Error.SCRIPT_FAILED);
assert.equal(error.message, 'Invalid job.');
done();
});
});
it('run failing job', (done) => {
Parse.Cloud.startJob('CloudJobFailing').then((jobStatusId) => {
return Parse.Cloud.getJobStatus(jobStatusId);
}).then((jobStatus) => {
assert.equal(jobStatus.get('status'), 'failed');
assert.equal(jobStatus.get('message'), 'cloud job failed');
done();
});
});
it('get jobs data', (done) => {
Parse.Cloud.getJobsData().then((result) => {
assert.equal(result.in_use.length, 0);
assert.equal(result.jobs.length, 3);
done();
});
});
it('invalid job status id', (done) => {
Parse.Cloud.getJobStatus('not-a-real-id').then(null).catch((error) => {
assert.equal(error.message, 'Object not found.');
done();
});
});
});