test.group.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var should = require( 'should' );
  2. var _ = require( 'underscore' );
  3. var testConfig = require( './config' );
  4. var rongSDK = require( '../index' );
  5. var groupIDs = _.keys( testConfig.group.groupIdNamePairs );
  6. var groupNames = _.values( testConfig.group.groupIdNamePairs );
  7. describe( 'Group 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( 'Sync Group', function() {
  17. it( 'Synchornize group: should return OK', function( done ) {
  18. rongSDK.group.sync( testConfig.group.userId, testConfig.group.groupIdNamePairs, function( err, resultText ) {
  19. should.not.exists( err );
  20. var result = JSON.parse( resultText );
  21. result.code.should.equal( 200 );
  22. done();
  23. } );
  24. } );
  25. } );
  26. describe( 'Quit Group', function() {
  27. it( 'Quit group: should return OK', function( done ) {
  28. rongSDK.group.quit( testConfig.group.userId, groupIDs[0], function( err, resultText ) {
  29. should.not.exists( err );
  30. var result = JSON.parse( resultText );
  31. result.code.should.equal( 200 );
  32. done();
  33. } );
  34. } );
  35. } );
  36. describe( 'Create/Join Group', function() {
  37. it( 'Create/Join group with a single user: should return OK', function( done ) {
  38. rongSDK.group.create( testConfig.group.userId, 'MyGroupID', 'MyGroupName' , function( err, resultText ) {
  39. should.not.exists( err );
  40. var result = JSON.parse( resultText );
  41. result.code.should.equal( 200 );
  42. done();
  43. } );
  44. } );
  45. it( 'Create/Join group with multiple users: should return OK', function( done ) {
  46. rongSDK.group.join( [ testConfig.message.fromUserId, testConfig.message.toUserId ], 'MyGroupID', 'MyGroupName' , function( err, resultText ) {
  47. should.not.exists( err );
  48. var result = JSON.parse( resultText );
  49. result.code.should.equal( 200 );
  50. done();
  51. } );
  52. } );
  53. } );
  54. describe( 'Dissmiss Group', function() {
  55. it( 'Dismiss group(' + groupNames[0] + '): should return OK', function( done ) {
  56. rongSDK.group.dismiss( testConfig.group.userId, groupIDs[0], function( err, resultText ) {
  57. should.not.exists( err );
  58. var result = JSON.parse( resultText );
  59. result.code.should.equal( 200 );
  60. done();
  61. } );
  62. } );
  63. it( 'Dismiss group(' + groupNames[1] + '): should return OK', function( done ) {
  64. rongSDK.group.dismiss( testConfig.group.userId, groupIDs[1], function( err, resultText ) {
  65. should.not.exists( err );
  66. var result = JSON.parse( resultText );
  67. result.code.should.equal( 200 );
  68. done();
  69. } );
  70. } );
  71. it( 'Dismiss group(MyGroupName): should return OK', function( done ) {
  72. rongSDK.group.dismiss( testConfig.group.userId, 'MyGroupID', function( err, resultText ) {
  73. should.not.exists( err );
  74. var result = JSON.parse( resultText );
  75. result.code.should.equal( 200 );
  76. done();
  77. } );
  78. } );
  79. } );
  80. describe( 'Refresh Group', function() {
  81. var newGroupName = groupNames[0];
  82. it( 'Refresh group(' + groupNames[0] + ') to be ' + newGroupName + ': should return OK', function( done ) {
  83. rongSDK.group.refresh( groupIDs[0], newGroupName, function( err, resultText ) {
  84. should.not.exists( err );
  85. var result = JSON.parse( resultText );
  86. result.code.should.equal( 200 );
  87. done();
  88. } );
  89. } );
  90. });
  91. } );