Skip to content

Commit 344fe75

Browse files
committed
add test case with empty overrides and env variables being set
1 parent 8cc007c commit 344fe75

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

packages/smtppostmaster/__tests__/send.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { send, resetTransport } from '../src/index';
22
import { createSmtpCatcher } from './smtp-catcher';
33

44
describe('send', () => {
5+
const originalEnv = { ...process.env };
6+
57
afterEach(() => {
68
resetTransport();
9+
// Restore original env vars
10+
process.env = { ...originalEnv };
711
});
812

9-
it('sends email via SMTP catcher', async () => {
13+
it('sends email via SMTP catcher with overrides', async () => {
1014
const catcher = await createSmtpCatcher();
1115

1216
try {
@@ -33,4 +37,34 @@ describe('send', () => {
3337
await catcher.stop();
3438
}
3539
}, 10000);
40+
41+
it('sends email using SMTP config from environment variables', async () => {
42+
const catcher = await createSmtpCatcher();
43+
44+
// Set SMTP config via environment variables
45+
process.env.SMTP_HOST = catcher.host;
46+
process.env.SMTP_PORT = String(catcher.port);
47+
process.env.SMTP_SECURE = 'false';
48+
process.env.SMTP_FROM = 'env-sender@example.com';
49+
50+
// Clear cached transport to pick up new env vars
51+
resetTransport();
52+
53+
try {
54+
// Send without overrides - should use env vars
55+
await send({
56+
to: 'recipient@example.com',
57+
subject: 'Email from env config',
58+
text: 'This email was sent using env var configuration.'
59+
});
60+
61+
const message = await catcher.waitForMessage(5000);
62+
63+
expect(message.raw).toContain('Subject: Email from env config');
64+
expect(message.raw).toContain('This email was sent using env var configuration.');
65+
expect(message.raw).toContain('From: env-sender@example.com');
66+
} finally {
67+
await catcher.stop();
68+
}
69+
}, 10000);
3670
});

0 commit comments

Comments
 (0)