forked from ClearBlade/JavaScript-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearBlade.test.ts
More file actions
144 lines (132 loc) · 4.46 KB
/
ClearBlade.test.ts
File metadata and controls
144 lines (132 loc) · 4.46 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { cb } from "./utils";
describe("ClearBlade initialization should", function() {
beforeEach(function() {
var initOptions = {
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret"
};
cb.init(initOptions);
});
it("have the systemKey stored", function() {
expect(cb.systemKey).toEqual("fakeSystemKey");
});
it("have the systemSecret stored", function() {
expect(cb.systemSecret).toEqual("fakeSystemSecret");
});
it("have defaulted the URI to the Platform", function() {
expect(cb.URI).toEqual("https://platform.clearblade.com");
});
it("have defaulted the logging to false", function() {
expect(cb.logging).toEqual(false);
});
it("have defaulted the callTimeout to 30000", function() {
expect(cb._callTimeout).toEqual(30000);
});
});
describe("ClearBlade user setup", function() {
beforeEach(function() {
var initOptions = {
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret"
};
cb.init(initOptions);
});
it("should register a new user correctly", function() {
var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later
cb.registerUser("[email protected]", "testPass", function(err, data) {});
var expectedData = {
method: "POST",
endpoint: "api/v/1/user/reg",
useUser: true,
user: {
email: "[email protected]",
authToken: undefined
},
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
authToken: undefined,
timeout: 30000,
URI: "https://platform.clearblade.com",
body: {
email: "[email protected]",
password: "testPass"
}
};
// expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData);
expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData);
});
it("should login as anon", function() {
var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later
cb.loginAnon(function(err, data) {});
var expectedData = {
method: "POST",
endpoint: "api/v/1/user/anon",
useUser: false,
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
timeout: 30000,
URI: "https://platform.clearblade.com"
};
expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData);
});
it("should login as user", function() {
var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later
var initOptions = {
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
email: "[email protected]",
password: "testPass"
};
cb.init(initOptions);
var expectedData = {
method: "POST",
endpoint: "api/v/1/user/auth",
useUser: false,
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
timeout: 30000,
URI: "https://platform.clearblade.com",
body: {
email: "[email protected]",
password: "testPass"
}
};
expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData);
});
it("should check to see if the user is authed", function() {
cb.setUser("[email protected]", "testUserToken");
var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later
cb.isCurrentUserAuthenticated(function(err, data) {});
var expectedData = {
method: "POST",
endpoint: "api/v/1/user/checkauth",
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
timeout: 30000,
URI: "https://platform.clearblade.com",
user: {
email: "[email protected]",
authToken: "testUserToken"
}
};
expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData);
});
it("should log out user", function() {
cb.setUser("[email protected]", "testUserToken");
var callNum = ClearBlade.request.mock.calls.length; // we get the call count so we can grab the right call later
cb.logoutUser(function(err, data) {});
var expectedData = {
method: "POST",
endpoint: "api/v/1/user/logout",
systemKey: "fakeSystemKey",
systemSecret: "fakeSystemSecret",
timeout: 30000,
URI: "https://platform.clearblade.com",
user: {
email: "[email protected]",
authToken: "testUserToken"
}
};
expect(ClearBlade.request.mock.calls[callNum][0]).toEqual(expectedData);
});
});