feat(storage): add comprehensive tests for StorageManager with memory, filesystem, and custom function backends
feat(email): implement EmailSendJob class for robust email delivery with retry logic and MX record resolution feat(mail): restructure mail module exports for simplified access to core and delivery functionalities
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
/**
|
||||
* Test SMTP Client Utilities for Deno
|
||||
* Provides helpers for creating and testing SMTP client functionality
|
||||
*/
|
||||
|
||||
import { smtpClientMod } from '../../ts/mail/delivery/index.ts';
|
||||
import type { ISmtpClientOptions } from '../../ts/mail/delivery/smtpclient/interfaces.ts';
|
||||
import type { SmtpClient } from '../../ts/mail/delivery/smtpclient/smtp-client.ts';
|
||||
import type { ISmtpClientOptions, SmtpClient } from '../../ts/mail/delivery/smtpclient/index.ts';
|
||||
import { Email } from '../../ts/mail/core/classes.email.ts';
|
||||
|
||||
/**
|
||||
* Create a test SMTP client with sensible defaults
|
||||
* Create a test SMTP client
|
||||
*/
|
||||
export function createTestSmtpClient(options: Partial<ISmtpClientOptions> = {}): SmtpClient {
|
||||
const defaultOptions: ISmtpClientOptions = {
|
||||
@@ -23,11 +17,10 @@ export function createTestSmtpClient(options: Partial<ISmtpClientOptions> = {}):
|
||||
maxMessages: options.maxMessages || 100,
|
||||
debug: options.debug || false,
|
||||
tls: options.tls || {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
pool: options.pool || false,
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return smtpClientMod.createSmtpClient(defaultOptions);
|
||||
}
|
||||
|
||||
@@ -49,17 +42,16 @@ export async function sendTestEmail(
|
||||
to: options.to || 'recipient@example.com',
|
||||
subject: options.subject || 'Test Email',
|
||||
text: options.text || 'This is a test email',
|
||||
html: options.html,
|
||||
html: options.html
|
||||
};
|
||||
|
||||
|
||||
const email = new Email({
|
||||
from: mailOptions.from,
|
||||
to: mailOptions.to,
|
||||
subject: mailOptions.subject,
|
||||
text: mailOptions.text,
|
||||
html: mailOptions.html,
|
||||
html: mailOptions.html
|
||||
});
|
||||
|
||||
return client.sendMail(email);
|
||||
}
|
||||
|
||||
@@ -74,9 +66,9 @@ export async function testClientConnection(
|
||||
const client = createTestSmtpClient({
|
||||
host,
|
||||
port,
|
||||
connectionTimeout: timeout,
|
||||
connectionTimeout: timeout
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
const result = await client.verify();
|
||||
return result;
|
||||
@@ -105,9 +97,9 @@ export function createAuthenticatedClient(
|
||||
auth: {
|
||||
user: username,
|
||||
pass: password,
|
||||
method: authMethod,
|
||||
method: authMethod
|
||||
},
|
||||
secure: false,
|
||||
secure: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,8 +119,8 @@ export function createTlsClient(
|
||||
port,
|
||||
secure: options.secure || false,
|
||||
tls: {
|
||||
rejectUnauthorized: options.rejectUnauthorized || false,
|
||||
},
|
||||
rejectUnauthorized: options.rejectUnauthorized || false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,14 +131,14 @@ export async function testClientPoolStatus(client: SmtpClient): Promise<any> {
|
||||
if (typeof client.getPoolStatus === 'function') {
|
||||
return client.getPoolStatus();
|
||||
}
|
||||
|
||||
|
||||
// Fallback for clients without pool status
|
||||
return {
|
||||
size: 1,
|
||||
available: 1,
|
||||
pending: 0,
|
||||
connecting: 0,
|
||||
active: 0,
|
||||
active: 0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -164,16 +156,16 @@ export async function sendConcurrentEmails(
|
||||
} = {}
|
||||
): Promise<any[]> {
|
||||
const promises = [];
|
||||
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
promises.push(
|
||||
sendTestEmail(client, {
|
||||
...emailOptions,
|
||||
subject: `${emailOptions.subject || 'Test Email'} ${i + 1}`,
|
||||
subject: `${emailOptions.subject || 'Test Email'} ${i + 1}`
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
@@ -189,17 +181,12 @@ export async function measureClientThroughput(
|
||||
subject?: string;
|
||||
text?: string;
|
||||
} = {}
|
||||
): Promise<{
|
||||
totalSent: number;
|
||||
successCount: number;
|
||||
errorCount: number;
|
||||
throughput: number;
|
||||
}> {
|
||||
): Promise<{ totalSent: number; successCount: number; errorCount: number; throughput: number }> {
|
||||
const startTime = Date.now();
|
||||
let totalSent = 0;
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
|
||||
while (Date.now() - startTime < duration) {
|
||||
try {
|
||||
await sendTestEmail(client, emailOptions);
|
||||
@@ -209,28 +196,14 @@ export async function measureClientThroughput(
|
||||
}
|
||||
totalSent++;
|
||||
}
|
||||
|
||||
|
||||
const actualDuration = (Date.now() - startTime) / 1000; // in seconds
|
||||
const throughput = totalSent / actualDuration;
|
||||
|
||||
|
||||
return {
|
||||
totalSent,
|
||||
successCount,
|
||||
errorCount,
|
||||
throughput,
|
||||
throughput
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pooled SMTP client for concurrent testing
|
||||
*/
|
||||
export function createPooledTestClient(
|
||||
options: Partial<ISmtpClientOptions> = {}
|
||||
): SmtpClient {
|
||||
return createTestSmtpClient({
|
||||
...options,
|
||||
pool: true,
|
||||
maxConnections: options.maxConnections || 5,
|
||||
maxMessages: options.maxMessages || 100,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user