YUKI Hiroshi
null+****@clear*****
Tue Feb 5 18:00:12 JST 2013
YUKI Hiroshi 2013-02-05 18:00:12 +0900 (Tue, 05 Feb 2013) New Revision: 7c1ff5ebf09c99a9d9750eb0c5e91d577a0d47ae https://github.com/groonga/express-kotoumi/commit/7c1ff5ebf09c99a9d9750eb0c5e91d577a0d47ae Log: Add test for plugin system for REST handlers 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 17:49:46 +0900 (340de99) +++ lib/frontend/rest-adaptor.js 2013-02-05 18:00:12 +0900 (5e6d0c5) @@ -66,6 +66,7 @@ exports.register = function(application, params) { }); }); + var registeredCommands = []; Object.keys(unifiedCommandSet).forEach(function(command) { var definition = unifiedCommandSet[command]; if (!definition.method) return; // ignore not a command definition @@ -76,5 +77,7 @@ exports.register = function(application, params) { requestBuilder: definition.requestBuilder }); application[method](prefix + definition.path, handler); + registeredCommands.push({ command: command, definition: definition }); }); + return registeredCommands; } Modified: test/frontend-rest-adaptor.test.js (+48 -9) =================================================================== --- test/frontend-rest-adaptor.test.js 2013-02-05 17:49:46 +0900 (4d412cb) +++ test/frontend-rest-adaptor.test.js 2013-02-05 18:00:12 +0900 (7064c90) @@ -8,18 +8,57 @@ var restAdaptor = require('../lib/frontend/rest-adaptor'); var Connection = require('../lib/backend/connection').Connection; suite('REST API', function() { - test('registeration for given handlers', function() { - var fakeConnection = utils.createStubbedBackendConnection(); - var mockedHandlers = nodemock.mock('search') - .takes(fakeConnection) - .returns(function() {}); + test('registeration of plugin commands', function() { + var basePlugin = { + getCommand: { + method: 'GET', + path: '/get', + requestBuilder: function() {} + }, + putCommand: { + method: 'PUT', + path: '/put', + requestBuilder: function() {} + }, + postCommand: { + method: 'POST', + path: '/post', + requestBuilder: function() {} + }, + deleteCommand: { + method: 'DELETE', + path: '/delete', + requestBuilder: function() {} + } + }; + var overridingPlugin = { + postCommand: { + method: 'POST', + path: '/post/overridden', + requestBuilder: function() {} + }, + deleteCommand: { + method: 'DELETE', + path: '/delete/overridden', + requestBuilder: function() {} + } + }; + var application = express(); - restAdaptor.register(application, { + var registeredCommands = restAdaptor.register(application, { prefix: '', - connection: fakeConnection, - handlers: mockedHandlers + connection: utils.createStubbedBackendConnection(), + plugins: [ + basePlugin, + overridingPlugin + ] }); - mockedHandlers.assertThrows(); + + assert.deepEqual(registeredCommands, + [basePlugin.getCommand, + basePlugin.putCommand, + overridingPlugin.postCommand, + overridingPlugin.deleteCommand]); }); suite('registeration', function() { -------------- next part -------------- HTML����������������������������...Download