Skip to content

Commit

Permalink
Merge pull request #18 from abetomo/add_sendMessageBatch_to_server
Browse files Browse the repository at this point in the history
Add sendMessageBatch to server
  • Loading branch information
abetomo authored Sep 19, 2017
2 parents 2e23c84 + 363459a commit 6d67c73
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/__tests__/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<SendMessageBatchResponse>
<SendMessageBatchResult>
<SendMessageBatchResultEntry>
<Id>entry.Id</Id>
<MessageId>SimplyImitatedSQS-MessageId-0</MessageId>
<MD5OfMessageBody>c4ca4238a0b923820dcc509a6f75849b</MD5OfMessageBody>
</SendMessageBatchResultEntry>
<SendMessageBatchResultEntry>
<Id>entry.Id</Id>
<MessageId>SimplyImitatedSQS-MessageId-1</MessageId>
<MD5OfMessageBody>c81e728d9d4c2f636f067f89cc14862c</MD5OfMessageBody>
</SendMessageBatchResultEntry>
</SendMessageBatchResult>
<ResponseMetadata>
<RequestId>SimplyImitatedSQS-RequestId</RequestId>
</ResponseMetadata>
</SendMessageBatchResponse>`

test('XML is returned', () => {
expect(server.SendMessageBatch(params)).toBe(expected)
})
})

describe('ReceiveMessage()', () => {
const expected = (receiptHandle) => {
return `<ReceiveMessageResponse>
Expand Down
31 changes: 31 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ class SimplyImitatedSQSHttpServer {
</SendMessageResponse>`
}

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 `
<SendMessageBatchResultEntry>
<Id>entry.Id</Id>
<MessageId>SimplyImitatedSQS-MessageId-${i}</MessageId>
<MD5OfMessageBody>${this.sqs.md5_(entry.MessageBody)}</MD5OfMessageBody>
</SendMessageBatchResultEntry>`
}).join('\n')
})()
return `<SendMessageBatchResponse>
<SendMessageBatchResult>${entryXML}
</SendMessageBatchResult>
<ResponseMetadata>
<RequestId>SimplyImitatedSQS-RequestId</RequestId>
</ResponseMetadata>
</SendMessageBatchResponse>`
}

ReceiveMessage (params) {
const response = this.sqs.vsq.receive()
return `<ReceiveMessageResponse>
Expand Down

0 comments on commit 6d67c73

Please sign in to comment.