'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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ritmatter