forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestQuery.spec.js
95 lines (90 loc) · 2.67 KB
/
RestQuery.spec.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
// These tests check the "find" functionality of the REST API.
var auth = require('../Auth');
var cache = require('../cache');
var Config = require('../Config');
var rest = require('../rest');
var config = new Config('test');
var nobody = auth.nobody(config);
describe('rest query', () => {
it('basic query', (done) => {
rest.create(config, nobody, 'TestObject', {}).then(() => {
return rest.find(config, nobody, 'TestObject', {});
}).then((response) => {
expect(response.results.length).toEqual(1);
done();
});
});
it('query with limit', (done) => {
rest.create(config, nobody, 'TestObject', {foo: 'baz'}
).then(() => {
return rest.create(config, nobody,
'TestObject', {foo: 'qux'});
}).then(() => {
return rest.find(config, nobody,
'TestObject', {}, {limit: 1});
}).then((response) => {
expect(response.results.length).toEqual(1);
expect(response.results[0].foo).toBeTruthy();
done();
});
});
// Created to test a scenario in AnyPic
it('query with include', (done) => {
var photo = {
foo: 'bar'
};
var user = {
username: 'aUsername',
password: 'aPassword'
};
var activity = {
type: 'comment',
photo: {
__type: 'Pointer',
className: 'TestPhoto',
objectId: ''
},
fromUser: {
__type: 'Pointer',
className: '_User',
objectId: ''
}
};
var queryWhere = {
photo: {
__type: 'Pointer',
className: 'TestPhoto',
objectId: ''
},
type: 'comment'
};
var queryOptions = {
include: 'fromUser',
order: 'createdAt',
limit: 30
};
rest.create(config, nobody, 'TestPhoto', photo
).then((p) => {
photo = p;
return rest.create(config, nobody, '_User', user);
}).then((u) => {
user = u.response;
activity.photo.objectId = photo.objectId;
activity.fromUser.objectId = user.objectId;
return rest.create(config, nobody,
'TestActivity', activity);
}).then(() => {
queryWhere.photo.objectId = photo.objectId;
return rest.find(config, nobody,
'TestActivity', queryWhere, queryOptions);
}).then((response) => {
var results = response.results;
expect(results.length).toEqual(1);
expect(typeof results[0].objectId).toEqual('string');
expect(typeof results[0].photo).toEqual('object');
expect(typeof results[0].fromUser).toEqual('object');
expect(typeof results[0].fromUser.username).toEqual('string');
done();
}).catch((error) => { console.log(error); });
});
});