Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.6 KB

File metadata and controls

43 lines (31 loc) · 1.6 KB

@reapit-cdk/email-receiver-client

npm version npm downloads coverage: 99.02%25

This module helps you write tests which rely on receiving emails. Once you have set up @reapit-cdk/email-receiver, this module helps you interact with the dynamodb table it creates. You'll have to export the table arn and domain name from your stack and import them to be used here, using something like this.

Package Installation:

yarn add --dev @reapit-cdk/email-receiver-client
# or
npm install @reapit-cdk/email-receiver-client --save-dev

Usage

import { EmailReceiverClient } from '@reapit-cdk/email-receiver-client'
import { randomUUID } from 'crypto'

const emailClient = new EmailReceiverClient({
  // ...dynamoDbClient config
  tableArn: '', // imported emailReceiver.table.tableArn from cdk stack via export
})

const domainName = '' // imported emailReceiver.domainName from cdk stack via export

const recipient = `${randomUUID()}@${domainName}`

// ...
// Test code goes here that causes your system to send an email to that recipient
// ...

const emails = await emailClient.getRecipientEmails(recipient)
const emailWeWant = emails.find((message) => message.subject === "Something You're Testing")
if (!emailWeWant) {
  // retry a few times then throw error
}
// check emailWeWant.body is what you were expecting