YUKI Hiroshi
null+****@clear*****
Wed Feb 13 12:19:33 JST 2013
YUKI Hiroshi 2013-02-13 12:19:33 +0900 (Wed, 13 Feb 2013) New Revision: c4418ebffa51949336f2319f98ce9741c0fa0954 https://github.com/groonga/express-kotoumi/commit/c4418ebffa51949336f2319f98ce9741c0fa0954 Log: test: Create dummy envelopes by a helper function Modified files: test/backend-connection.test.js Modified: test/backend-connection.test.js (+18 -35) =================================================================== --- test/backend-connection.test.js 2013-02-13 12:12:30 +0900 (d05689d) +++ test/backend-connection.test.js 2013-02-13 12:19:33 +0900 (f11b2de) @@ -98,27 +98,29 @@ suite('Connection, simple communication', function() { } }); - function createExpectedEnvelope(type, body) { - return { - id: TypeOf('string'), - date: InstanceOf(Date), + function createEnvelope(type, body) { + var now = new Date(); + var envelope = { + id: now.getTime(), + date: now.toISOString(), replyTo: 'localhost:' + utils.testReceivePort, statusCode: 200, type: type, body: body }; + return envelope; + } + + function createExpectedEnvelope(type, body) { + var envelope = createEnvelope(type, body); + envelope.id = TypeOf('string'); + envelope.date = InstanceOf(Date); + return envelope; } function createReplyEnvelopeFor(message, type, body) { - var now = new Date(); - var response = { - id: now.getTime(), - date: now.toISOString(), - inReplyTo: message.id, - statusCode: 200, - type: type, - body: body - }; + var response = createEnvelope(type, body); + response.inReplyTo = message.id; return response; } @@ -174,28 +176,9 @@ suite('Connection, simple communication', function() { var callback = createMockedMessageCallback(); connection.on('message', callback); - var now = new Date(); - var stringMessage = { - id: now.getTime(), - date: now.toISOString(), - statusCode: 200, - type: 'string', - body: 'first call' - }; - var numericMessage = { - id: now.getTime(), - date: now.toISOString(), - statusCode: 200, - type: 'numeric', - body: 1234 - }; - var objectMessage = { - id: now.getTime(), - date: now.toISOString(), - statusCode: 200, - type: 'object', - body: { value: true } - }; + var stringMessage = createEnvelope('string', 'string'); + var numericMessage = createEnvelope('numeric', 1234); + var objectMessage = createEnvelope('object', { value: true }); callback .takes(stringMessage) .takes(numericMessage) -------------- next part -------------- HTML����������������������������... 下载