From 363459a5e5e84b5b0123364dfccc287e76f2fba9 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 19 Sep 2017 18:24:52 +0900 Subject: [PATCH] Add sendMessageBatch to server --- lib/__tests__/server.js | 32 ++++++++++++++++++++++++++++++++ lib/server.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/lib/__tests__/server.js b/lib/__tests__/server.js index 154f27b..5a5dede 100644 --- a/lib/__tests__/server.js +++ b/lib/__tests__/server.js @@ -57,6 +57,38 @@ describe('web server', () => { }) }) + describe('SendMessageBatch()', () => { + const params = { + QueueUrl: 'QueueUrl', + 'SendMessageBatchRequestEntry.1.Id': 'a', + 'SendMessageBatchRequestEntry.1.MessageBody': '1', + 'SendMessageBatchRequestEntry.2.Id': 'b', + 'SendMessageBatchRequestEntry.2.MessageBody': '2' + } + const expected = ` + + + entry.Id + SimplyImitatedSQS-MessageId-0 + c4ca4238a0b923820dcc509a6f75849b + + + + entry.Id + SimplyImitatedSQS-MessageId-1 + c81e728d9d4c2f636f067f89cc14862c + + + + SimplyImitatedSQS-RequestId + + ` + + test('XML is returned', () => { + expect(server.SendMessageBatch(params)).toBe(expected) + }) + }) + describe('ReceiveMessage()', () => { const expected = (receiptHandle) => { return ` diff --git a/lib/server.js b/lib/server.js index 7f6211b..cf0c368 100644 --- a/lib/server.js +++ b/lib/server.js @@ -47,6 +47,37 @@ class SimplyImitatedSQSHttpServer { ` } + SendMessageBatch (params) { + const entryXML = (() => { + const entries = [] + for (let i = 1; i <= 10; i++) { + if (params[`SendMessageBatchRequestEntry.${i}.Id`] && + params[`SendMessageBatchRequestEntry.${i}.MessageBody`]) { + entries.push({ + Id: params[`SendMessageBatchRequestEntry.${i}.Id`], + MessageBody: params[`SendMessageBatchRequestEntry.${i}.MessageBody`] + }) + } + } + return entries.map((entry, i) => { + this.sqs.vsq.send(entry.MessageBody) + return ` + + entry.Id + SimplyImitatedSQS-MessageId-${i} + ${this.sqs.md5_(entry.MessageBody)} + ` + }).join('\n') + })() + return ` + ${entryXML} + + + SimplyImitatedSQS-RequestId + + ` + } + ReceiveMessage (params) { const response = this.sqs.vsq.receive() return `