e2e.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 quick = require('quick-pomelo');
  17. var P = quick.Promise;
  18. var logger = quick.logger.getLogger('test', __filename);
  19. var main = function(){
  20. var gateServer = {host : '127.0.0.1', port : 3010};
  21. var connectorServer = null;
  22. var client = null;
  23. var playerId = 'p1', areaId = 'a1';
  24. return P.try(function(){
  25. client = quick.mocks.client(gateServer);
  26. return client.connect();
  27. })
  28. .then(function(){
  29. return client.request('gate.gateHandler.getConnector', null);
  30. })
  31. .then(function(ret){
  32. connectorServer = ret;
  33. return client.disconnect();
  34. })
  35. .then(function(){
  36. // Connect to connector
  37. client = quick.mocks.client(connectorServer);
  38. return client.connect();
  39. })
  40. .then(function(){
  41. return client.request('player.playerHandler.create', {opts : {_id : playerId}});
  42. })
  43. .then(function(){
  44. var token = playerId;
  45. return client.request('connector.entryHandler.login', {token : token});
  46. })
  47. .then(function(){
  48. return client.request('area.areaHandler.create', {opts : {_id : areaId}});
  49. })
  50. .then(function(){
  51. return client.request('area.areaHandler.join', {areaId : areaId});
  52. })
  53. .then(function(){
  54. client.on('notify', function(msg){
  55. logger.info('on notify %j', msg);
  56. });
  57. return client.request('area.areaHandler.push', {areaId : areaId, route : 'notify', msg : 'hello', persistent : true});
  58. })
  59. .then(function(){
  60. return client.request('area.areaHandler.getMsgs', {areaId : areaId, seq : 0})
  61. .then(function(msgs){
  62. logger.info('%j', msgs);
  63. });
  64. })
  65. .then(function(){
  66. return client.request('area.areaHandler.quit', {areaId : areaId});
  67. })
  68. .then(function(){
  69. return client.request('area.areaHandler.remove', {areaId : areaId});
  70. })
  71. .then(function(){
  72. return client.request('player.playerHandler.remove', {});
  73. })
  74. .then(function(){
  75. return client.disconnect();
  76. })
  77. .catch(function(e){
  78. logger.error('%j', e);
  79. })
  80. .finally(function(){
  81. process.exit();
  82. });
  83. };
  84. if (require.main === module) {
  85. main();
  86. }