Skip to content

Commit a6d7c6f

Browse files
author
Igor Khomenko
committed
cleanup tests
1 parent 95d38f4 commit a6d7c6f

10 files changed

+163
-90
lines changed

quickblox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/QB-ChatSpec.js

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@ describe('Chat API', function() {
33

44
var LOGIN_TIMEOUT = 10000;
55
var MESSAGING_TIMEOUT = 1500;
6-
var IQ_TIMEOUT = 1000;
6+
var IQ_TIMEOUT = 3000;
77
var REST_REQUESTS_TIMEOUT = 3000;
88

99
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
1010

1111
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
1212
var CREDS = isNodeEnv ? require('./config').CREDS : window.CREDS;
13+
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1314

1415
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1516
var QBUser2 = isNodeEnv ? require('./config').QBUser2 : window.QBUser2;
1617

18+
var chatEndpoint = CONFIG.endpoints.chat;
19+
1720
describe('XMPP (real time messaging)', function() {
18-
if(isNodeEnv) {
19-
pending('This describe "XMPP - real time messaging" isn\'t supported outside of the browser');
20-
}
21+
if(isNodeEnv) {
22+
pending('This describe "XMPP - real time messaging" isn\'t supported outside of the browser');
23+
}
2124

22-
beforeAll(function(done){
23-
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CONFIG);
25+
beforeAll(function(done){
26+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CONFIG);
2427

25-
QB.chat.connect({
26-
'userId': QBUser1.id,
27-
'password': QBUser1.password
28-
}, function(err, roster) {
29-
if(err){ done.fail("Chat login error: ", err); }
28+
QB.chat.connect({
29+
'userId': QBUser1.id,
30+
'password': QBUser1.password
31+
}, function(err, roster) {
32+
if(err){ done.fail("Chat login error: ", err); }
3033

31-
expect(roster).not.toBeNull();
32-
done();
33-
});
34-
}, LOGIN_TIMEOUT);
34+
expect(roster).not.toBeNull();
35+
done();
36+
});
37+
}, LOGIN_TIMEOUT);
3538

3639
// 1-1 mesasging
3740
//
@@ -179,10 +182,64 @@ describe('Chat API', function() {
179182

180183
}, MESSAGING_TIMEOUT);
181184

185+
// Privacy lists API
186+
//
187+
describe("Contact list: ", function() {
188+
189+
// Retrieve contact list
190+
//
191+
it("can retrieve contact list", function(done) {
192+
QB.chat.roster.get(function(roster) {
193+
if(!roster){
194+
done.fail("Retrieve contact list error");
195+
}else{
196+
console.info("can retrieve contact list");
197+
done();
198+
}
199+
});
200+
}, IQ_TIMEOUT);
201+
202+
// Add user to contact list
203+
//
204+
it("can add user to contact list", function(done) {
205+
QB.chat.roster.add(QBUser2.id, function() {
206+
console.info("can add user to contact list");
207+
done();
208+
});
209+
}, IQ_TIMEOUT);
210+
211+
// // Remove user from contact list
212+
// //
213+
// it("can remove user from contact list", function(done) {
214+
// QB.chat.roster.remove(QBUser2.id, function() {
215+
// console.info("can remove user from contact list");
216+
// done();
217+
// });
218+
// }, IQ_TIMEOUT);
219+
220+
// Confirm subscription request
221+
//
222+
it("can confirm subscription request", function(done) {
223+
QB.chat.roster.confirm(QBUser2.id, function() {
224+
console.info("can confirm subscription request");
225+
done();
226+
});
227+
}, IQ_TIMEOUT);
228+
229+
// // Reject subscription request
230+
// //
231+
// it("can reject subscription request", function(done) {
232+
// QB.chat.roster.reject(QBUser2.id, function() {
233+
// console.info("can reject subscription request");
234+
// done();
235+
// });
236+
// }, IQ_TIMEOUT);
237+
});
238+
182239

183240
// Privacy lists API
184241
//
185-
describe("Privacy list", function() {
242+
describe("Privacy list: ", function() {
186243

187244
// Create
188245
//
@@ -368,7 +425,7 @@ describe('Chat API', function() {
368425
expect(res._id).not.toBeNull();
369426
expect(res.type).toEqual(2);
370427
expect(res.name).toEqual("GroupDialogName");
371-
expect(res.xmpp_room_jid).toMatch('muc.chat.quickblox.com');
428+
expect(res.xmpp_room_jid).toContain(chatEndpoint);
372429

373430
var ocuupantsArray = [QBUser2.id, QBUser1.id].sort(function(a,b){
374431
return a - b;

spec/QB-ContentSpec.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var fileId;
2+
13
describe('Content API', function() {
24
'use strict';
35

@@ -7,14 +9,15 @@ describe('Content API', function() {
79
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
810
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
911
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
12+
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1013

1114
var token,
1215
data = {},
1316
fileUID = '97f5802dcbd34a59a4921d73f6baedd000',
14-
urlToBlobs = 'https://api.quickblox.com/blobs/';
17+
urlToBlobs = 'https://' + CONFIG.endpoints.api + '/blobs/';
1518

1619
beforeAll(function(done){
17-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
20+
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
1821

1922
QB.createSession(QBUser1, function(err, session) {
2023
if (err) {
@@ -42,13 +45,28 @@ describe('Content API', function() {
4245
if (err) {
4346
done.fail('Create and upload files error: ' + JSON.stringify(err));
4447
}else{
48+
fileId = res.id;
49+
4550
expect(res).not.toBeNull();
4651
expect(res.name).toBe('QB.txt');
4752

4853
done();
4954
}
5055
});
51-
}, 5000);
56+
}, REST_REQUESTS_TIMEOUT);
57+
58+
it('can get file information by ID', function(done) {
59+
QB.content.getInfo(fileId, function(err, res) {
60+
if (err) {
61+
done.fail("Get file information by ID error: " + JSON.stringify(err));
62+
}else{
63+
expect(res).not.toBeNull();
64+
expect(res.blob.id).toEqual(self.fileId);
65+
66+
done();
67+
}
68+
});
69+
}, REST_REQUESTS_TIMEOUT);
5270

5371
it('can list content objects', function(done) {
5472
QB.content.list(function(err, res) {
@@ -87,20 +105,6 @@ describe('Content API', function() {
87105
});
88106
}, 7000);
89107

90-
it('can get file information by ID', function(done) {
91-
QB.content.getInfo(2917985, function(err, res) {
92-
if (err) {
93-
done.fail("Get file information by ID error: " + JSON.stringify(err));
94-
}else{
95-
expect(res).not.toBeNull();
96-
expect(res.blob.id).toEqual(2917985);
97-
expect(res.blob.size).toBe(15);
98-
99-
done();
100-
}
101-
});
102-
}, REST_REQUESTS_TIMEOUT);
103-
104108
it('can access public URL', function() {
105109
var publicUrl = QB.content.publicUrl(fileUID);
106110

spec/QB-DataSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Custom Objects API', function() {
1313
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1414

1515
beforeAll(function(done){
16-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
16+
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
1717

1818
QB.createSession(QBUser1, function(err, res) {
1919
if (err) {
@@ -164,7 +164,7 @@ describe('Custom Objects API', function() {
164164
done.fail("Download a file from existing record error: " + JSON.stringify(err));
165165
} else {
166166
expect(res).not.toBeNull();
167-
expect(res).toBe("https://api.quickblox.com/data/cars/"+paramsFile.id+
167+
expect(res).toBe("https://" + CONFIG.endpoints.api + "/data/cars/"+paramsFile.id+
168168
"/file.json?field_name="+paramsFile.field_name+
169169
"&token="+session.token);
170170

@@ -182,7 +182,7 @@ describe('Custom Objects API', function() {
182182
var url = QB.data.fileUrl('cars', paramsFor);
183183

184184
expect(url).not.toBeNull();
185-
expect(url).toBe("https://api.quickblox.com/data/cars/"+paramsFile.id+
185+
expect(url).toBe("https://" + CONFIG.endpoints.api + "/data/cars/"+paramsFile.id+
186186
"/file.json?field_name="+paramsFile.field_name+
187187
"&token="+session.token);
188188

spec/QB-HelpersSpec.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
describe('Helpers', function() {
22
'use strict';
33

4-
var LOGIN_TIMEOUT = 10000;
4+
var LOGIN_TIMEOUT = 20000;
55

66
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
77

88
var QB = isNodeEnv ? require('../quickblox.min.js') : window.QB;
99
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1010
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
11+
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
12+
13+
var appId = CREDENTIALS.appId;
14+
var chatEndpoint = CONFIG.endpoints.chat;
1115

1216
beforeAll(function() {
13-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
17+
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
1418
});
1519

1620
/**
1721
* TEST CASES
1822
*/
1923
it('can generate user\'s jid', function() {
20-
var userJid = QB.chat.helpers.getUserJid(5, 29650);
24+
var userJid = QB.chat.helpers.getUserJid(5, appId);
2125

22-
expect(userJid).toEqual('5-[email protected]');
26+
expect(userJid).toEqual('5-' + appId + '@' + chatEndpoint);
2327
});
2428

2529
it('can return jid from jid or from user\'s id', function() {
2630
var jid = QB.chat.helpers.jidOrUserId(100500);
2731

28-
expect(jid).toEqual('100500-[email protected]');
32+
expect(jid).toEqual('100500-' + appId + '@' + chatEndpoint);
2933
});
3034

3135
it('can get type chat from jid or from user\'s id', function() {
3236
var id = QB.chat.helpers.typeChat(100500);
3337

3438
expect(id).toEqual('chat');
35-
var jid = QB.chat.helpers.typeChat('100500-29650@chat.quickblox.com');
39+
var jid = QB.chat.helpers.typeChat('100500-29650@' + chatEndpoint);
3640
expect(jid).toEqual('chat');
3741

38-
var room = QB.chat.helpers.typeChat('29650_562f271ba28f9aa53e004788@muc.chat.quickblox.com');
42+
var room = QB.chat.helpers.typeChat('29650_562f271ba28f9aa53e004788@muc.' + chatEndpoint);
3943
expect(room).toEqual('groupchat');
4044
});
4145

@@ -50,25 +54,25 @@ describe('Helpers', function() {
5054
it('can get user nick with muc domain', function() {
5155
var userNick = QB.chat.helpers.getUserNickWithMucDomain(100500);
5256

53-
expect(userNick).toEqual('muc.chat.quickblox.com/100500');
57+
expect(userNick).toEqual('muc.' + chatEndpoint + '/100500');
5458
});
5559

5660
it('can get id from node', function() {
57-
var userId = QB.chat.helpers.getIdFromNode('100500-29650@chat.quickblox.com');
61+
var userId = QB.chat.helpers.getIdFromNode('100500-29650@' + chatEndpoint);
5862

5963
expect(userId).toEqual(100500);
6064
});
6165

6266
it('can get dialog id from node', function() {
63-
var dialogId = QB.chat.helpers.getDialogIdFromNode('28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com');
67+
var dialogId = QB.chat.helpers.getDialogIdFromNode(appId + '_5640ada2a28f9a76540006b6@muc.' + chatEndpoint);
6468

6569
expect(dialogId).toEqual('5640ada2a28f9a76540006b6');
6670
});
6771

6872
it('can get room jid from dialog id', function() {
6973
var roomJid = QB.chat.helpers.getRoomJidFromDialogId('5640ada2a28f9a76540006b6');
7074

71-
expect(roomJid).toEqual('29650_5640ada2a28f9a76540006b6@muc.chat.quickblox.com');
75+
expect(roomJid).toEqual(appId + '_5640ada2a28f9a76540006b6@muc.' + chatEndpoint);
7276
});
7377

7478
it('can get roomJid from jid', function(done) {
@@ -80,18 +84,18 @@ describe('Helpers', function() {
8084
if (err) {
8185
done.fail('Connection to chat error: ' + JSON.stringify(err));
8286
} else {
83-
var roomJid = QB.chat.helpers.getRoomJid('28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com');
87+
var roomJid = QB.chat.helpers.getRoomJid(appId + '_5640ada2a28f9a76540006b6@muc.' + chatEndpoint);
8488

85-
expect(roomJid).toEqual('28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733');
89+
expect(roomJid).toEqual(appId + '_5640ada2a28f9a76540006b6@muc.' + chatEndpoint + '/' + QBUser1.id);
8690
done();
8791
}
8892
});
8993
}, LOGIN_TIMEOUT);
9094

9195
it('can get id from resource', function() {
92-
var userId = QB.chat.helpers.getIdFromResource('28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733');
96+
var userId = QB.chat.helpers.getIdFromResource(appId + '_5640ada2a28f9a76540006b6@muc.' + chatEndpoint + '/' + QBUser1.id);
9397

94-
expect(userId).toEqual(6126733);
98+
expect(userId).toEqual(QBUser1.id);
9599
});
96100

97101
it('can get unique id', function() {
@@ -111,8 +115,8 @@ describe('Helpers', function() {
111115
});
112116

113117
it('can get user id from roomJid', function() {
114-
var userId = QB.chat.helpers.getUserIdFromRoomJid('28287_5640ada2a28f9a76540006b6@muc.chat.quickblox.com/6126733');
118+
var userId = QB.chat.helpers.getUserIdFromRoomJid('28287_5640ada2a28f9a76540006b6@muc.' + chatEndpoint + '/' + QBUser1.id);
115119

116-
expect(userId).toEqual('6126733');
120+
expect(parseInt(userId)).toEqual(QBUser1.id);
117121
});
118122
});

spec/QB-LocationSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Location API', function() {
1010
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1111

1212
beforeAll(function(done){
13-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
13+
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
1414

1515
QB.createSession(QBUser1, function(err, session) {
1616
if (err) {

0 commit comments

Comments
 (0)