[Groonga-commit] groonga/express-kotoumi [master] test: Update tests for REST API

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Feb 8 17:22:58 JST 2013


YUKI Hiroshi	2013-02-08 17:22:58 +0900 (Fri, 08 Feb 2013)

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

  Log:
    test: Update tests for REST API

  Modified files:
    test/frontend-rest-adaptor.test.js
    test/test-utils.js

  Modified: test/frontend-rest-adaptor.test.js (+12 -15)
===================================================================
--- test/frontend-rest-adaptor.test.js    2013-02-08 17:22:33 +0900 (ea32c4c)
+++ test/frontend-rest-adaptor.test.js    2013-02-08 17:22:58 +0900 (c1196cd)
@@ -83,14 +83,9 @@ suite('REST API', function() {
     var application;
     var server;
 
-    setup(function(done) {
-      connection = utils.createMockedBackendConnection();
+    setup(function() {
+      connection = utils.createMockedBackendConnection(testPlugin);
       application = express();
-      utils.setupServer(application)
-        .next(function(newServer) {
-          server = newServer;
-          done();
-        });
     });
 
     teardown(function() {
@@ -106,7 +101,7 @@ suite('REST API', function() {
 
     test('to the document root', function(done) {
       var onReceive = {};
-      connection
+      connection = connection
         .mock('emitMessage')
           .takes('api', 'api requested', function() {}, { 'timeout': null })
           .ctrl(2, onReceive);
@@ -118,9 +113,9 @@ suite('REST API', function() {
       });
 
       var responseBody;
-      Deferred
-        .wait(0.01)
-        .next(function() {
+      utils.setupServer(application)
+        .next(function(newServer) {
+          server = newServer;
           utils.get('/path/to/api')
             .next(function(response) {
               responseBody = response.body;
@@ -128,6 +123,7 @@ suite('REST API', function() {
         })
         .wait(0.01)
         .next(function() {
+          connection.assertThrows();
           onReceive.trigger(null, { body: 'API OK?' });
         })
         .wait(0.01)
@@ -142,7 +138,7 @@ suite('REST API', function() {
 
     test('under specified path', function(done) {
       var onReceive = {};
-      connection
+      connection = connection
         .mock('emitMessage')
           .takes('api', 'api requested', function() {}, { 'timeout': null })
           .ctrl(2, onReceive);
@@ -154,9 +150,9 @@ suite('REST API', function() {
       });
 
       var responseBody;
-      Deferred
-        .wait(0.01)
-        .next(function() {
+      utils.setupServer(application)
+        .next(function(newServer) {
+          server = newServer;
           utils.get('/path/to/kotoumi/path/to/api')
             .next(function(response) {
               responseBody = response.body;
@@ -164,6 +160,7 @@ suite('REST API', function() {
         })
         .wait(0.01)
         .next(function() {
+          connection.assertThrows();
           onReceive.trigger(null, { body: 'API OK?' });
         })
         .wait(0.01)

  Modified: test/test-utils.js (+10 -5)
===================================================================
--- test/test-utils.js    2013-02-08 17:22:33 +0900 (f73eb66)
+++ test/test-utils.js    2013-02-08 17:22:58 +0900 (56f2a88)
@@ -142,8 +142,11 @@ function createMockedBackendConnection(socketCommands) {
   socketCommands = socketCommands || {};
   var connection = nodemock;
   var onMessageControllers = {};
+  var hasSocketCommand = false;
   Object.keys(socketCommands).forEach(function(commandName) {
     var command = socketCommands[commandName];
+    hasSocketCommand = hasSocketCommand ||
+                         model.SocketCommand.isInstance(command);
     if (model.PublishSubscribe.isInstance(command)) {
       onMessageControllers[commandName] = {};
       connection = connection
@@ -153,11 +156,13 @@ function createMockedBackendConnection(socketCommands) {
     }
   });
 
-  onMessageControllers.error = {};
-  connection = connection
-    .mock('on')
-      .takes('error', function() {})
-      .ctrl(1, onMessageControllers.error);
+  if (hasSocketCommand) {
+    onMessageControllers.error = {};
+    connection = connection
+      .mock('on')
+        .takes('error', function() {})
+        .ctrl(1, onMessageControllers.error);
+  }
 
   connection.controllers = onMessageControllers;
   return connection;
-------------- next part --------------
HTML����������������������������...
Download 



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