-
Notifications
You must be signed in to change notification settings - Fork 1
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
Filipe Torrado
committed
Mar 24, 2022
1 parent
65de65e
commit 69d3eee
Showing
7 changed files
with
8,981 additions
and
4,512 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,41 +1,30 @@ | ||
import AWSMock from 'aws-sdk-mock'; | ||
import AWS, { SQS } from 'aws-sdk'; | ||
|
||
type Options = { | ||
sendCallback?: ( | ||
params: AWS.SQS.SendMessageRequest, | ||
callback: (error: AWS.AWSError, data: Record<string, unknown>) => void | ||
) => void; | ||
deleteCallback?: ( | ||
params: AWS.SQS.DeleteMessageRequest, | ||
callback: (error: AWS.AWSError, data: Record<string, unknown>) => void | ||
) => void; | ||
}; | ||
import { AwsStub, mockClient } from 'aws-sdk-client-mock'; | ||
import { | ||
Message, | ||
ReceiveMessageCommand, | ||
ServiceInputTypes, | ||
ServiceOutputTypes, | ||
SQSClient | ||
} from '@aws-sdk/client-sqs'; | ||
|
||
export default ( | ||
messages: SQS.MessageList, | ||
{ sendCallback, deleteCallback }: Options = {} | ||
): AWS.SQS => { | ||
messages: Array<Message>, | ||
sqsClient: SQSClient | ||
): AwsStub<ServiceInputTypes, ServiceOutputTypes> => { | ||
let receiveCount = 0; | ||
|
||
AWSMock.mock('SQS', 'receiveMessage', (_params, callback) => { | ||
const RequestId = `r${receiveCount + 1}`; | ||
const sqsMock = mockClient(sqsClient); | ||
|
||
if (receiveCount >= messages.length) { | ||
// Simulate empty queue | ||
callback(null, { ResponseMetadata: { RequestId } }); | ||
} | ||
sqsMock.on(ReceiveMessageCommand).callsFake(() => { | ||
const result = { | ||
$metadata: { requestId: `r${receiveCount + 1}` }, | ||
Messages: | ||
receiveCount >= messages.length ? undefined : [messages[receiveCount]] | ||
}; | ||
receiveCount += 1; | ||
|
||
callback(null, { | ||
ResponseMetadata: { RequestId }, | ||
Messages: [messages[receiveCount]] | ||
}); | ||
|
||
receiveCount++; | ||
return result; | ||
}); | ||
|
||
AWSMock.mock('SQS', 'sendMessage', sendCallback); | ||
AWSMock.mock('SQS', 'deleteMessage', deleteCallback); | ||
|
||
return new AWS.SQS(); | ||
return sqsMock; | ||
}; |
Oops, something went wrong.