test.chatroom.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var should = require( 'should' );
  2. var _ = require( 'underscore' );
  3. var testConfig = require( './config' );
  4. var rongSDK = require( '../index' );
  5. var chatroomIDs = _.keys( testConfig.chatroom.chatroomIdNamePairs );
  6. var chatroomNames = _.values( testConfig.chatroom.chatroomIdNamePairs );
  7. describe( 'Chatroom Test', function() {
  8. before( function( done ) {
  9. // Init the SDK before testing.
  10. rongSDK.init( testConfig.appKey, testConfig.appSecret );
  11. done();
  12. } );
  13. after( function( done ) {
  14. done();
  15. } );
  16. describe( 'Create Chatroom', function() {
  17. it( 'Create chatroom: should return OK', function( done ) {
  18. var chatroomIdNamePairsArray = [];
  19. _.each( chatroomIDs, function( chatroomId ) {
  20. chatroomIdNamePairsArray.push( { id : chatroomId, name : testConfig.chatroom.chatroomIdNamePairs[ chatroomId ] } );
  21. } );
  22. rongSDK.chatroom.create( chatroomIdNamePairsArray , function( err, resultText ) {
  23. should.not.exists( err );
  24. var result = JSON.parse( resultText );
  25. result.code.should.equal( 200 );
  26. done();
  27. } );
  28. } );
  29. } );
  30. describe( 'Destroy Chatroom', function() {
  31. it( 'Destroy a single chatroom: should return OK', function( done ) {
  32. rongSDK.chatroom.destroy( chatroomIDs.pop(), function( err, resultText ) {
  33. should.not.exists( err );
  34. var result = JSON.parse( resultText );
  35. result.code.should.equal( 200 );
  36. done();
  37. } );
  38. } );
  39. it( 'Destroy chatrooms: should return OK', function( done ) {
  40. rongSDK.chatroom.destroy( chatroomIDs.splice( 0, 2 ), function( err, resultText ) {
  41. should.not.exists( err );
  42. var result = JSON.parse( resultText );
  43. result.code.should.equal( 200 );
  44. done();
  45. } );
  46. } );
  47. } );
  48. describe( 'Query Chatroom', function() {
  49. it( 'Query a single chatroom: should return OK', function( done ) {
  50. rongSDK.chatroom.query( chatroomIDs[0], function( err, resultText ) {
  51. should.not.exists( err );
  52. var result = JSON.parse( resultText );
  53. result.code.should.equal( 200 );
  54. var found = _.findWhere( result.chatRooms, { chrmId : chatroomIDs[0] } );
  55. found.should.not.be.undefined;
  56. found.should.have.property( 'chrmId', chatroomIDs[0] );
  57. done();
  58. } );
  59. } );
  60. } );
  61. describe( 'Query Chatroom Users', function() {
  62. it( 'Query the users of a chatroom: should return OK', function( done ) {
  63. rongSDK.chatroom.user.query( chatroomIDs[0], function( err, resultText ) {
  64. should.not.exists( err );
  65. var result = JSON.parse( resultText );
  66. result.code.should.equal( 200 );
  67. done();
  68. } );
  69. } );
  70. } );
  71. } );