This commit is contained in:
2025-05-25 19:02:18 +00:00
parent 5b33623c2d
commit 4c9fd22a86
20 changed files with 1551 additions and 1451 deletions

View File

@@ -44,14 +44,36 @@ tap.test('CCM-01: Basic TCP Connection - should connect to SMTP server', async (
});
tap.test('CCM-01: Basic TCP Connection - should report connection status', async () => {
expect(smtpClient.isConnected()).toBeTrue();
// After verify(), connection is closed, so isConnected should be false
expect(smtpClient.isConnected()).toBeFalse();
const poolStatus = smtpClient.getPoolStatus();
console.log('📊 Connection pool status:', poolStatus);
// For non-pooled connection, should have 1 connection
expect(poolStatus.total).toBeGreaterThanOrEqual(1);
expect(poolStatus.active).toBeGreaterThanOrEqual(0);
// After verify(), pool should be empty
expect(poolStatus.total).toEqual(0);
expect(poolStatus.active).toEqual(0);
// Test that connection status is correct during actual email send
const email = new (await import('../../../ts/mail/core/classes.email.js')).Email({
from: 'sender@example.com',
to: ['recipient@example.com'],
subject: 'Connection status test',
text: 'Testing connection status'
});
// During sendMail, connection should be established
const sendPromise = smtpClient.sendMail(email);
// Check status while sending (might be too fast to catch)
const duringStatus = smtpClient.getPoolStatus();
console.log('📊 Pool status during send:', duringStatus);
await sendPromise;
// After send, connection might be pooled or closed
const afterStatus = smtpClient.getPoolStatus();
console.log('📊 Pool status after send:', afterStatus);
});
tap.test('CCM-01: Basic TCP Connection - should handle multiple connect/disconnect cycles', async () => {
@@ -79,48 +101,40 @@ tap.test('CCM-01: Basic TCP Connection - should handle multiple connect/disconne
});
tap.test('CCM-01: Basic TCP Connection - should fail with invalid host', async () => {
let errorThrown = false;
const invalidClient = createSmtpClient({
host: 'invalid.host.that.does.not.exist',
port: 2525,
secure: false,
connectionTimeout: 3000
});
try {
const invalidClient = createSmtpClient({
host: 'invalid.host.that.does.not.exist',
port: 2525,
secure: false,
connectionTimeout: 3000
});
await invalidClient.verify();
} catch (error) {
errorThrown = true;
expect(error).toBeInstanceOf(Error);
console.log('✅ Correctly failed to connect to invalid host');
}
// verify() returns false on connection failure, doesn't throw
const result = await invalidClient.verify();
expect(result).toBeFalse();
console.log('✅ Correctly failed to connect to invalid host');
expect(errorThrown).toBeTrue();
await invalidClient.close();
});
tap.test('CCM-01: Basic TCP Connection - should timeout on unresponsive port', async () => {
let errorThrown = false;
const startTime = Date.now();
try {
const timeoutClient = createSmtpClient({
host: testServer.hostname,
port: 9999, // Port that's not listening
secure: false,
connectionTimeout: 2000
});
await timeoutClient.verify();
} catch (error) {
errorThrown = true;
const duration = Date.now() - startTime;
expect(error).toBeInstanceOf(Error);
expect(duration).toBeLessThan(3000); // Should timeout within 3 seconds
console.log(`✅ Connection timeout working correctly (${duration}ms)`);
}
const timeoutClient = createSmtpClient({
host: testServer.hostname,
port: 9999, // Port that's not listening
secure: false,
connectionTimeout: 2000
});
expect(errorThrown).toBeTrue();
// verify() returns false on connection failure, doesn't throw
const result = await timeoutClient.verify();
expect(result).toBeFalse();
const duration = Date.now() - startTime;
expect(duration).toBeLessThan(3000); // Should timeout within 3 seconds
console.log(`✅ Connection timeout working correctly (${duration}ms)`);
await timeoutClient.close();
});
tap.test('cleanup - close SMTP client', async () => {