update
This commit is contained in:
@ -10,21 +10,6 @@ import {
|
||||
type IDomainRule
|
||||
} from '../ts/classes.dcrouter.js';
|
||||
|
||||
// Mock platform service for testing
|
||||
const mockPlatformService = {
|
||||
mtaService: {
|
||||
saveToLocalMailbox: async (email: any) => {
|
||||
// Mock implementation
|
||||
console.log('Mock: Saving email to local mailbox');
|
||||
return Promise.resolve();
|
||||
},
|
||||
isBounceNotification: (email: any) => false,
|
||||
processBounceNotification: async (email: any) => {
|
||||
// Mock implementation
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
tap.test('DcRouter class - Custom email port configuration', async () => {
|
||||
// Define custom port mapping
|
||||
@ -98,8 +83,8 @@ tap.test('DcRouter class - Custom email port configuration', async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create DcRouter instance with mock platform service
|
||||
const router = new DcRouter(options, mockPlatformService);
|
||||
// Create DcRouter instance
|
||||
const router = new DcRouter(options);
|
||||
|
||||
// Verify the options are correctly set
|
||||
expect(router.options.emailPortConfig).toBeTruthy();
|
||||
@ -168,46 +153,23 @@ tap.test('DcRouter class - Custom email storage path', async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create a mock MTA service with a trackable saveToLocalMailbox method
|
||||
let savedToCustomPath = false;
|
||||
const mockEmail = {
|
||||
to: ['test@example.com'],
|
||||
toRFC822String: () => 'From: sender@example.com\nTo: test@example.com\nSubject: Test\n\nTest email'
|
||||
};
|
||||
// Create DcRouter instance
|
||||
const router = new DcRouter(options);
|
||||
|
||||
const mockMtaService = {
|
||||
saveToLocalMailbox: async (email: any) => {
|
||||
console.log('Original saveToLocalMailbox called');
|
||||
return Promise.resolve();
|
||||
},
|
||||
isBounceNotification: (email: any) => false,
|
||||
processBounceNotification: async (email: any) => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
// Start the router to initialize email services
|
||||
await router.start();
|
||||
|
||||
const mockPlatformServiceWithMta = {
|
||||
mtaService: mockMtaService
|
||||
};
|
||||
// Verify that the custom email storage path was configured
|
||||
expect(router.options.emailPortConfig?.receivedEmailsPath).toEqual(customEmailsPath);
|
||||
|
||||
// Create DcRouter instance with mock platform service
|
||||
const router = new DcRouter(options, mockPlatformServiceWithMta);
|
||||
// Verify the directory exists
|
||||
expect(fs.existsSync(customEmailsPath)).toEqual(true);
|
||||
|
||||
// Import the patch function and apply it directly for testing
|
||||
const { configureEmailStorage } = await import('../ts/mail/delivery/classes.mta.patch.js');
|
||||
configureEmailStorage(mockMtaService, { receivedEmailsPath: customEmailsPath });
|
||||
// Verify unified email server was initialized
|
||||
expect(router.unifiedEmailServer).toBeTruthy();
|
||||
|
||||
// Call the patched method
|
||||
await mockMtaService.saveToLocalMailbox(mockEmail);
|
||||
|
||||
// Check if a file was created in the custom path
|
||||
const files = fs.readdirSync(customEmailsPath);
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
expect(files[0].endsWith('.eml')).toEqual(true);
|
||||
|
||||
// Verify file contents
|
||||
const fileContent = fs.readFileSync(path.join(customEmailsPath, files[0]), 'utf8');
|
||||
expect(fileContent).toContain('From: sender@example.com');
|
||||
// Stop the router
|
||||
await router.stop();
|
||||
|
||||
// Clean up
|
||||
try {
|
||||
|
Reference in New Issue
Block a user