Skip to content

Commit b93dc00

Browse files
committed
Separated out configuration so can switch between rtp and platform targets easily
1 parent 853a86e commit b93dc00

1 file changed

Lines changed: 78 additions & 31 deletions

File tree

test/ClearBladeSpec.js

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@
77
* password: testPass
88
*/
99

10+
var TEST_TIMEOUT = 30000;
11+
var RTP_INFO = {
12+
serverAddress: "https://rtp.clearblade.com",
13+
appKey: "c899bfae0afca9b1c899c2fe841d",
14+
appSecret: "C899BFAE0ACAE5A3C2A086ECDCF801",
15+
safariCollection: "aaaabfae0ad0da86f2dde3bba761",
16+
chromeCollection: "949abfae0aae8aaeffb09f80f8c101",
17+
generalCollection: "b69abfae0ad28bceb1dba4eecb19",
18+
firefoxCollection: "a49abfae0ac8e987e699def0e4e301"
19+
};
20+
var PLATFORM_INFO = {
21+
serverAddress: "https://platform.clearblade.com",
22+
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
23+
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801',
24+
safariCollection: "82f7f8aa0ab8929ab1c3cad7e534",
25+
chromeCollection:"84f6f8aa0abcf9fbb6ae97a6c9da01",
26+
firefoxCollection:"d8f6f8aa0ababdbbc5b8fdf49356",
27+
generalCollection:'90f6f8aa0a86969ced80c0a8b03e'
28+
}
29+
var TargetPlatform = RTP_INFO;
30+
1031
describe("ClearBlade API", function () {
1132
it("should return the correct API version", function () {
1233
var APIversion = ClearBlade.getApiVersion();
@@ -18,18 +39,19 @@ describe("ClearBlade API", function () {
1839
describe("ClearBlade initialization should", function () {
1940
beforeEach(function () {
2041
var initOptions = {
21-
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
22-
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801'
42+
appKey: TargetPlatform.appKey,
43+
appSecret: TargetPlatform.appSecret,
44+
URI: TargetPlatform.serverAddress
2345
};
2446
ClearBlade.init(initOptions);
2547
});
2648

2749
it("have the appKey stored", function () {
28-
expect(ClearBlade.appKey).toEqual('f2f5f8aa0aba8bc7e4bdcd8ef142');
50+
expect(ClearBlade.appKey).toEqual(TargetPlatform.appKey);
2951
});
3052

3153
it("have the appSecret stored", function () {
32-
expect(ClearBlade.appSecret).toEqual('F2F5F8AA0AB4F2C4A4E1C387F3F801');
54+
expect(ClearBlade.appSecret).toEqual(TargetPlatform.appSecret);
3355
});
3456

3557
// it("have defaulted the URI to the Platform", function () {
@@ -48,20 +70,42 @@ describe("ClearBlade initialization should", function () {
4870
expect(ClearBlade._callTimeout).toEqual(30000);
4971
});
5072
});
73+
describe("ClearBlade users should", function () {
74+
var initOptions;
75+
beforeEach(function () {
76+
initOptions = {
77+
appKey: TargetPlatform.appKey,
78+
appSecret: TargetPlatform.appSecret,
79+
URI: TargetPlatform.serverAddress
80+
};
81+
});
82+
it("have anonymous user authenticated when no options given", function () {
83+
var authenticated = false;
84+
initOptions.onSuccess = function() {
85+
authenticated = true;
86+
expect(ClearBlade.user).toBeDefined();
87+
};
88+
ClearBlade.init(initOptions)
89+
waitsFor(function() {
90+
return authenticated;
91+
}, "user should be defined", TEST_TIMEOUT);
92+
});
93+
});
5194

5295
describe("ClearBlade collections fetching", function () {
5396
var col;
5497
beforeEach(function () {
5598
var initOptions = {
56-
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
57-
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801'
99+
appKey: TargetPlatform.appKey,
100+
appSecret: TargetPlatform.appSecret,
101+
URI: TargetPlatform.serverAddress
58102
};
59103
ClearBlade.init(initOptions);
60-
col = new ClearBlade.Collection('90f6f8aa0a86969ced80c0a8b03e');
104+
col = new ClearBlade.Collection(TargetPlatform.generalCollection);
61105
});
62106

63107
it("should have the collectionID stored", function () {
64-
expect(col.ID).toEqual('90f6f8aa0a86969ced80c0a8b03e');
108+
expect(col.ID).toEqual(TargetPlatform.generalCollection);
65109
});
66110

67111
it("should return the stuff I entered before", function () {
@@ -81,7 +125,7 @@ describe("ClearBlade collections fetching", function () {
81125

82126
waitsFor(function () {
83127
return flag;
84-
}, "returnedData should not be undefined", 30000);
128+
}, "returnedData should not be undefined", TEST_TIMEOUT);
85129

86130
runs(function () {
87131
expect(returnedData[0].data.name).toEqual('aaron');
@@ -91,17 +135,18 @@ describe("ClearBlade collections fetching", function () {
91135
describe("ClearBlade collections CRUD should", function () {
92136
var collection, col;
93137
if(window.navigator.userAgent.indexOf("Firefox") > 0) {
94-
collection = "d8f6f8aa0ababdbbc5b8fdf49356";
138+
collection = TargetPlatform.firefoxCollection;
95139
} else if(window.navigator.userAgent.indexOf("Chrome") > 0) {
96-
collection = "84f6f8aa0abcf9fbb6ae97a6c9da01";
140+
collection = TargetPlatform.chromeCollection;
97141
} else if(window.navigator.userAgent.indexOf("Safari") > 0){
98-
collection = "82f7f8aa0ab8929ab1c3cad7e534";
142+
collection = TargetPlatform.safariCollection;
99143
}
100144

101145
beforeEach(function () {
102146
var initOptions = {
103-
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
104-
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801'
147+
appKey: TargetPlatform.appKey,
148+
appSecret: TargetPlatform.appSecret,
149+
URI: TargetPlatform.serverAddress
105150
};
106151
ClearBlade.init(initOptions);
107152
col = new ClearBlade.Collection(collection);
@@ -129,7 +174,7 @@ describe("ClearBlade collections CRUD should", function () {
129174

130175
waitsFor(function () {
131176
return flag;
132-
}, "returnedData should not be undefined", 30000);
177+
}, "returnedData should not be undefined", TEST_TIMEOUT);
133178

134179
runs(function () {
135180
secondFlag = false;
@@ -145,7 +190,7 @@ describe("ClearBlade collections CRUD should", function () {
145190

146191
waitsFor(function () {
147192
return secondFlag;
148-
}, "returnedData should not be undefined", 30000);
193+
}, "returnedData should not be undefined", TEST_TIMEOUT);
149194

150195
runs(function () {
151196
expect(returnedData[0].data.name).toEqual('jim');
@@ -174,7 +219,7 @@ describe("ClearBlade collections CRUD should", function () {
174219

175220
waitsFor(function () {
176221
return flag;
177-
}, "returnedData should not be undefined", 30000);
222+
}, "returnedData should not be undefined", TEST_TIMEOUT);
178223

179224
runs(function () {
180225
secondFlag = false;
@@ -190,7 +235,7 @@ describe("ClearBlade collections CRUD should", function () {
190235

191236
waitsFor(function () {
192237
return secondFlag;
193-
}, "returnedData should not be undefined", 30000);
238+
}, "returnedData should not be undefined", TEST_TIMEOUT);
194239

195240
runs(function () {
196241
expect(returnedData[0].data.name).toEqual('john');
@@ -214,7 +259,7 @@ describe("ClearBlade collections CRUD should", function () {
214259

215260
waitsFor(function () {
216261
return flag;
217-
}, "returnedData should not be undefined", 30000);
262+
}, "returnedData should not be undefined", TEST_TIMEOUT);
218263

219264
runs(function () {
220265
secondFlag = false;
@@ -227,7 +272,7 @@ describe("ClearBlade collections CRUD should", function () {
227272

228273
waitsFor(function () {
229274
return secondFlag;
230-
}, "returnedData should not be undefined", 30000);
275+
}, "returnedData should not be undefined", TEST_TIMEOUT);
231276

232277
runs(function () {
233278
expect(returnedData).toEqual([]);
@@ -240,16 +285,17 @@ describe("Query objects should", function () {
240285
beforeEach(function () {
241286
var isJohnInserted = false;
242287
var initOptions = {
243-
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
244-
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801'
288+
appKey: TargetPlatform.appKey,
289+
appSecret: TargetPlatform.appSecret,
290+
URI: TargetPlatform.serverAddress
245291
};
246292
ClearBlade.init(initOptions);
247293
if(window.navigator.userAgent.indexOf("Firefox") > 0) {
248-
collection = "d8f6f8aa0ababdbbc5b8fdf49356";
294+
collection = TargetPlatform.firefoxCollection;
249295
} else if(window.navigator.userAgent.indexOf("Chrome") > 0) {
250-
collection = "84f6f8aa0abcf9fbb6ae97a6c9da01";
296+
collection = TargetPlatform.chromeCollection;
251297
} else if(window.navigator.userAgent.indexOf("Safari") > 0){
252-
collection = "82f7f8aa0ab8929ab1c3cad7e534";
298+
collection = TargetPlatform.safariCollection;
253299
}
254300
col = new ClearBlade.Collection(collection);
255301
var newItem = {
@@ -264,7 +310,7 @@ describe("Query objects should", function () {
264310
col.create(newItem, callback);
265311
waitsFor(function() {
266312
return isJohnInserted;
267-
}, "John should be inserted", 30000);
313+
}, "John should be inserted", TEST_TIMEOUT);
268314
});
269315

270316
afterEach(function () {
@@ -279,7 +325,7 @@ describe("Query objects should", function () {
279325
col.remove(query, callback);
280326
waitsFor(function() {
281327
return isJohnRemoved;
282-
}, "John should be removed", 30000);
328+
}, "John should be removed", TEST_TIMEOUT);
283329

284330
});
285331

@@ -305,7 +351,7 @@ describe("Query objects should", function () {
305351

306352
waitsFor(function () {
307353
return flag;
308-
}, "returned data should not be undefined", 30000);
354+
}, "returned data should not be undefined", TEST_TIMEOUT);
309355

310356
runs(function () {
311357
expect(returnedData[0].data.name).toEqual('John');
@@ -338,7 +384,7 @@ describe("Query objects should", function () {
338384

339385
waitsFor(function () {
340386
return flag;
341-
}, "returned data should not be undefined", 30000);
387+
}, "returned data should not be undefined", TEST_TIMEOUT);
342388

343389
runs(function () {
344390
expect(returnedData[0].data.age).toEqual(35);
@@ -361,8 +407,9 @@ describe("The ClearBlade Messaging module", function() {
361407

362408
beforeEach(function () {
363409
var initOptions = {
364-
appKey: 'f2f5f8aa0aba8bc7e4bdcd8ef142',
365-
appSecret: 'F2F5F8AA0AB4F2C4A4E1C387F3F801'
410+
appKey: TargetPlatform.appKey,
411+
appSecret: TargetPlatform.appSecret,
412+
URI: TargetPlatform.serverAddress
366413
};
367414
ClearBlade.init(initOptions);
368415
});

0 commit comments

Comments
 (0)