player.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. var env = require('../env');
  17. var quick = require('quick-pomelo');
  18. var P = quick.Promise;
  19. var logger = quick.logger.getLogger('test', __filename);
  20. describe('player test', function(){
  21. beforeEach(env.initMemdbSync);
  22. afterEach(env.closeMemdbSync);
  23. it('create/remove/connect/disconnect', function(cb){
  24. var app = env.createApp('player-server-1', 'player');
  25. return P.try(function(){
  26. return P.promisify(app.start, app)();
  27. })
  28. .then(function(){
  29. var playerController = app.controllers.player;
  30. var area = app.controllers.area;
  31. var goose = app.memdb.goose;
  32. return goose.transaction(function(){
  33. var playerId = null;
  34. return P.try(function(){
  35. return playerController.createAsync({name : 'rain'});
  36. })
  37. .then(function(ret){
  38. playerId = ret;
  39. return playerController.connectAsync(playerId, 'c1');
  40. })
  41. .then(function(){
  42. return playerController.pushAsync(playerId, 'notify', 'content', true);
  43. })
  44. .then(function(){
  45. return playerController.getMsgsAsync(playerId, 0)
  46. .then(function(ret){
  47. ret.length.should.eql(1);
  48. ret[0].msg.should.eql('content');
  49. });
  50. })
  51. .then(function(){
  52. return playerController.disconnectAsync(playerId);
  53. })
  54. .then(function(){
  55. return playerController.removeAsync(playerId);
  56. });
  57. }, app.getServerId());
  58. })
  59. .then(function(){
  60. return P.promisify(app.stop, app)();
  61. })
  62. .nodeify(cb);
  63. });
  64. });