2025-05-16 15:26:47 +00:00
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2025-05-07 22:06:55 +00:00
|
|
|
import * as plugins from '../ts/plugins.js';
|
2025-05-23 20:40:20 +00:00
|
|
|
// SzPlatformService doesn't exist in codebase - using DcRouter instead for integration tests
|
|
|
|
import DcRouter from '../ts/classes.dcrouter.js';
|
2025-05-08 01:13:54 +00:00
|
|
|
import { EmailService } from '../ts/mail/services/classes.emailservice.js';
|
|
|
|
import { BounceManager } from '../ts/mail/core/classes.bouncemanager.js';
|
2025-05-23 20:40:20 +00:00
|
|
|
import { SmtpClient } from '../ts/mail/delivery/classes.smtp.client.js';
|
|
|
|
import { SmtpServer } from '../ts/mail/delivery/smtpserver/smtp-server.js';
|
2025-05-07 22:06:55 +00:00
|
|
|
|
|
|
|
// Test the new integration architecture
|
2025-05-23 20:40:20 +00:00
|
|
|
tap.test('should be able to create an SMTP server', async (tools) => {
|
|
|
|
// Create an SMTP server
|
|
|
|
const smtpServer = new SmtpServer({
|
|
|
|
options: {
|
|
|
|
port: 10025,
|
|
|
|
hostname: 'test.example.com',
|
|
|
|
key: '',
|
|
|
|
cert: ''
|
2025-05-07 22:06:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
// Verify it was created properly
|
|
|
|
expect(smtpServer).toBeTruthy();
|
|
|
|
expect(smtpServer.options.port).toEqual(10025);
|
|
|
|
expect(smtpServer.options.hostname).toEqual('test.example.com');
|
2025-05-07 22:06:55 +00:00
|
|
|
});
|
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
tap.test('should be able to create an EmailService', async (tools) => {
|
|
|
|
// Create an email service with test config
|
|
|
|
const emailService = new EmailService({
|
|
|
|
useEmail: true,
|
|
|
|
domainRules: [],
|
|
|
|
deliveryConfig: {
|
|
|
|
smtpHosts: [{
|
|
|
|
host: 'smtp.test.com',
|
|
|
|
port: 587,
|
|
|
|
secure: false,
|
|
|
|
auth: {
|
|
|
|
user: 'test@example.com',
|
|
|
|
pass: 'testpass'
|
|
|
|
}
|
|
|
|
}]
|
2025-05-08 12:46:10 +00:00
|
|
|
}
|
|
|
|
});
|
2025-05-07 22:06:55 +00:00
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
// Verify it was created properly
|
|
|
|
expect(emailService).toBeTruthy();
|
2025-05-07 22:06:55 +00:00
|
|
|
expect(emailService.bounceManager).toBeTruthy();
|
2025-05-23 20:40:20 +00:00
|
|
|
expect(emailService.templateManager).toBeTruthy();
|
|
|
|
expect(emailService.emailValidator).toBeTruthy();
|
2025-05-07 22:06:55 +00:00
|
|
|
});
|
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
tap.test('DcRouter should support email configuration', async (tools) => {
|
|
|
|
// Create a DcRouter with email config
|
|
|
|
const dcRouter = new DcRouter({
|
|
|
|
emailConfig: {
|
|
|
|
useEmail: true,
|
|
|
|
domainRules: [{
|
|
|
|
name: 'test-rule',
|
|
|
|
match: {
|
|
|
|
senderPattern: '.*@test.com',
|
|
|
|
},
|
|
|
|
actions: []
|
|
|
|
}]
|
2025-05-07 22:06:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
// Verify it was created properly
|
|
|
|
expect(dcRouter).toBeTruthy();
|
2025-05-07 22:06:55 +00:00
|
|
|
});
|
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
tap.test('SMTP client should be able to connect to SMTP server', async (tools) => {
|
|
|
|
// Create an SMTP client
|
|
|
|
const options = {
|
|
|
|
host: 'smtp.test.com',
|
|
|
|
port: 587,
|
|
|
|
secure: false,
|
|
|
|
auth: {
|
|
|
|
user: 'test@example.com',
|
|
|
|
pass: 'testpass'
|
2025-05-08 12:46:10 +00:00
|
|
|
},
|
2025-05-23 20:40:20 +00:00
|
|
|
connectionTimeout: 5000,
|
|
|
|
socketTimeout: 5000
|
|
|
|
};
|
2025-05-07 22:06:55 +00:00
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
const smtpClient = new SmtpClient(options);
|
2025-05-07 22:06:55 +00:00
|
|
|
|
2025-05-23 20:40:20 +00:00
|
|
|
// Verify it was created properly
|
|
|
|
expect(smtpClient).toBeTruthy();
|
|
|
|
// Since options are not exposed, just verify the client was created
|
|
|
|
expect(typeof smtpClient.sendMail).toEqual('function');
|
|
|
|
expect(typeof smtpClient.getPoolStatus).toEqual('function');
|
2025-05-07 22:06:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('stop', async () => {
|
|
|
|
await tap.stopForcefully();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Export for tapbundle execution
|
|
|
|
export default tap.start();
|