[Groonga-commit] groonga/express-kotoumi [master] Update tests based on new plugin system (work in progress)

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Feb 5 18:20:18 JST 2013


YUKI Hiroshi	2013-02-05 18:20:18 +0900 (Tue, 05 Feb 2013)

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

  Log:
    Update tests based on new plugin system (work in progress)

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

  Modified: lib/frontend/rest-adaptor.js (+3 -0)
===================================================================
--- lib/frontend/rest-adaptor.js    2013-02-05 18:05:03 +0900 (32ebc8c)
+++ lib/frontend/rest-adaptor.js    2013-02-05 18:20:18 +0900 (0f5566c)
@@ -5,6 +5,7 @@ function createHandler(params) {
   var connection = params.connection;
   var command = params.command;
   var requestBuilder = params.requestBuilder;
+  var responseBuilder = params.responseBuilder;
 
   if (!requestBuilder)
     throw new Error('no request builder for ' + command);
@@ -22,6 +23,8 @@ function createHandler(params) {
           response.send(body, error);
         } else {
           var body = responseMessage.body;
+          if (responseBuilder)
+            body = responseBuilder(body);
           response.contentType('application/json');
           response.send(body, 200);
         }

  Modified: test/frontend-rest-adaptor.test.js (+14 -14)
===================================================================
--- test/frontend-rest-adaptor.test.js    2013-02-05 18:05:03 +0900 (8610239)
+++ test/frontend-rest-adaptor.test.js    2013-02-05 18:20:18 +0900 (dcdf2e1)
@@ -69,16 +69,16 @@ suite('REST API', function() {
   });
 
   suite('registeration', function() {
-    function createHandlerFactory(type) {
-      return function() {
-        return function(request, response) {
-          response.contentType('text/plain');
-          response.send(type + ' OK', 200);
-        };
+    function defineCommand(command, path) {
+      return {
+        method: 'GET',
+        path: path,
+        requestBuilder: function() { return command + ' requested'; },
+        responseBuilder: function() { return command + ' OK'; }
       };
     }
-    var handlersFactory = {
-      search: createHandlerFactory('search')
+    var testPlugin = {
+      api: defineCommand('api', '/path/to/api')
     };
 
     var server;
@@ -95,15 +95,15 @@ suite('REST API', function() {
       restAdaptor.register(application, {
         prefix:     '',
         connection: fakeConnection,
-        handlers:   handlersFactory
+        plugins:    [testPlugin]
       });
       utils.setupServer(application)
         .next(function(newServer) {
           server = newServer;
         })
-        .get('/tables/foobar')
+        .get('/path/to/api')
         .next(function(response) {
-          assert.equal(response.body, 'search OK');
+          assert.equal(response.body, 'api OK');
           done();
         })
         .error(function(error) {
@@ -117,15 +117,15 @@ suite('REST API', function() {
       restAdaptor.register(application, {
         prefix:     '/path/to/kotoumi',
         connection: fakeConnection,
-        handlers:   handlersFactory
+        plugins:    [testPlugin]
       });
       utils.setupServer(application)
         .next(function(newServer) {
           server = newServer;
         })
-        .get('/path/to/kotoumi/tables/foobar')
+        .get('/path/to/kotoumi/path/to/api')
         .next(function(response) {
-          assert.equal(response.body, 'search OK');
+          assert.equal(response.body, 'api OK');
           done();
         })
         .error(function(error) {
-------------- next part --------------
HTML����������������������������...
Télécharger 



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