-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRoles.test.ts
More file actions
122 lines (112 loc) · 3.45 KB
/
Copy pathRoles.test.ts
File metadata and controls
122 lines (112 loc) · 3.45 KB
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
/*
* Javascript tests for Triggers
*/
import { cb, platformUrl, mockRequest } from "./utils";
var roles: RoleAPI;
beforeEach(function () {
roles = cb.Roles();
});
describe("ClearBlade Roles", function () {
it("updates roles", function () {
var callNum = mockRequest.mock.calls.length;
var id = "fakeId";
var changes = {};
var body = {
id,
changes,
};
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "PUT",
body,
};
roles.update(id, changes, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("fetch roles by user", function () {
var callNum = mockRequest.mock.calls.length;
var id = "fakeId";
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "GET",
qs: "user=fakeId",
};
roles.fetch({ user: id }, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("fetch roles by device", function () {
var callNum = mockRequest.mock.calls.length;
var id = "fakeId";
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "GET",
qs: "device=fakeId",
};
roles.fetch({ device: id }, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("fetch roles by query", function () {
var callNum = mockRequest.mock.calls.length;
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "GET",
qs: "query=%7B%22FILTERS%22%3A%5B%5B%7B%22EQ%22%3A%5B%7B%22Name%22%3A%22Authenticated%22%7D%5D%7D%5D%5D%7D",
};
var query = cb.Query();
query.equalTo("Name", "Authenticated");
roles.fetch({ query }, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("delete role", function () {
var callNum = mockRequest.mock.calls.length;
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "DELETE",
qs: "role=blah",
};
roles.delete("blah", function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("create role", function () {
var callNum = mockRequest.mock.calls.length;
var theRole = {
name: "new",
description: "",
collections: [],
topics: [],
services: [],
servicecaches: [],
};
var expectedData = {
URI: platformUrl,
endpoint: "api/v/3/user/roles/fakeSystemKey",
method: "POST",
body: theRole,
};
roles.create(theRole, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
});