3

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?

Lin Du
  • 88,126
  • 95
  • 281
  • 483
Vikas Roy
  • 854
  • 2
  • 10
  • 25

1 Answers1

1

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

ritmatter
  • 3,448
  • 4
  • 24
  • 43