Skip to content

Commit d259db7

Browse files
committed
Fixed: message.update don't fire success callback (#135)
* Fixed: message.update don't fire success callback * add test case for 'set a status 'read' to all messages' * rename CREDENTIALS to CREDS in tests * off a test case 'delete privacy list by name' (need review)
1 parent 312d1df commit d259db7

15 files changed

+146
-111
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "quickblox.js",
77
"license": "MIT",

js/modules/qbChat.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,11 +1274,23 @@ MessageProxy.prototype = {
12741274
this.service.ajax({url: Utils.getUrl(messageUrl), type: 'POST', data: params}, callback);
12751275
},
12761276

1277-
update: function(id, params, callback) {
1278-
Utils.QBLog('[MessageProxy]', 'update', id, params);
1277+
/**
1278+
* uses dataType:text
1279+
* because this request returnes
1280+
* empty body if the request was success
1281+
*/
1282+
update: function(id, params, callback) {
1283+
var attrAjax = {
1284+
'type': 'PUT',
1285+
'dataType': 'text',
1286+
'url': Utils.getUrl(messageUrl, id),
1287+
'data': params
1288+
};
12791289

1280-
this.service.ajax({url: Utils.getUrl(messageUrl, id), type: 'PUT', data: params}, callback);
1281-
},
1290+
Utils.QBLog('[MessageProxy]', 'update', id, params);
1291+
1292+
this.service.ajax(attrAjax, callback);
1293+
},
12821294

12831295
delete: function(id, params_or_callback, callback) {
12841296
Utils.QBLog('[DialogProxy]', 'delete', id);

js/qbConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
var config = {
13-
version: '2.1.1',
13+
version: '2.1.2',
1414
creds: {
1515
appId: '',
1616
authKey: '',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "js/qbMain.js",
77
"license": [

quickblox.min.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/QB-ChatSpec.js

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
describe('Chat API', function() {
2-
'use strict';
2+
'use strict';
33

4-
var LOGIN_TIMEOUT = 10000;
5-
var MESSAGING_TIMEOUT = 1500;
6-
var IQ_TIMEOUT = 1000;
7-
var REST_REQUESTS_TIMEOUT = 3000;
4+
var LOGIN_TIMEOUT = 10000;
5+
var MESSAGING_TIMEOUT = 1500;
6+
var IQ_TIMEOUT = 1000;
7+
var REST_REQUESTS_TIMEOUT = 3000;
88

9-
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
9+
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
1010

11-
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
12-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
13-
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
14-
var QBUser2 = isNodeEnv ? require('./config').QBUser2 : window.QBUser2;
11+
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
12+
var CREDS = isNodeEnv ? require('./config').CREDS : window.CREDS;
13+
14+
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
15+
var QBUser2 = isNodeEnv ? require('./config').QBUser2 : window.QBUser2;
1516

1617
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+
}
1721

18-
if(isNodeEnv) {
19-
pending('This describe "XMPP - real time messaging" isn\'t supported outside of the browser');
20-
}
22+
beforeAll(function(done){
23+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CONFIG);
2124

22-
beforeAll(function(done){
23-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
24-
25-
QB.chat.connect({userId: QBUser1.id, password: QBUser1.password}, function(err, roster) {
26-
if(err){
27-
done.fail("Chat login error: " + JSON.stringify(err));
28-
}else{
29-
expect(roster).not.toBeNull();
30-
done();
31-
}
32-
});
33-
}, LOGIN_TIMEOUT);
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); }
3430

31+
expect(roster).not.toBeNull();
32+
done();
33+
});
34+
}, LOGIN_TIMEOUT);
3535

3636
// 1-1 mesasging
3737
//
@@ -148,7 +148,6 @@ describe('Chat API', function() {
148148

149149
}, MESSAGING_TIMEOUT);
150150

151-
152151
// 'Is typing' status
153152
//
154153
it("can send and receive 'is typing' status (private)", function(done) {
@@ -307,18 +306,18 @@ describe('Chat API', function() {
307306
});
308307
});
309308

310-
// Delete list
311-
//
312-
it("can delete list by name", function(done) {
313-
QB.chat.privacylist.delete("test", function(error) {
314-
if(error){
315-
done.fail("Delete list by name error: " + JSON.stringify(error));
316-
}else{
317-
console.info("can delete list by name");
318-
done();
319-
}
320-
});
321-
});
309+
// Delete list TODO: need review this
310+
//
311+
// it("can delete list by name", function(done) {
312+
// QB.chat.privacylist.delete("test", function(error) {
313+
// if(error){
314+
// done.fail("Delete list by name error: " + JSON.stringify(error));
315+
// }else{
316+
// console.info("can delete list by name");
317+
// done();
318+
// }
319+
// });
320+
// });
322321

323322
});
324323

@@ -337,18 +336,21 @@ describe('Chat API', function() {
337336
var messageId;
338337

339338
beforeAll(function(done){
340-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
339+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret);
341340

342-
QB.createSession({login: QBUser1.login, password: QBUser1.password},function (err, result){
343-
if(err){
344-
done.fail("Create session error: " + err);
345-
}else{
346-
expect(result).not.toBeNull();
347-
expect(result.application_id).toEqual(CREDENTIALS.appId);
341+
QB.createSession({
342+
'login': QBUser1.login,
343+
'password': QBUser1.password
344+
},
345+
function(err, result) {
346+
if(err){ done.fail('Create session error: ' + err); }
348347

349-
done();
350-
}
351-
});
348+
expect(result).not.toBeNull();
349+
expect(result.application_id).toEqual(CREDS.appId);
350+
351+
done();
352+
}
353+
);
352354
}, REST_REQUESTS_TIMEOUT);
353355

354356
it('can create a dialog (group)', function(done) {
@@ -360,7 +362,7 @@ describe('Chat API', function() {
360362

361363
QB.chat.dialog.create(params, function(err, res) {
362364
if(err){
363-
done.fail("Creat dialog error: " + JSON.stringify(err));
365+
done.fail("Create dialog error: " + JSON.stringify(err));
364366
}else{
365367
expect(res).not.toBeNull();
366368
expect(res._id).not.toBeNull();
@@ -415,15 +417,15 @@ describe('Chat API', function() {
415417
});
416418
}, REST_REQUESTS_TIMEOUT);
417419

418-
it('can create a mesasge', function(done) {
420+
it('can create a message', function(done) {
419421
var params = {
420422
chat_dialog_id: dialogId,
421423
message: 'hello world'
422424
};
423425

424426
QB.chat.message.create(params, function(err, res) {
425427
if(err){
426-
done.fail("Create a mesasge error: " + JSON.stringify(err));
428+
done.fail("Create a message error: " + JSON.stringify(err));
427429
}else{
428430
expect(res._id).not.toBeNull();
429431
expect(res.message).toEqual("hello world");
@@ -466,6 +468,24 @@ describe('Chat API', function() {
466468
});
467469
}, REST_REQUESTS_TIMEOUT);
468470

471+
it('can set \'read\' status for all messages in dialog', function(done) {
472+
/**
473+
* dialogId we get from previous test case 'can create a dialog'
474+
*/
475+
476+
QB.chat.message.update('', {
477+
'read': '1',
478+
'chat_dialog_id': dialogId
479+
}, function(error, result) {
480+
if(error) {
481+
done.fail('can\'t set status "read" to all messages' , error);
482+
}
483+
484+
/** result will be equal to empty */
485+
done();
486+
});
487+
}, REST_REQUESTS_TIMEOUT);
488+
469489
it('can delete a message with id', function(done) {
470490
QB.chat.message.delete([messageId, "notExistentId"], {force: 1}, function(err, res) {
471491
if(err){

spec/QB-ContentSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('Content API', function() {
55

66
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
77
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
8-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
8+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
99
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1010

1111
var token,

spec/QB-CoreSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Session API', function() {
77
var request = isNodeEnv ? require('request') : {};
88

99
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
10-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
10+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1111
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1212
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1313

spec/QB-DataSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('Custom Objects API', function() {
88
var request = isNodeEnv ? require('request') : {};
99

1010
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
11-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
11+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1212
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1313
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1414

spec/QB-HelpersSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
describe('Helpers', function() {
22
'use strict';
3-
3+
44
var LOGIN_TIMEOUT = 10000;
55

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

88
var QB = isNodeEnv ? require('../quickblox.min.js') : window.QB;
9-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
9+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1010
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1111

1212
beforeAll(function() {

spec/QB-LocationSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('Location API', function() {
55
var request = isNodeEnv ? require('request') : {};
66

77
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
8-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
8+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
99
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1010
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1111

spec/QB-PushnotificationsSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('PushNotifications API', function() {
66
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
77

88
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
9-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
9+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1010
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1111
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1212

spec/QB-UsersSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Users API', function() {
77
var request = isNodeEnv ? require('request') : {};
88

99
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
10-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
10+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
1111
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1212
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1313

@@ -19,7 +19,7 @@ describe('Users API', function() {
1919
done.fail("Create session error: " + JSON.stringify(err));
2020
} else {
2121
expect(result).not.toBeNull();
22-
22+
2323
done();
2424
}
2525
}, REST_REQUESTS_TIMEOUT);

spec/QB-WebRTCSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('WebRTC API', function() {
55
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
66

77
var QB = isNodeEnv ? require('../js/qbMain') : window.QB;
8-
var CREDENTIALS = isNodeEnv ? require('./config').CREDENTIALS : window.CREDENTIALS;
8+
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
99
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
1010
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1111
var QBUser2 = isNodeEnv ? require('./config').QBUser2 : window.QBUser2;

0 commit comments

Comments
 (0)