1
1
describe ( 'Chat API' , function ( ) {
2
- 'use strict' ;
2
+ 'use strict' ;
3
3
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 ;
8
8
9
- var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object' ;
9
+ var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object' ;
10
10
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 ;
15
16
16
17
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
+ }
17
21
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 ) ;
21
24
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 ) ; }
34
30
31
+ expect ( roster ) . not . toBeNull ( ) ;
32
+ done ( ) ;
33
+ } ) ;
34
+ } , LOGIN_TIMEOUT ) ;
35
35
36
36
// 1-1 mesasging
37
37
//
@@ -148,7 +148,6 @@ describe('Chat API', function() {
148
148
149
149
} , MESSAGING_TIMEOUT ) ;
150
150
151
-
152
151
// 'Is typing' status
153
152
//
154
153
it ( "can send and receive 'is typing' status (private)" , function ( done ) {
@@ -307,18 +306,18 @@ describe('Chat API', function() {
307
306
} ) ;
308
307
} ) ;
309
308
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
+ // });
322
321
323
322
} ) ;
324
323
@@ -337,18 +336,21 @@ describe('Chat API', function() {
337
336
var messageId ;
338
337
339
338
beforeAll ( function ( done ) {
340
- QB . init ( CREDENTIALS . appId , CREDENTIALS . authKey , CREDENTIALS . authSecret ) ;
339
+ QB . init ( CREDS . appId , CREDS . authKey , CREDS . authSecret ) ;
341
340
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 ) ; }
348
347
349
- done ( ) ;
350
- }
351
- } ) ;
348
+ expect ( result ) . not . toBeNull ( ) ;
349
+ expect ( result . application_id ) . toEqual ( CREDS . appId ) ;
350
+
351
+ done ( ) ;
352
+ }
353
+ ) ;
352
354
} , REST_REQUESTS_TIMEOUT ) ;
353
355
354
356
it ( 'can create a dialog (group)' , function ( done ) {
@@ -360,7 +362,7 @@ describe('Chat API', function() {
360
362
361
363
QB . chat . dialog . create ( params , function ( err , res ) {
362
364
if ( err ) {
363
- done . fail ( "Creat dialog error: " + JSON . stringify ( err ) ) ;
365
+ done . fail ( "Create dialog error: " + JSON . stringify ( err ) ) ;
364
366
} else {
365
367
expect ( res ) . not . toBeNull ( ) ;
366
368
expect ( res . _id ) . not . toBeNull ( ) ;
@@ -415,15 +417,15 @@ describe('Chat API', function() {
415
417
} ) ;
416
418
} , REST_REQUESTS_TIMEOUT ) ;
417
419
418
- it ( 'can create a mesasge ' , function ( done ) {
420
+ it ( 'can create a message ' , function ( done ) {
419
421
var params = {
420
422
chat_dialog_id : dialogId ,
421
423
message : 'hello world'
422
424
} ;
423
425
424
426
QB . chat . message . create ( params , function ( err , res ) {
425
427
if ( err ) {
426
- done . fail ( "Create a mesasge error: " + JSON . stringify ( err ) ) ;
428
+ done . fail ( "Create a message error: " + JSON . stringify ( err ) ) ;
427
429
} else {
428
430
expect ( res . _id ) . not . toBeNull ( ) ;
429
431
expect ( res . message ) . toEqual ( "hello world" ) ;
@@ -466,6 +468,24 @@ describe('Chat API', function() {
466
468
} ) ;
467
469
} , REST_REQUESTS_TIMEOUT ) ;
468
470
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
+
469
489
it ( 'can delete a message with id' , function ( done ) {
470
490
QB . chat . message . delete ( [ messageId , "notExistentId" ] , { force : 1 } , function ( err , res ) {
471
491
if ( err ) {
0 commit comments