import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2' import { expect } from 'chai' import Mailer from '../../src/Mailer/Mailer.js' import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js' const SESMock = mockAwsClient(SESv2Client) describe('SendRaw', () => { // reset mock beforeEach(() => { SESMock.reset() }) const provider = new Mailer('dev+tests@creator.co', 'ca-central-1') test('Send raw with success', async () => { const messageId = 'id-123' SESMock.on(mockAwsCommand(SendEmailCommand)).resolves( mockAwsResult({ MessageId: messageId, }) ) const res = await provider.sendRawEmail('test@test.com', 'My message', 'My subject') expect(res).is.not.null console.log(res) }) test('Send raw with success', async () => { const messageId = 'id-123' const from = 'test@test.com' const to = 'test@test2.com' const msg = 'My message' const subject = 'My subject' const cc = 'test@test3.com' const replyTo = 'test@test4.com' SESMock.on(mockAwsCommand(SendEmailCommand)).resolves( mockAwsResult({ MessageId: messageId, }) ) const res = await provider.sendRawEmail(to, msg, subject, cc, from, replyTo) expect(res).is.not.null console.log(res) }) test('Send raw with failure', async () => { SESMock.on(mockAwsCommand(SendEmailCommand)).rejects(new Error('failed!')) let res: any = null, err: any = null try { res = await provider.sendRawEmail('test@test.com', 'My message', 'My subject') } catch (e) { err = e } expect(res).is.null expect(err?.message).to.be.equals('failed!') expect(res).is.null console.log(res) }) }) export {}