forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchema.spec.js
134 lines (126 loc) · 3.76 KB
/
Schema.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
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
126
127
128
129
130
131
132
133
134
// These tests check that the Schema operates correctly.
var Config = require('../Config');
var Schema = require('../Schema');
var config = new Config('test');
describe('Schema', () => {
it('can validate one object', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false});
}).then((schema) => {
done();
}, (error) => {
fail(error);
done();
});
});
it('can validate two objects in a row', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('Foo', {x: true, y: 'yyy', z: 0});
}).then((schema) => {
return schema.validateObject('Foo', {x: false, y: 'YY', z: 1});
}).then((schema) => {
done();
});
});
it('rejects inconsistent types', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('Stuff', {bacon: 7});
}).then((schema) => {
return schema.validateObject('Stuff', {bacon: 'z'});
}).then(() => {
fail('expected invalidity');
done();
}, done);
});
it('updates when new fields are added', (done) => {
config.database.loadSchema().then((schema) => {
return schema.validateObject('Stuff', {bacon: 7});
}).then((schema) => {
return schema.validateObject('Stuff', {sausage: 8});
}).then((schema) => {
return schema.validateObject('Stuff', {sausage: 'ate'});
}).then(() => {
fail('expected invalidity');
done();
}, done);
});
it('class-level permissions test find', (done) => {
config.database.loadSchema().then((schema) => {
// Just to create a valid class
return schema.validateObject('Stuff', {foo: 'bar'});
}).then((schema) => {
return schema.setPermissions('Stuff', {
'find': {}
});
}).then((schema) => {
var query = new Parse.Query('Stuff');
return query.find();
}).then((results) => {
fail('Class permissions should have rejected this query.');
done();
}, (e) => {
done();
});
});
it('class-level permissions test user', (done) => {
var user;
createTestUser().then((u) => {
user = u;
return config.database.loadSchema();
}).then((schema) => {
// Just to create a valid class
return schema.validateObject('Stuff', {foo: 'bar'});
}).then((schema) => {
var find = {};
find[user.id] = true;
return schema.setPermissions('Stuff', {
'find': find
});
}).then((schema) => {
var query = new Parse.Query('Stuff');
return query.find();
}).then((results) => {
done();
}, (e) => {
fail('Class permissions should have allowed this query.');
done();
});
});
it('class-level permissions test get', (done) => {
var user;
var obj;
createTestUser().then((u) => {
user = u;
return config.database.loadSchema();
}).then((schema) => {
// Just to create a valid class
return schema.validateObject('Stuff', {foo: 'bar'});
}).then((schema) => {
var find = {};
var get = {};
get[user.id] = true;
return schema.setPermissions('Stuff', {
'find': find,
'get': get
});
}).then((schema) => {
obj = new Parse.Object('Stuff');
obj.set('foo', 'bar');
return obj.save();
}).then((o) => {
obj = o;
var query = new Parse.Query('Stuff');
return query.find();
}).then((results) => {
fail('Class permissions should have rejected this query.');
done();
}, (e) => {
var query = new Parse.Query('Stuff');
return query.get(obj.id).then((o) => {
done();
}, (e) => {
fail('Class permissions should have allowed this get query');
});
});
});
});