YUKI Hiroshi
null+****@clear*****
Fri Jan 18 15:15:14 JST 2013
YUKI Hiroshi 2013-01-18 15:15:14 +0900 (Fri, 18 Jan 2013) New Revision: 974aff0c024a5fc8a42ef5de94107360d4450c3a https://github.com/groonga/express-kotoumi/commit/974aff0c024a5fc8a42ef5de94107360d4450c3a Log: Create unique id with internal counter Modified files: lib/backend-adaptor.js test/rest-api.test.js Modified: lib/backend-adaptor.js (+2 -1) =================================================================== --- lib/backend-adaptor.js 2013-01-17 15:57:36 +0900 (c376b3d) +++ lib/backend-adaptor.js 2013-01-18 15:15:14 +0900 (77bb252) @@ -75,8 +75,9 @@ Connection.prototype._handleMessage = function(envelope) { } }; +var count = 0; function createId() { - return Date.now() + ':' + Math.round(Math.random() * 65536); + return Date.now() + ':' + (count++); } function getCurrentTime() { Modified: test/rest-api.test.js (+56 -0) =================================================================== --- test/rest-api.test.js 2013-01-17 15:57:36 +0900 (9162ee1) +++ test/rest-api.test.js 2013-01-18 15:15:14 +0900 (6819744) @@ -117,5 +117,61 @@ suite('REST API', function() { onReceive.trigger({ responseMessage: true }); fakeResponse.assertThrows(); }); + + suite('default handlers', function() { + var server; + + teardown(function() { + if (server) { + server.close(); + } + server = undefined; + }); + + test('search', function(done) { + var receiverCallback = {}; + var connection = { + emitMessage: function(type, message, callback) { + this.emitMessageCalledArguments.push({ + type: type, + message: message, + callback: callback + }); + }, + emitMessageCalledArguments: [] + }; + var application = express(); + application.kotoumi({ + prefix: '', + connection: connection + }); + server = utils.setupServer(application); + + utils.get('/tables/foo?query=bar'); + + setTimeout(function() { + try { + assert.equal(1, connection.emitMessageCalledArguments.length); + var args = connection.emitMessageCalledArguments[0]; + assert.equal(args.type, 'search'); + + var expected = { + queries: { + result: { + source: 'foo', + query: 'bar', + output: utils.outputAll + } + } + }; + assert.equalJSON(args.message, expected); + + done(); + } catch(error) { + done(error); + } + }, 100); + }); + }); }); -------------- next part -------------- HTML����������������������������...다운로드