@@ -7,6 +7,9 @@ describe('Chat API', function() {
77
88 describe ( 'XMPP (real time messaging)' , function ( ) {
99
10+ var messageId ;
11+
12+
1013 // beforeAll
1114 //
1215 beforeAll ( function ( done ) {
@@ -29,8 +32,6 @@ describe('Chat API', function() {
2932 //
3033 it ( 'can send and receive private messages' , function ( done ) {
3134
32- var self = this ;
33-
3435 QB . chat . onMessageListener = function ( userId , receivedMessage ) {
3536
3637 expect ( receivedMessage ) . not . toBeNull ( ) ;
@@ -40,9 +41,9 @@ describe('Chat API', function() {
4041 param1 : "value1" ,
4142 param2 : "value2"
4243 } ) ;
43- expect ( receivedMessage . id ) . toEqual ( self . messageId ) ;
44+ expect ( receivedMessage . id ) . toEqual ( messageId ) ;
4445 expect ( receivedMessage . markable ) . toEqual ( 1 ) ;
45- self . messageId = null ;
46+ messageId = null ;
4647
4748 done ( ) ;
4849 } ;
@@ -53,10 +54,11 @@ describe('Chat API', function() {
5354 param1 : "value1" ,
5455 param2 : "value2"
5556 } ,
57+ body : "hello amigo" ,
5658 markable : 1
5759 } ;
5860 QB . chat . send ( QBUser1 . id , message ) ;
59- this . messageId = message . id ;
61+ messageId = message . id ;
6062
6163 } , MESSAGING_TIMEOUT ) ;
6264
@@ -65,17 +67,15 @@ describe('Chat API', function() {
6567 //
6668 it ( 'can send and receive system messages' , function ( done ) {
6769
68- var self = this ;
69-
7070 QB . chat . onSystemMessageListener = function ( receivedMessage ) {
7171 expect ( receivedMessage ) . not . toBeNull ( ) ;
7272 expect ( receivedMessage . userId ) . toEqual ( QBUser1 . id ) ;
7373 expect ( receivedMessage . extension ) . toEqual ( {
7474 param1 : "value1" ,
7575 param2 : "value2"
7676 } ) ;
77- expect ( receivedMessage . id ) . toEqual ( self . messageId ) ;
78- self . messageId = null ;
77+ expect ( receivedMessage . id ) . toEqual ( messageId ) ;
78+ messageId = null ;
7979
8080 done ( ) ;
8181 } ;
@@ -87,7 +87,7 @@ describe('Chat API', function() {
8787 }
8888 } ;
8989 QB . chat . sendSystemMessage ( QBUser1 . id , message ) ;
90- this . messageId = message . id ;
90+ messageId = message . id ;
9191
9292 } , MESSAGING_TIMEOUT ) ;
9393
@@ -96,23 +96,19 @@ describe('Chat API', function() {
9696 //
9797 it ( "can send and receive 'delivered' status" , function ( done ) {
9898
99- var self = this ;
100-
101- QB . chat . onDeliveredStatusListener = function ( messageId , dialogId , userId ) {
102- expect ( messageId ) . toEqual ( self . params . messageId ) ;
103- expect ( dialogId ) . toEqual ( self . params . dialogId ) ;
104- expect ( userId ) . toEqual ( self . params . userId ) ;
105- self . params = null ;
106-
107- done ( ) ;
108- } ;
109-
11099 var params = {
111100 messageId : "507f1f77bcf86cd799439011" ,
112101 userId : QBUser1 . id ,
113- dialogId : "507f191e810c19729de860ea"
102+ dialogId : "507f191e810c19729de86012"
103+ } ;
104+
105+ QB . chat . onDeliveredStatusListener = function ( msgId , dialogId , userId ) {
106+ expect ( msgId ) . toEqual ( "507f1f77bcf86cd799439011" ) ;
107+ expect ( dialogId ) . toEqual ( "507f191e810c19729de86012" ) ;
108+ expect ( userId ) . toEqual ( QBUser1 . id ) ;
109+
110+ done ( ) ;
114111 } ;
115- this . params = params ;
116112
117113 QB . chat . sendDeliveredStatus ( params ) ;
118114
@@ -123,24 +119,20 @@ describe('Chat API', function() {
123119 //
124120 it ( "can send and receive 'read' status" , function ( done ) {
125121
126- var self = this ;
122+ var params = {
123+ messageId : "507f1f77bcf86cd799439022" ,
124+ userId : QBUser1 . id ,
125+ dialogId : "507f191e810c19729de86023"
126+ } ;
127127
128- QB . chat . onReadStatusListener = function ( messageId , dialogId , userId ) {
129- expect ( messageId ) . toEqual ( self . params . messageId ) ;
130- expect ( dialogId ) . toEqual ( self . params . dialogId ) ;
131- expect ( userId ) . toEqual ( self . params . userId ) ;
132- self . params = null ;
128+ QB . chat . onReadStatusListener = function ( msgId , dialogId , userId ) {
129+ expect ( msgId ) . toEqual ( "507f1f77bcf86cd799439022" ) ;
130+ expect ( dialogId ) . toEqual ( "507f191e810c19729de86023" ) ;
131+ expect ( userId ) . toEqual ( QBUser1 . id ) ;
133132
134133 done ( ) ;
135134 } ;
136135
137- var params = {
138- messageId : "507f1f77bcf86cd799439011" ,
139- userId : QBUser1 . id ,
140- dialogId : "507f191e810c19729de860ea"
141- } ;
142- this . params = params ;
143-
144136 QB . chat . sendReadStatus ( params ) ;
145137
146138 } , MESSAGING_TIMEOUT ) ;
@@ -217,10 +209,17 @@ describe('Chat API', function() {
217209 //
218210 it ( 'can create a dialog (group)' , function ( done ) {
219211
212+ var customParams = {
213+ class_name : "JasmineDialogCustomParams" ,
214+ age : 1 ,
215+ name : "challeng"
216+ }
220217 var params = { occupants_ids :[ QBUser2 . id ] ,
221218 name : "GroupDialogName" ,
222- type : 2
219+ type : 2 ,
220+ data : customParams
223221 }
222+
224223 QB . chat . dialog . create ( params , function ( err , res ) {
225224
226225 if ( err ) {
@@ -235,6 +234,7 @@ describe('Chat API', function() {
235234 return a - b ;
236235 } ) ;
237236 expect ( res . occupants_ids ) . toEqual ( ocuupantsArray ) ;
237+ expect ( res . data ) . toEqual ( customParams ) ;
238238
239239 dialogId = res . _id ;
240240
@@ -268,10 +268,18 @@ describe('Chat API', function() {
268268 //
269269 it ( 'can update a dialog (group)' , function ( done ) {
270270
271+ var customParams = {
272+ class_name : "JasmineDialogCustomParams" ,
273+ age : 2 ,
274+ name : "challeng2"
275+ }
276+
271277 var toUpdate = {
272278 name : "GroupDialogNewName" ,
273- pull_all : { occupants_ids : [ QBUser2 . id ] }
279+ pull_all : { occupants_ids : [ QBUser2 . id ] } ,
280+ data : customParams
274281 } ;
282+
275283 QB . chat . dialog . update ( dialogId , toUpdate , function ( err , res ) {
276284
277285 if ( err ) {
@@ -280,6 +288,7 @@ describe('Chat API', function() {
280288 expect ( res ) . not . toBeNull ( ) ;
281289 expect ( res . name ) . toEqual ( "GroupDialogNewName" ) ;
282290 expect ( res . occupants_ids ) . toEqual ( [ QBUser1 . id ] ) ;
291+ expect ( res . data ) . toEqual ( customParams ) ;
283292
284293 done ( ) ;
285294 }
0 commit comments