[Groonga-commit] droonga/express-droonga at c892466 [master] test: extract HTTP method related register tests

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 21 18:20:20 JST 2014


Kouhei Sutou	2014-01-21 18:20:20 +0900 (Tue, 21 Jan 2014)

  New Revision: c89246656e11dfe00c2ee2ae59aa21dc37a18e6e
  https://github.com/droonga/express-droonga/commit/c89246656e11dfe00c2ee2ae59aa21dc37a18e6e

  Message:
    test: extract HTTP method related register tests

  Added files:
    test/adapter/http/register.test.js
  Modified files:
    test/adapter/http.test.js

  Modified: test/adapter/http.test.js (+0 -11)
===================================================================
--- test/adapter/http.test.js    2014-01-21 18:17:38 +0900 (06d9e98)
+++ test/adapter/http.test.js    2014-01-21 18:20:20 +0900 (1bbcd10)
@@ -15,13 +15,6 @@ var groongaAPI = require('../../lib/adapter/api/groonga');
 suite('HTTP Adapter', function() {
   test('registration of plugin commands', function() {
     var basePlugin = {
-      getCommand: new command.HTTPRequestResponse({
-        path: '/get'
-      }),
-      putCommand: new command.HTTPRequestResponse({
-        method: 'PUT',
-        path: '/put'
-      }),
       postCommand: new command.HTTPRequestResponse({
         method: 'POST',
         path: '/post'
@@ -72,10 +65,6 @@ suite('HTTP Adapter', function() {
                         definition: droongaAPI.droonga },
                       { name:       'droonga-streaming:watch',
                         definition: droongaAPI["droonga-streaming:watch"] },
-                      { name:       'getCommand',
-                        definition: basePlugin.getCommand },
-                      { name:       'putCommand',
-                        definition: basePlugin.putCommand },
                       { name:       'postCommand',
                         definition: overridingPlugin.postCommand },
                       { name:       'deleteCommand',

  Added: test/adapter/http/register.test.js (+118 -0) 100644
===================================================================
--- /dev/null
+++ test/adapter/http/register.test.js    2014-01-21 18:20:20 +0900 (249d055)
@@ -0,0 +1,118 @@
+var assert = require('chai').assert;
+
+var utils = require('../../test-utils');
+
+var express = require('express');
+var httpAdapter = require('../../../lib/adapter/http');
+var command = require('../../../lib/adapter/command');
+
+suite('adapter/http.register', function() {
+  suite('method', function() {
+    function StubApplication() {
+      this.getPaths    = [];
+      this.postPaths   = [];
+      this.putPaths    = [];
+      this.deletePaths = [];
+    }
+
+    StubApplication.prototype.configure = function() {
+    };
+
+    ["get", "post", "put", "delete"].forEach(function(method) {
+      StubApplication.prototype[method] = function(path, handler) {
+        this[method + "Paths"].push(path);
+      };
+    });
+
+    StubApplication.prototype.paths = function() {
+      return {
+        get:    this.getPaths,
+        post:   this.postPaths,
+        put:    this.putPaths,
+        delete: this.deletePaths
+      };
+    };
+
+    function register(commandSet) {
+      var application = new StubApplication();
+      httpAdapter.register(application, {
+        prefix:     '',
+        connection: utils.createStubbedBackendConnection(),
+        plugins: [
+          commandSet
+        ]
+      });
+      return application.paths();
+    }
+
+    test('default', function() {
+      var noMethodCommand = new command.HTTPRequestResponse({
+        path: '/no-method'
+      });
+      assert.deepEqual(register({ 'no-method': noMethodCommand }),
+                       {
+                         "get":    ['/no-method'],
+                         "post":   [],
+                         "put":    [],
+                         "delete": []
+                       });
+    });
+
+    test('get', function() {
+      var getMethodCommand = new command.HTTPRequestResponse({
+        path:   '/get',
+        method: 'GET'
+      });
+      assert.deepEqual(register({ 'get-method': getMethodCommand }),
+                       {
+                         "get":    ['/get'],
+                         "post":   [],
+                         "put":    [],
+                         "delete": []
+                       });
+    });
+
+    test('post', function() {
+      var postMethodCommand = new command.HTTPRequestResponse({
+        path:   '/post',
+        method: 'POST'
+      });
+      assert.deepEqual(register({ 'post-method': postMethodCommand }),
+                       {
+                         "get":    [],
+                         "post":   ['/post'],
+                         "put":    [],
+                         "delete": []
+                       });
+    });
+
+    test('put', function() {
+      var putMethodCommand = new command.HTTPRequestResponse({
+        path:   '/put',
+        method: 'PUT'
+      });
+      assert.deepEqual(register({ 'put-method': putMethodCommand }),
+                       {
+                         "get":    [],
+                         "post":   [],
+                         "put":    ['/put'],
+                         "delete": []
+                       });
+    });
+
+    test('delete', function() {
+      var deleteMethodCommand = new command.HTTPRequestResponse({
+        path:   '/delete',
+        method: 'DELETE'
+      });
+      assert.deepEqual(register({ 'delete-method': deleteMethodCommand }),
+                       {
+                         "get":    [],
+                         "post":   [],
+                         "put":    [],
+                         "delete": ['/delete']
+                       });
+    });
+  });
+});
+
-------------- next part --------------
HTML����������������������������...
Download 



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