This commit is contained in:
2025-05-23 20:40:20 +00:00
parent a7438a7cd6
commit f651cd1c2f
5 changed files with 73 additions and 275 deletions

View File

@ -1,123 +1,95 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as plugins from '../ts/plugins.js';
import { SzPlatformService } from '../ts/classes.platformservice.js';
import { MtaService } from '../ts/mail/delivery/classes.mta.js';
// SzPlatformService doesn't exist in codebase - using DcRouter instead for integration tests
import DcRouter from '../ts/classes.dcrouter.js';
import { EmailService } from '../ts/mail/services/classes.emailservice.js';
import { BounceManager } from '../ts/mail/core/classes.bouncemanager.js';
import DcRouter from '../ts/classes.dcrouter.js';
import { SmtpClient } from '../ts/mail/delivery/classes.smtp.client.js';
import { SmtpServer } from '../ts/mail/delivery/smtpserver/smtp-server.js';
// Test the new integration architecture
tap.test('should be able to create an independent MTA service', async (tools) => {
// Create an independent MTA service
const mta = new MtaService(undefined, {
smtp: {
port: 10025, // Use a different port for testing
hostname: 'test.example.com'
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: ''
}
});
// Verify it was created properly without a platform service reference
expect(mta).toBeTruthy();
expect(mta.platformServiceRef).toBeUndefined();
// Even without a platform service, it should have its own SMTP rule engine
expect(mta.smtpRuleEngine).toBeTruthy();
// Verify it was created properly
expect(smtpServer).toBeTruthy();
expect(smtpServer.options.port).toEqual(10025);
expect(smtpServer.options.hostname).toEqual('test.example.com');
});
tap.test('should be able to create an EmailService with an existing MTA', async (tools) => {
// Create a platform service with test config
const platformService = new SzPlatformService({
id: 'test-platform-service',
version: '1.0.0',
environment: 'test',
name: 'TestPlatformService',
enabled: true,
logging: {
level: 'info',
structured: true,
correlationTracking: true
},
server: {
enabled: false // Disable server for tests
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'
}
}]
}
});
// Create a shared bounce manager
const bounceManager = new BounceManager();
// Create an independent MTA service
const mta = new MtaService(undefined, {
smtp: {
port: 10025, // Use a different port for testing
}
});
// Manually set the bounce manager for testing
// @ts-ignore - adding property for testing
mta.bounceManager = bounceManager;
// Create an email service that uses the independent MTA
// @ts-ignore - passing a third argument to the constructor
const emailService = new EmailService(platformService, {}, mta);
// Manually set the mtaService property
emailService.mtaService = mta;
// Verify relationships
expect(emailService.mtaService === mta).toBeTrue();
// Verify it was created properly
expect(emailService).toBeTruthy();
expect(emailService.bounceManager).toBeTruthy();
// MTA should not have a direct platform service reference
expect(mta.platformServiceRef).toBeUndefined();
// But it should have access to bounce manager
// @ts-ignore - accessing property for testing
expect(mta.bounceManager === bounceManager).toBeTrue();
expect(emailService.templateManager).toBeTruthy();
expect(emailService.emailValidator).toBeTruthy();
});
tap.test('MTA service should have SMTP rule engine', async (tools) => {
// Create an independent MTA service
const mta = new MtaService(undefined, {
smtp: {
port: 10025, // Use a different port for testing
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: []
}]
}
});
// Verify the MTA has an SMTP rule engine
expect(mta.smtpRuleEngine).toBeTruthy();
// Verify it was created properly
expect(dcRouter).toBeTruthy();
});
tap.test('platform service should support having an MTA service', async (tools) => {
// Create a platform service with test config
const platformService = new SzPlatformService({
id: 'test-platform-service',
version: '1.0.0',
environment: 'test',
name: 'TestPlatformService',
enabled: true,
logging: {
level: 'info',
structured: true,
correlationTracking: true
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'
},
server: {
enabled: false // Disable server for tests
}
});
connectionTimeout: 5000,
socketTimeout: 5000
};
// Create MTA - don't await start() to avoid binding to ports
platformService.mtaService = new MtaService(platformService, {
smtp: {
port: 10025, // Use a different port for testing
}
});
const smtpClient = new SmtpClient(options);
// Create email service using the platform
platformService.emailService = new EmailService(platformService);
// Verify the MTA has a reference to the platform service
expect(platformService.mtaService).toBeTruthy();
expect(platformService.mtaService.platformServiceRef).toBeTruthy();
// 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');
});
tap.test('stop', async () => {