[Groonga-commit] groonga/express-kotoumi [master] test: Update tests for socket.io API for new plugin spec

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Feb 7 19:01:35 JST 2013


YUKI Hiroshi	2013-02-07 19:01:35 +0900 (Thu, 07 Feb 2013)

  New Revision: d4c7857705b6bc130fdd765af84f00b0da6a58ff
  https://github.com/groonga/express-kotoumi/commit/d4c7857705b6bc130fdd765af84f00b0da6a58ff

  Log:
    test: Update tests for socket.io API for new plugin spec

  Modified files:
    test/express-adaptor.test.js
    test/frontend-socket.io-adaptor.test.js

  Modified: test/express-adaptor.test.js (+19 -11)
===================================================================
--- test/express-adaptor.test.js    2013-02-07 19:01:20 +0900 (5fc8b0f)
+++ test/express-adaptor.test.js    2013-02-07 19:01:35 +0900 (39d2f51)
@@ -140,7 +140,10 @@ suite('Adaption for express application', function() {
     test('front to back', function(done) {
       connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule)
         .mock('emitMessage')
-          .takes('search', { requestMessage: true });
+          .takes('search',
+                 { requestMessage: true },
+                 function() {},
+                 { timeout: 10 * 1000 });
 
       var application = express();
       utils.setupServer(application)
@@ -168,15 +171,18 @@ suite('Adaption for express application', function() {
     });
 
     test('back to front', function(done) {
-      connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule);
-      connection.emitMessage = function() {}; // stubbing
+      var onResponse = {};
+      connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule)
+        .mock('emitMessage')
+          .takes('search',
+                 { requestMessage: true },
+                 function() {},
+                 { timeout: 10 * 1000 })
+          .ctrl(2, onResponse);
 
       var clientReceiver = nodemock
             .mock('receive')
-            .takes({
-              statusCode: 200,
-              body:       { searchResult: true }
-            });
+            .takes({ searchResult: true });
 
       var application = express();
       utils.setupServer(application)
@@ -192,18 +198,20 @@ suite('Adaption for express application', function() {
         .next(function(newClientSocket) {
           clientSocket = newClientSocket;
 
-          connection.assertThrows();
-
           clientSocket.on('search.result', function(data) {
             clientReceiver.receive(data);
           });
-
+          clientSocket.emit('search', { requestMessage: true });
+        })
+        .wait(0.1)
+        .next(function() {
+          connection.assertThrows();
           var envelope = {
             type:       'search.result',
             statusCode: 200,
             body:       { searchResult: true}
           };
-          connection.controllers.message.trigger(envelope);
+          onResponse.trigger(envelope);
         })
         .wait(0.01)
         .next(function() {

  Modified: test/frontend-socket.io-adaptor.test.js (+11 -14)
===================================================================
--- test/frontend-socket.io-adaptor.test.js    2013-02-07 19:01:20 +0900 (7fcb98a)
+++ test/frontend-socket.io-adaptor.test.js    2013-02-07 19:01:35 +0900 (f2609e0)
@@ -16,14 +16,14 @@ suite('Socket.IO API', function() {
   var clientSocket;
 
   var testPlugin = {
-    'foobar': new model.SocketCommand(),
-    'builder': new model.SocketRequestResponse({
+    'foobar': new model.SocketPublishSubscribe(),
+    'builder': new model.SocketPublishSubscribe({
       toBackend: function(event, data) { return [event, 'builder request']; },
       toClient: function(event, data) { return [event, 'builder response'] }
     }),
-    'customevent': new model.SocketRequestResponse({
+    'customevent': new model.SocketPublishSubscribe({
       toBackend: function(event, data) { return ['custom', data] },
-      toClient: function(event, data) { return [event, 'custom response']; }
+      toClient: function(event, data) { return ['custom', 'custom response']; }
     }),
     'pubsub': new model.SocketPublishSubscribe()
   };
@@ -160,10 +160,7 @@ suite('Socket.IO API', function() {
 
     var clientReceiver = nodemock
           .mock('receive')
-          .takes({
-            statusCode: 200,
-            body:       { published: true }
-          });
+          .takes({ published: true });
 
     var application = express();
     utils.setupServer(application)
@@ -204,7 +201,7 @@ suite('Socket.IO API', function() {
 
   test('front to back, extra command (without builder)', function(done) {
     var extraController = {};
-    connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule);
+    connection = utils.createMockedBackendConnection(testPlugin);
 
     var application = express();
     utils.setupServer(application)
@@ -222,7 +219,7 @@ suite('Socket.IO API', function() {
 
         connection = connection
           .mock('emitMessage')
-            .takes('foobar', { requestMessage: true });
+            .takes('foobar', { requestMessage: true }, null, {});
         clientSocket.emit('foobar', { requestMessage: true });
       })
       .wait(0.01)
@@ -237,7 +234,7 @@ suite('Socket.IO API', function() {
 
   test('front to back, extra command (with builder)', function(done) {
     var extraController = {};
-    connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule);
+    connection = utils.createMockedBackendConnection(testPlugin);
 
     var mockedReceiver = nodemock
           .mock('receive')
@@ -259,7 +256,7 @@ suite('Socket.IO API', function() {
 
         connection = connection
           .mock('emitMessage')
-            .takes('builder', 'builder request');
+            .takes('builder', 'builder request', null, {});
         clientSocket.on('builder.result', function(data) {
           mockedReceiver.receive(data);
         });
@@ -286,7 +283,7 @@ suite('Socket.IO API', function() {
 
   test('front to back, extra command (custom event name)', function(done) {
     var extraController = {};
-    connection = utils.createMockedBackendConnection(utils.socketIoDefaultCommandsModule);
+    connection = utils.createMockedBackendConnection(testPlugin);
 
     var mockedReceiver = nodemock
           .mock('receive')
@@ -308,7 +305,7 @@ suite('Socket.IO API', function() {
 
         connection = connection
           .mock('emitMessage')
-            .takes('customevent', { requestMessage: true });
+            .takes('custom', { requestMessage: true }, null, {});
         clientSocket.on('custom', function(data) {
           mockedReceiver.receive(data);
         });
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index