This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f349bb
commit 686d7b6
Showing
11 changed files
with
107 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const debug = require('debug')('systemic-aws-sqs'); | ||
|
||
module.exports = client => async ({ commandParams, commandName }) => { | ||
try { | ||
debug(`Calling ${commandName}`); | ||
const data = await client[commandName](commandParams); | ||
debug(`${commandName} executed successfully`); | ||
return data; | ||
} catch (error) { | ||
debug(`Error executing ${commandName}: ${error.message}`); | ||
throw error; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const crypto = require("crypto"); | ||
|
||
const startSQSComponent = require("../helpers/startSQSComponent"); | ||
const createSQSQueue = require("../helpers/createSQSQueue"); | ||
const deleteSQSQueue = require("../helpers/deleteSQSQueue"); | ||
|
||
const getLocalstackConfig = require("../fixtures/getLocalstackConfig"); | ||
|
||
let sqs; | ||
let createQueue; | ||
let deleteQueue; | ||
|
||
describe("Systemic SQS - commandExecutor function", () => { | ||
beforeAll(async () => { | ||
sqs = await startSQSComponent(getLocalstackConfig()); | ||
createQueue = createSQSQueue(sqs); | ||
deleteQueue = deleteSQSQueue(sqs); | ||
}); | ||
|
||
it("should execute the \"getQueueUrl\" command and retrieve it", async () => { | ||
const awsAccountId = "000000000000"; | ||
const queueName = "testQName"; | ||
await createQueue(queueName); | ||
|
||
const commandParams = { QueueName: queueName, AwsAccountId: awsAccountId } | ||
const res = await sqs.commandExecutor({ commandParams, commandName: 'getQueueUrl' }); | ||
|
||
expect(res.QueueUrl).toBe(`http://localhost/${awsAccountId}/${queueName}`); | ||
|
||
await deleteQueue(queueName); | ||
}); | ||
|
||
it("should execute the \"receiveMessage\" command and receive a message from the queue", async () => { | ||
const awsAccountId = "000000000000"; | ||
const messageBody = "Example message"; | ||
const queueName = "receiveMessageQueueName"; | ||
|
||
await createQueue(queueName); | ||
|
||
const getUrlCommandParams = { QueueName: queueName, AwsAccountId: awsAccountId } | ||
const urlResponse = await sqs.commandExecutor({ commandParams: getUrlCommandParams, commandName: 'getQueueUrl' }); | ||
|
||
const sendMessageCommandParams = { QueueUrl: urlResponse.QueueUrl, MessageBody: messageBody } | ||
await sqs.commandExecutor({ commandParams: sendMessageCommandParams, commandName: 'sendMessage' }); | ||
|
||
const res = await sqs.commandExecutor({ commandParams: { QueueUrl: urlResponse.QueueUrl }, commandName: 'receiveMessage' }); | ||
|
||
expect(res.Messages).toHaveLength(1); | ||
expect(res.Messages[0].Body).toBe(messageBody); | ||
|
||
await deleteQueue(queueName); | ||
}); | ||
|
||
it("should execute the \"sendMessage\" command and send a message", async () => { | ||
const awsAccountId = "000000000000"; | ||
const messageBody = "Example message"; | ||
const queueName = "testQName1"; | ||
await createQueue(queueName); | ||
|
||
const getUrlCommandParams = { QueueName: queueName, AwsAccountId: awsAccountId } | ||
const urlResponse = await sqs.commandExecutor({ commandParams: getUrlCommandParams, commandName: 'getQueueUrl' }); | ||
|
||
const sendMessageCommandParams = { QueueUrl: urlResponse.QueueUrl, MessageBody: messageBody } | ||
const res = await sqs.commandExecutor({ commandParams: sendMessageCommandParams, commandName: 'sendMessage' }); | ||
|
||
const md5MessageBodySent = crypto | ||
.createHash("md5") | ||
.update(messageBody) | ||
.digest("hex"); | ||
expect(res.$metadata.httpStatusCode).toBe(200); //enviado | ||
expect(res.MD5OfMessageBody).toBe(md5MessageBodySent); // comprobación de md5 | ||
|
||
await deleteQueue(queueName); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
const { CreateQueueCommand } = require("@aws-sdk/client-sqs"); | ||
|
||
module.exports = (sqs) => (queueName) => sqs.client.send(new CreateQueueCommand({ QueueName: queueName })); | ||
const commandConfig = (queueName) => ({ | ||
commandParams: { | ||
QueueName: queueName | ||
}, | ||
commandName:'createQueue' | ||
}) | ||
module.exports = (sqs) => (queueName) => sqs.commandExecutor(commandConfig(queueName)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
const { DeleteQueueCommand } = require("@aws-sdk/client-sqs"); | ||
|
||
module.exports = (sqs) => (queueName) => sqs.client | ||
.send(new DeleteQueueCommand({ QueueUrl: `https://localhost/000000000000/${queueName}` })); | ||
const commandConfig = (queueName) => ({ | ||
commandParams: { | ||
QueueUrl: queueName | ||
}, | ||
commandName:'deleteQueue' | ||
}) | ||
module.exports = (sqs) => (queueName) => sqs | ||
.commandExecutor(commandConfig(`https://localhost/000000000000/${queueName}`)) |