forked from ClearBlade/JavaScript-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearBladeSpec.js
More file actions
152 lines (137 loc) · 4.51 KB
/
ClearBladeSpec.js
File metadata and controls
152 lines (137 loc) · 4.51 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
145
146
147
148
149
150
151
152
/**
* This is the Jasmine testing file for the ClearBlade javascript API
*/
var cb;
beforeEach(function() {
spyOn(ClearBlade, 'request').and.callFake(function (options, callback) {
callback(null, {fake: "data", DATA: []});
});
cb = new ClearBlade();
});
function TestRequest(requester, expectedRequest) {
}
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.calls.count(); // we get the call count so we can grab the right call later
var expectedData = {
method: 'POST',
endpoint: 'api/v/1/user/reg',
useUser: false,
systemKey: 'fakeSystemKey',
systemSecret: 'fakeSystemSecret',
timeout: 30000,
URI: 'https://platform.clearblade.com',
body: {
password: 'testPass'
}
};
expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData);
});
it('should login as anon', function () {
var callNum = ClearBlade.request.calls.count(); // 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.calls.argsFor(callNum)[0]).toEqual(expectedData);
});
it('should login as user', function () {
var callNum = ClearBlade.request.calls.count(); // we get the call count so we can grab the right call later
var initOptions = {
systemKey: 'fakeSystemKey',
systemSecret: 'fakeSystemSecret',
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: {
password: 'testPass'
}
};
expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData);
});
it('should check to see if the user is authed', function () {
var callNum = ClearBlade.request.calls.count(); // 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: {
authToken: 'testUserToken'
}
};
expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData);
});
it('should log out user', function () {
var callNum = ClearBlade.request.calls.count(); // 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: {
authToken: 'testUserToken'
}
};
expect(ClearBlade.request.calls.argsFor(callNum)[0]).toEqual(expectedData);
});
});