Skip to content

Commit 584b1d3

Browse files
committed
test(integration): add optional oauth2 smtp send scenario 🛂
- Add oauth2 integration send test behind env toggle - Add oauth2 smtp config fixture with access token input - Add password auth type in existing smtp integration fixtures
1 parent 39f2e2c commit 584b1d3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/Integration.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import * as App from '@app/index.ts'
33

44
const etherealUser = Deno.env.get('ETHEREAL_USER')
55
const etherealPass = Deno.env.get('ETHEREAL_PASS')
6+
const oauth2AccessToken = Deno.env.get('SMTP_OAUTH2_ACCESS_TOKEN')
67
const runSecureSmtpTest = Deno.env.get('RUN_SECURE_SMTP_TEST') === 'true'
8+
const runOAuth2SmtpTest = Deno.env.get('RUN_OAUTH2_SMTP_TEST') === 'true'
79
const hasEtherealCredentials = Boolean(etherealUser && etherealPass)
810

911
const smtpConfig = {
1012
host: 'smtp.ethereal.email',
1113
port: 587,
1214
secure: false,
1315
auth: {
16+
type: 'password' as const,
1417
user: etherealUser ?? '',
1518
pass: etherealPass ?? ''
1619
}
@@ -21,11 +24,23 @@ const secureSmtpConfig = {
2124
port: 465,
2225
secure: true,
2326
auth: {
27+
type: 'password' as const,
2428
user: etherealUser ?? '',
2529
pass: etherealPass ?? ''
2630
}
2731
}
2832

33+
const oauth2SmtpConfig = {
34+
host: 'smtp.ethereal.email',
35+
port: 587,
36+
secure: false,
37+
auth: {
38+
type: 'oauth2' as const,
39+
user: etherealUser ?? '',
40+
accessToken: oauth2AccessToken ?? ''
41+
}
42+
}
43+
2944
Deno.test('create transporter with Ethereal SMTP config', () => {
3045
if (!hasEtherealCredentials) {
3146
return
@@ -185,3 +200,16 @@ Deno.test('send email with string attachment content and 7bit encoding', async (
185200
]
186201
})
187202
})
203+
204+
Deno.test('send email over oauth2 configuration', async () => {
205+
if (!etherealUser || !oauth2AccessToken || !runOAuth2SmtpTest) {
206+
return
207+
}
208+
const sender = App.mailer.transporter(oauth2SmtpConfig)
209+
await sender.send({
210+
from: `Mailer Integration <${etherealUser}>`,
211+
to: `Mailer Integration <${etherealUser}>`,
212+
subject: 'Deno-Mailer oauth2 integration test',
213+
text: 'OAuth2 send test'
214+
})
215+
})

0 commit comments

Comments
 (0)