1- import type { SimplifiedSQSClient } from "../../src/drivers/sqs.js" ;
2- import type {
3- ReceiveMessageCommandOutput ,
4- DeleteMessageCommandOutput ,
5- ChangeMessageVisibilityCommandOutput
1+ import {
2+ SendMessageCommand ,
3+ ReceiveMessageCommand ,
4+ DeleteMessageCommand ,
5+ ChangeMessageVisibilityCommand ,
6+ type SendMessageCommandOutput ,
7+ type ReceiveMessageCommandOutput ,
8+ type DeleteMessageCommandOutput ,
9+ type ChangeMessageVisibilityCommandOutput
610} from "@aws-sdk/client-sqs" ;
711
812interface StoredMessage {
@@ -16,7 +20,7 @@ interface StoredMessage {
1620 visibilityTimeoutUntil ?: Date ;
1721}
1822
19- export class TestSQSClient implements SimplifiedSQSClient {
23+ export class TestSQSClient {
2024 private messages : Map < string , StoredMessage > = new Map ( ) ;
2125 private nextMessageId = 1 ;
2226 private nextReceiptHandle = 1 ;
@@ -31,12 +35,25 @@ export class TestSQSClient implements SimplifiedSQSClient {
3135
3236 public deletedMessages : Array < { MessageId : string ; ReceiptHandle : string } > = [ ] ;
3337
34- async sendMessage ( params : {
38+ async send ( command : SendMessageCommand | ReceiveMessageCommand | DeleteMessageCommand | ChangeMessageVisibilityCommand ) : Promise < any > {
39+ if ( command instanceof SendMessageCommand ) {
40+ return this . handleSendMessage ( command . input as any ) ;
41+ } else if ( command instanceof ReceiveMessageCommand ) {
42+ return this . handleReceiveMessage ( command . input as any ) ;
43+ } else if ( command instanceof DeleteMessageCommand ) {
44+ return this . handleDeleteMessage ( command . input as any ) ;
45+ } else if ( command instanceof ChangeMessageVisibilityCommand ) {
46+ return this . handleChangeMessageVisibility ( command . input as any ) ;
47+ }
48+ throw new Error ( `Unsupported command type: ${ ( command as any ) . constructor . name } ` ) ;
49+ }
50+
51+ private async handleSendMessage ( params : {
3552 QueueUrl : string ;
3653 MessageBody : string ;
3754 DelaySeconds ?: number ;
3855 MessageAttributes ?: Record < string , { StringValue : string ; DataType : string } > ;
39- } ) : Promise < { MessageId : string , $metadata : any } > {
56+ } ) : Promise < SendMessageCommandOutput > {
4057 const messageId = this . nextMessageId . toString ( ) ;
4158 this . nextMessageId ++ ;
4259
@@ -65,11 +82,14 @@ export class TestSQSClient implements SimplifiedSQSClient {
6582
6683 return {
6784 MessageId : messageId ,
68- $metadata : { }
85+ $metadata : {
86+ httpStatusCode : 200 ,
87+ requestId : 'test-request-id'
88+ }
6989 } ;
7090 }
7191
72- async receiveMessage ( params : {
92+ private async handleReceiveMessage ( params : {
7393 QueueUrl : string ;
7494 MaxNumberOfMessages ?: number ;
7595 WaitTimeSeconds ?: number ;
@@ -106,7 +126,7 @@ export class TestSQSClient implements SimplifiedSQSClient {
106126 } as ReceiveMessageCommandOutput ;
107127 }
108128
109- async deleteMessage ( params : {
129+ private async handleDeleteMessage ( params : {
110130 QueueUrl : string ;
111131 ReceiptHandle : string ;
112132 } ) : Promise < DeleteMessageCommandOutput > {
@@ -127,7 +147,7 @@ export class TestSQSClient implements SimplifiedSQSClient {
127147 } as DeleteMessageCommandOutput ;
128148 }
129149
130- async changeMessageVisibility ( params : {
150+ private async handleChangeMessageVisibility ( params : {
131151 QueueUrl : string ;
132152 ReceiptHandle : string ;
133153 VisibilityTimeout : number ;
0 commit comments