Kouhei Sutou
null+****@clear*****
Tue Jan 21 18:36:37 JST 2014
Kouhei Sutou 2014-01-21 18:36:37 +0900 (Tue, 21 Jan 2014) New Revision: 991e77a17328a4cdc150c271f06c58f2bb3a16bc https://github.com/droonga/express-droonga/commit/991e77a17328a4cdc150c271f06c58f2bb3a16bc Message: test: extract override case Modified files: test/adapter/http.test.js test/adapter/http/register.test.js Modified: test/adapter/http.test.js (+2 -30) =================================================================== --- test/adapter/http.test.js 2014-01-21 18:29:20 +0900 (1bbcd10) +++ test/adapter/http.test.js 2014-01-21 18:36:37 +0900 (dc54b8c) @@ -14,28 +14,6 @@ var groongaAPI = require('../../lib/adapter/api/groonga'); suite('HTTP Adapter', function() { test('registration of plugin commands', function() { - var basePlugin = { - postCommand: new command.HTTPRequestResponse({ - method: 'POST', - path: '/post' - }), - deleteCommand: new command.HTTPRequestResponse({ - method: 'DELETE', - path: '/delete' - }), - ignored: new command.SocketCommand() - }; - var overridingPlugin = { - postCommand: new command.HTTPRequestResponse({ - method: 'POST', - path: '/post/overridden' - }), - deleteCommand: new command.HTTPRequestResponse({ - method: 'DELETE', - path: '/delete/overridden' - }) - }; - var application = express(); var registeredCommands = httpAdapter.register(application, { prefix: '', @@ -44,9 +22,7 @@ suite('HTTP Adapter', function() { api.API_REST, api.API_SOCKET_IO, api.API_GROONGA, - api.API_DROONGA, - basePlugin, - overridingPlugin + api.API_DROONGA ] }); @@ -64,11 +40,7 @@ suite('HTTP Adapter', function() { { name: 'droonga', definition: droongaAPI.droonga }, { name: 'droonga-streaming:watch', - definition: droongaAPI["droonga-streaming:watch"] }, - { name: 'postCommand', - definition: overridingPlugin.postCommand }, - { name: 'deleteCommand', - definition: overridingPlugin.deleteCommand }]); + definition: droongaAPI["droonga-streaming:watch"] }]); }); suite('registeration', function() { Modified: test/adapter/http/register.test.js (+37 -9) =================================================================== --- test/adapter/http/register.test.js 2014-01-21 18:29:20 +0900 (e1f9523) +++ test/adapter/http/register.test.js 2014-01-21 18:36:37 +0900 (df8b183) @@ -48,14 +48,12 @@ suite('adapter/http.register', function() { return paths; }; - function register(commandSet) { + function register(plugins) { var application = new StubApplication(); httpAdapter.register(application, { prefix: '', connection: utils.createStubbedBackendConnection(), - plugins: [ - commandSet - ] + plugins: plugins }); return application.paths(); } @@ -65,7 +63,7 @@ suite('adapter/http.register', function() { var noMethodCommand = new command.HTTPRequestResponse({ path: '/no-method' }); - assert.deepEqual(register({ 'no-method': noMethodCommand }), + assert.deepEqual(register([{ 'no-method': noMethodCommand }]), { 'get': ['/no-method'] }); }); @@ -74,7 +72,7 @@ suite('adapter/http.register', function() { path: '/get', method: 'GET' }); - assert.deepEqual(register({ 'get-method': getMethodCommand }), + assert.deepEqual(register([{ 'get-method': getMethodCommand }]), { 'get': ['/get'] }); }); @@ -83,7 +81,7 @@ suite('adapter/http.register', function() { path: '/post', method: 'POST' }); - assert.deepEqual(register({ 'post-method': postMethodCommand }), + assert.deepEqual(register([{ 'post-method': postMethodCommand }]), { 'post': ['/post'] }); }); @@ -92,7 +90,7 @@ suite('adapter/http.register', function() { path: '/put', method: 'PUT' }); - assert.deepEqual(register({ 'put-method': putMethodCommand }), + assert.deepEqual(register([{ 'put-method': putMethodCommand }]), { 'put': ['/put'] }); }); @@ -101,10 +99,40 @@ suite('adapter/http.register', function() { path: '/delete', method: 'DELETE' }); - assert.deepEqual(register({ 'delete-method': deleteMethodCommand }), + assert.deepEqual(register([{ 'delete-method': deleteMethodCommand }]), { 'delete': ['/delete'] }); }); }); + + suite('override', function() { + test('same method', function() { + var command1 = new command.HTTPRequestResponse({ + path: '/command1', + method: 'POST' + }); + var command2 = new command.HTTPRequestResponse({ + path: '/command2', + method: 'POST' + }); + assert.deepEqual(register([{ 'command': command1 }, + { 'command': command2 }]), + { 'post': ['/command2'] }); + }); + + test('different method', function() { + var command1 = new command.HTTPRequestResponse({ + path: '/command1', + method: 'GET' + }); + var command2 = new command.HTTPRequestResponse({ + path: '/command2', + method: 'POST' + }); + assert.deepEqual(register([{ 'command': command1 }, + { 'command': command2 }]), + { 'post': ['/command2'] }); + }); + }); }); }); -------------- next part -------------- HTML����������������������������...Download