1- var LOGIN_TIMEOUT = 10000 ;
2- var MESSAGING_TIMEOUT = 1500 ;
3- var IQ_TIMEOUT = 1000 ;
4- var REST_REQUESTS_TIMEOUT = 3000 ;
5-
61describe ( 'Chat API' , function ( ) {
2+ var LOGIN_TIMEOUT = 10000 ;
3+ var MESSAGING_TIMEOUT = 1500 ;
4+ var IQ_TIMEOUT = 1000 ;
5+ var REST_REQUESTS_TIMEOUT = 3000 ;
76
87 describe ( 'XMPP (real time messaging)' , function ( ) {
98
10- // beforeAll
11- //
129 beforeAll ( function ( done ) {
13-
1410 QB . init ( CREDENTIALS . appId , CREDENTIALS . authKey , CREDENTIALS . authSecret , CONFIG ) ;
1511
1612 QB . chat . connect ( { userId : QBUser1 . id , password : QBUser1 . password } , function ( err , roster ) {
@@ -21,18 +17,15 @@ describe('Chat API', function() {
2117 done ( ) ;
2218 }
2319 } ) ;
24-
2520 } , LOGIN_TIMEOUT ) ;
2621
2722
2823 // 1-1 mesasging
2924 //
3025 it ( 'can send and receive private messages' , function ( done ) {
31-
3226 var self = this ;
3327
3428 QB . chat . onMessageListener = function ( userId , receivedMessage ) {
35-
3629 expect ( receivedMessage ) . not . toBeNull ( ) ;
3730 expect ( receivedMessage . type ) . toEqual ( "chat" ) ;
3831 expect ( userId ) . toEqual ( QBUser1 . id ) ;
@@ -55,16 +48,15 @@ describe('Chat API', function() {
5548 } ,
5649 markable : 1
5750 } ;
58- QB . chat . send ( QBUser1 . id , message ) ;
59- this . messageId = message . id ;
6051
52+ QB . chat . send ( QBUser1 . id , message ) ;
53+ self . messageId = message . id ;
6154 } , MESSAGING_TIMEOUT ) ;
6255
6356
6457 // System messages
6558 //
6659 it ( 'can send and receive system messages' , function ( done ) {
67-
6860 var self = this ;
6961
7062 QB . chat . onSystemMessageListener = function ( receivedMessage ) {
@@ -87,15 +79,14 @@ describe('Chat API', function() {
8779 }
8880 } ;
8981 QB . chat . sendSystemMessage ( QBUser1 . id , message ) ;
90- this . messageId = message . id ;
82+ self . messageId = message . id ;
9183
9284 } , MESSAGING_TIMEOUT ) ;
9385
9486
9587 // 'Delivered' status
9688 //
9789 it ( "can send and receive 'delivered' status" , function ( done ) {
98-
9990 var self = this ;
10091
10192 QB . chat . onDeliveredStatusListener = function ( messageId , dialogId , userId ) {
@@ -112,7 +103,7 @@ describe('Chat API', function() {
112103 userId : QBUser1 . id ,
113104 dialogId : "507f191e810c19729de860ea"
114105 } ;
115- this . params = params ;
106+ self . params = params ;
116107
117108 QB . chat . sendDeliveredStatus ( params ) ;
118109
@@ -122,7 +113,6 @@ describe('Chat API', function() {
122113 // 'Read' status
123114 //
124115 it ( "can send and receive 'read' status" , function ( done ) {
125-
126116 var self = this ;
127117
128118 QB . chat . onReadStatusListener = function ( messageId , dialogId , userId ) {
@@ -139,7 +129,7 @@ describe('Chat API', function() {
139129 userId : QBUser1 . id ,
140130 dialogId : "507f191e810c19729de860ea"
141131 } ;
142- this . params = params ;
132+ self . params = params ;
143133
144134 QB . chat . sendReadStatus ( params ) ;
145135
@@ -149,7 +139,6 @@ describe('Chat API', function() {
149139 // 'Is typing' status
150140 //
151141 it ( "can send and receive 'is typing' status (private)" , function ( done ) {
152-
153142 QB . chat . onMessageTypingListener = function ( composing , userId , dialogId ) {
154143 expect ( composing ) . toEqual ( true ) ;
155144 expect ( userId ) . toEqual ( QBUser1 . id ) ;
@@ -166,7 +155,6 @@ describe('Chat API', function() {
166155 // 'Stop typing' status
167156 //
168157 it ( "can send and receive 'stop typing' status (private)" , function ( done ) {
169-
170158 QB . chat . onMessageTypingListener = function ( composing , userId , dialogId ) {
171159 expect ( composing ) . toEqual ( false ) ;
172160 expect ( userId ) . toEqual ( QBUser1 . id ) ;
@@ -408,13 +396,12 @@ describe('Chat API', function() {
408396 // Dialog update
409397 //
410398 it ( 'can update a dialog (group)' , function ( done ) {
411-
412399 var toUpdate = {
413400 name : "GroupDialogNewName" ,
414401 pull_all : { occupants_ids : [ QBUser2 . id ] }
415402 } ;
416- QB . chat . dialog . update ( dialogId , toUpdate , function ( err , res ) {
417403
404+ QB . chat . dialog . update ( dialogId , toUpdate , function ( err , res ) {
418405 if ( err ) {
419406 done . fail ( "Update dialog " + dialogId + " error: " + JSON . stringify ( err ) ) ;
420407 } else {
@@ -428,16 +415,13 @@ describe('Chat API', function() {
428415 } ) ;
429416 } , REST_REQUESTS_TIMEOUT ) ;
430417
431-
432418 // Can create a message
433419 //
434420 it ( 'can create a mesasge' , function ( done ) {
435-
436421 var params = { chat_dialog_id : dialogId ,
437422 message : "hello world" ,
438423 } ;
439424 QB . chat . message . create ( params , function ( err , res ) {
440-
441425 if ( err ) {
442426 done . fail ( "Create a mesasge error: " + JSON . stringify ( err ) ) ;
443427 } else {
@@ -457,10 +441,9 @@ describe('Chat API', function() {
457441 // Messages list
458442 //
459443 it ( 'can list messages' , function ( done ) {
460-
461444 var filters = { chat_dialog_id : dialogId } ;
462- QB . chat . message . list ( filters , function ( err , res ) {
463445
446+ QB . chat . message . list ( filters , function ( err , res ) {
464447 if ( err ) {
465448 done . fail ( "List messages error: " + JSON . stringify ( err ) ) ;
466449 } else {
@@ -469,18 +452,16 @@ describe('Chat API', function() {
469452
470453 done ( ) ;
471454 }
472-
473455 } ) ;
474456 } , REST_REQUESTS_TIMEOUT ) ;
475457
476458
477459 // Unread messages count
478460 //
479461 it ( 'can request unread messages count' , function ( done ) {
480-
481462 var params = { chat_dialog_ids : [ dialogId ] } ;
482- QB . chat . message . unreadCount ( params , function ( err , res ) {
483463
464+ QB . chat . message . unreadCount ( params , function ( err , res ) {
484465 if ( err ) {
485466 done . fail ( "Request unread messages count error: " + JSON . stringify ( err ) ) ;
486467 } else {
@@ -501,7 +482,6 @@ describe('Chat API', function() {
501482 console . log ( "messageId: " + messageId ) ;
502483
503484 QB . chat . message . delete ( [ messageId , "notExistentId" ] , { force : 1 } , function ( err , res ) {
504-
505485 if ( err ) {
506486 done . fail ( "Delete message " + messageId + " error: " + JSON . stringify ( err ) ) ;
507487 } else {
@@ -517,9 +497,7 @@ describe('Chat API', function() {
517497 // Dialog delete
518498 //
519499 it ( 'can delete a dialog (group)' , function ( done ) {
520-
521500 QB . chat . dialog . delete ( [ dialogId , "notExistentId" ] , { force : 1 } , function ( err , res ) {
522-
523501 if ( err ) {
524502 done . fail ( "Delete dialog " + dialogId + " error: " + JSON . stringify ( err ) ) ;
525503 } else {
@@ -532,7 +510,5 @@ describe('Chat API', function() {
532510
533511 } ) ;
534512 } , REST_REQUESTS_TIMEOUT ) ;
535-
536513 } ) ;
537-
538514} ) ;
0 commit comments