forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseRole-test.js
83 lines (73 loc) · 2.34 KB
/
ParseRole-test.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
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
jest.dontMock('../CoreManager');
jest.dontMock('../decode');
jest.dontMock('../ObjectStateMutations');
jest.dontMock('../ParseError');
jest.dontMock('../ParseObject');
jest.dontMock('../ParseOp');
jest.dontMock('../ParseRole');
jest.dontMock('../SingleInstanceStateController');
jest.dontMock('../UniqueInstanceStateController');
const ParseACL = require('../ParseACL');
const ParseError = require('../ParseError');
const ParseObject = require('../ParseObject');
const ParseRole = require('../ParseRole');
describe('ParseRole', () => {
beforeEach(() => {
ParseObject.disableSingleInstance();
});
it('can create Roles', () => {
var role = new ParseRole();
expect(role.getName()).toBe(undefined);
expect(role.getACL()).toBe(null);
var acl = new ParseACL({ aUserId: { read: true, write: true } });
role = new ParseRole('admin', acl);
expect(role.getName()).toBe('admin');
expect(role.getACL()).toBe(acl);
});
it('can validate attributes', () => {
var acl = new ParseACL({ aUserId: { read: true, write: true } });
var role = new ParseRole('admin', acl);
role.id = '101';
expect(role.validate({
name: 'author'
})).toEqual(new ParseError(
ParseError.OTHER_CAUSE,
'A role\'s name can only be set before it has been saved.'
));
role.id = undefined;
expect(role.validate({
name: 12
})).toEqual(new ParseError(
ParseError.OTHER_CAUSE,
'A role\'s name must be a String.'
));
expect(role.validate({
name: '$$$'
})).toEqual(new ParseError(
ParseError.OTHER_CAUSE,
'A role\'s name can be only contain alphanumeric characters, _, ' +
'-, and spaces.'
));
expect(role.validate({
name: 'admin'
})).toBe(false);
});
it('can be constructed from JSON', () => {
var role = ParseObject.fromJSON({
className: '_Role',
objectId: '102',
name: 'admin'
});
expect(role instanceof ParseObject).toBe(true);
expect(role instanceof ParseRole).toBe(true);
expect(role.getName()).toBe('admin');
});
});