Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Parameter Validation while using aws-sdk-mock

I am using aws-sdk-mock with Jest for testing AWS Lamda.

My lambda uses AWS Polly Service to convert text to speech. Following is the piece of code which I want to mock as well as do parameter validation.

var task = await polly.startSpeechSynthesisTask({
      OutputFormat: "mp3",
      Text: fullTextSSML,
      TextType: "ssml",
      Engine: audioProfile.engine,
      VoiceId: audioProfile.voice,
      OutputS3KeyPrefix: `${orgId}/${integrationId}/fa`,
      OutputS3BucketName: process.env.AUDIO_BUCKET,
      SnsTopicArn: process.env.POLLY_TASK_COMPLETED_SNS_TOPIC_ARN
    }).promise();

I have written a mock as follow.

 AWS.mock('Polly', 'startSpeechSynthesisTask', ()=>{
            return {
                SynthesisTask:{
                    TaskId: "0a4a503d-8be8-46a6-a638-1621d3405fb0"
                }
            }
        });

How do I mock this service as well as do parameter validation at the same time?

like image 572
Vikas Roy Avatar asked May 25 '26 07:05

Vikas Roy


1 Answers

I think you can do this using Sinon spies as described in the docs: https://www.npmjs.com/package/aws-sdk-mock#sinon

like image 145
ritmatter Avatar answered May 26 '26 20:05

ritmatter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!