[Groonga-commit] groonga/express-kotoumi [master] test: Add test for custom command name for REST API

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Feb 6 17:30:33 JST 2013


YUKI Hiroshi	2013-02-06 17:30:33 +0900 (Wed, 06 Feb 2013)

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

  Log:
    test: Add test for custom command name for REST API

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

  Modified: test/frontend-rest-adaptor.test.js (+50 -9)
===================================================================
--- test/frontend-rest-adaptor.test.js    2013-02-06 17:26:13 +0900 (9b2617b)
+++ test/frontend-rest-adaptor.test.js    2013-02-06 17:30:33 +0900 (ddeac01)
@@ -76,16 +76,18 @@ suite('REST API', function() {
   });
 
   suite('registeration', function() {
-    function defineCommand(command, path) {
-      return {
-        method: 'GET',
-        path: path,
-        requestBuilder: function() { return command + ' requested'; },
-        responseBuilder: function() { return command + ' OK'; }
-      };
-    }
     var testPlugin = {
-      api: defineCommand('api', '/path/to/api')
+      api: {
+        path: '/path/to/api',
+        requestBuilder: function() { return 'api requested'; },
+        responseBuilder: function() { return 'api OK'; }
+      },
+      customCommandAPI: {
+        command: 'custom',
+        path: '/path/to/customCommandAPI',
+        requestBuilder: function() { return 'customCommandAPI requested'; },
+        responseBuilder: function() { return 'customCommandAPI OK'; }
+      }
     };
 
     var connection;
@@ -184,6 +186,45 @@ suite('REST API', function() {
           done(error);
         });
     });
+
+    test('custom command name', function(done) {
+      var onReceive = {};
+      connection
+        .mock('emitMessage')
+          .takes('custom',
+                 'customCommandAPI requested',
+                 function() {},
+                 { 'timeout': null })
+          .ctrl(2, onReceive);
+
+      restAdaptor.register(application, {
+        prefix:     '',
+        connection: connection,
+        plugins:    [testPlugin]
+      });
+
+      var responseBody;
+      Deferred
+        .wait(0.01)
+        .next(function() {
+          utils.get('/path/to/customCommandAPI')
+            .next(function(response) {
+              responseBody = response.body;
+            });
+        })
+        .wait(0.01)
+        .next(function() {
+          onReceive.trigger(null, { body: 'API OK?' });
+        })
+        .wait(0.01)
+        .next(function() {
+          assert.equal(responseBody, 'customCommandAPI OK');
+          done();
+        })
+        .error(function(error) {
+          done(error);
+        });
+    });
   });
 
   suite('default commands', function() {
-------------- next part --------------
HTML����������������������������...
Download 



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