@@ -322,39 +322,32 @@ describe('Chat API', function() {
322322 } ) ;
323323
324324 describe ( 'REST API' , function ( ) {
325-
326325 var dialogId ;
327326 var messageId ;
328327
329- // beforeAll
330- //
331328 beforeAll ( function ( done ) {
332-
333329 QB . init ( CREDENTIALS . appId , CREDENTIALS . authKey , CREDENTIALS . authSecret ) ;
334330
335331 QB . createSession ( { login : QBUser1 . login , password : QBUser1 . password } , function ( err , result ) {
336332 if ( err ) {
337- done . fail ( "Creat session error: " + err ) ;
333+ done . fail ( "Create session error: " + err ) ;
338334 } else {
339335 expect ( result ) . not . toBeNull ( ) ;
340336 expect ( result . application_id ) . toEqual ( CREDENTIALS . appId ) ;
337+
341338 done ( ) ;
342339 }
343-
344340 } ) ;
345341 } , REST_REQUESTS_TIMEOUT ) ;
346342
347-
348- // Dialog create
349- //
350343 it ( 'can create a dialog (group)' , function ( done ) {
344+ var params = {
345+ occupants_ids : [ QBUser2 . id ] ,
346+ name : "GroupDialogName" ,
347+ type : 2
348+ } ;
351349
352- var params = { occupants_ids :[ QBUser2 . id ] ,
353- name : "GroupDialogName" ,
354- type : 2
355- }
356350 QB . chat . dialog . create ( params , function ( err , res ) {
357-
358351 if ( err ) {
359352 done . fail ( "Creat dialog error: " + JSON . stringify ( err ) ) ;
360353 } else {
@@ -363,41 +356,35 @@ describe('Chat API', function() {
363356 expect ( res . type ) . toEqual ( 2 ) ;
364357 expect ( res . name ) . toEqual ( "GroupDialogName" ) ;
365358 expect ( res . xmpp_room_jid ) . toMatch ( 'muc.chat.quickblox.com' ) ;
359+
366360 var ocuupantsArray = [ QBUser2 . id , QBUser1 . id ] . sort ( function ( a , b ) {
367361 return a - b ;
368362 } ) ;
363+
369364 expect ( res . occupants_ids ) . toEqual ( ocuupantsArray ) ;
370365
371366 dialogId = res . _id ;
372367
373368 done ( ) ;
374369 }
375-
376370 } ) ;
377371 } , REST_REQUESTS_TIMEOUT ) ;
378372
379-
380- // Dialog list
381- //
382373 it ( 'can list dialogs' , function ( done ) {
383-
384374 var filters = null ;
385- QB . chat . dialog . list ( filters , function ( err , res ) {
386375
376+ QB . chat . dialog . list ( filters , function ( err , res ) {
387377 if ( err ) {
388378 done . fail ( "List dialogs error: " + JSON . stringify ( err ) ) ;
389379 } else {
390380 expect ( res ) . not . toBeNull ( ) ;
391381 expect ( res . items . length ) . toBeGreaterThan ( 0 ) ;
382+
392383 done ( ) ;
393384 }
394-
395385 } ) ;
396386 } , REST_REQUESTS_TIMEOUT ) ;
397387
398-
399- // Dialog update
400- //
401388 it ( 'can update a dialog (group)' , function ( done ) {
402389 var toUpdate = {
403390 name : "GroupDialogNewName" ,
@@ -414,16 +401,15 @@ describe('Chat API', function() {
414401
415402 done ( ) ;
416403 }
417-
418404 } ) ;
419405 } , REST_REQUESTS_TIMEOUT ) ;
420406
421- // Can create a message
422- //
423407 it ( 'can create a mesasge' , function ( done ) {
424- var params = { chat_dialog_id : dialogId ,
425- message : "hello world" ,
426- } ;
408+ var params = {
409+ chat_dialog_id : dialogId ,
410+ message : 'hello world'
411+ } ;
412+
427413 QB . chat . message . create ( params , function ( err , res ) {
428414 if ( err ) {
429415 done . fail ( "Create a mesasge error: " + JSON . stringify ( err ) ) ;
@@ -436,15 +422,11 @@ describe('Chat API', function() {
436422
437423 done ( ) ;
438424 }
439-
440425 } ) ;
441426 } , REST_REQUESTS_TIMEOUT ) ;
442427
443-
444- // Messages list
445- //
446428 it ( 'can list messages' , function ( done ) {
447- var filters = { chat_dialog_id : dialogId } ;
429+ var filters = { chat_dialog_id : dialogId } ;
448430
449431 QB . chat . message . list ( filters , function ( err , res ) {
450432 if ( err ) {
@@ -458,9 +440,6 @@ describe('Chat API', function() {
458440 } ) ;
459441 } , REST_REQUESTS_TIMEOUT ) ;
460442
461-
462- // Unread messages count
463- //
464443 it ( 'can request unread messages count' , function ( done ) {
465444 var params = { chat_dialog_ids : [ dialogId ] } ;
466445
@@ -473,15 +452,10 @@ describe('Chat API', function() {
473452
474453 done ( ) ;
475454 }
476-
477455 } ) ;
478456 } , REST_REQUESTS_TIMEOUT ) ;
479457
480-
481- // Message delete
482- //
483458 it ( 'can delete a message' , function ( done ) {
484-
485459 console . log ( "messageId: " + messageId ) ;
486460
487461 QB . chat . message . delete ( [ messageId , "notExistentId" ] , { force : 1 } , function ( err , res ) {
@@ -492,13 +466,9 @@ describe('Chat API', function() {
492466 }
493467
494468 messageId = null ;
495-
496469 } ) ;
497470 } , REST_REQUESTS_TIMEOUT ) ;
498471
499-
500- // Dialog delete
501- //
502472 it ( 'can delete a dialog (group)' , function ( done ) {
503473 QB . chat . dialog . delete ( [ dialogId , "notExistentId" ] , { force : 1 } , function ( err , res ) {
504474 if ( err ) {
@@ -510,7 +480,6 @@ describe('Chat API', function() {
510480
511481 done ( ) ;
512482 }
513-
514483 } ) ;
515484 } , REST_REQUESTS_TIMEOUT ) ;
516485 } ) ;
0 commit comments