2025-05-24 16:19:19 +00:00
|
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2025-05-26 04:09:29 +00:00
|
|
|
|
import { startTestServer, stopTestServer, type ITestServer } from '../../helpers/server.loader.js';
|
|
|
|
|
import { createSmtpClient } from '../../../ts/mail/delivery/smtpclient/index.js';
|
2025-05-24 16:19:19 +00:00
|
|
|
|
import { Email } from '../../../ts/mail/core/classes.email.js';
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
let testServer: ITestServer;
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
tap.test('setup test SMTP server', async () => {
|
2025-05-26 04:09:29 +00:00
|
|
|
|
testServer = await startTestServer({
|
|
|
|
|
port: 2579,
|
|
|
|
|
tlsEnabled: false,
|
|
|
|
|
authRequired: false
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
expect(testServer).toBeTruthy();
|
2025-05-26 04:09:29 +00:00
|
|
|
|
expect(testServer.port).toEqual(2579);
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
tap.test('CEP-06: Basic UTF-8 characters', async () => {
|
|
|
|
|
console.log('Testing basic UTF-8 characters');
|
|
|
|
|
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const smtpClient = createSmtpClient({
|
|
|
|
|
host: testServer.hostname,
|
|
|
|
|
port: testServer.port,
|
|
|
|
|
secure: false,
|
|
|
|
|
connectionTimeout: 5000,
|
|
|
|
|
debug: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
// Email with basic UTF-8 characters
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const email = new Email({
|
|
|
|
|
from: 'sender@example.com',
|
|
|
|
|
to: ['recipient@example.com'],
|
2025-05-26 04:09:29 +00:00
|
|
|
|
subject: 'UTF-8 Test: café, naïve, résumé',
|
|
|
|
|
text: 'This email contains UTF-8 characters: café, naïve, résumé, piñata',
|
|
|
|
|
html: '<p>HTML with UTF-8: <strong>café</strong>, <em>naïve</em>, résumé, piñata</p>'
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await smtpClient.sendMail(email);
|
2025-05-26 04:09:29 +00:00
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.messageId).toBeDefined();
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
console.log('Successfully sent email with basic UTF-8 characters');
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
await smtpClient.close();
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
tap.test('CEP-06: European characters', async () => {
|
|
|
|
|
console.log('Testing European characters');
|
|
|
|
|
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const smtpClient = createSmtpClient({
|
|
|
|
|
host: testServer.hostname,
|
|
|
|
|
port: testServer.port,
|
|
|
|
|
secure: false,
|
|
|
|
|
connectionTimeout: 5000,
|
|
|
|
|
debug: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
// Email with European characters
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const email = new Email({
|
2025-05-26 04:09:29 +00:00
|
|
|
|
from: 'sender@example.com',
|
|
|
|
|
to: ['recipient@example.com'],
|
|
|
|
|
subject: 'European: ñ, ü, ø, å, ß, æ',
|
|
|
|
|
text: [
|
|
|
|
|
'German: Müller, Größe, Weiß',
|
|
|
|
|
'Spanish: niño, señor, España',
|
|
|
|
|
'French: français, crème, être',
|
|
|
|
|
'Nordic: København, Göteborg, Ålesund',
|
|
|
|
|
'Polish: Kraków, Gdańsk, Wrocław'
|
|
|
|
|
].join('\n'),
|
|
|
|
|
html: `
|
|
|
|
|
<h1>European Characters Test</h1>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>German: Müller, Größe, Weiß</li>
|
|
|
|
|
<li>Spanish: niño, señor, España</li>
|
|
|
|
|
<li>French: français, crème, être</li>
|
|
|
|
|
<li>Nordic: København, Göteborg, Ålesund</li>
|
|
|
|
|
<li>Polish: Kraków, Gdańsk, Wrocław</li>
|
|
|
|
|
</ul>
|
|
|
|
|
`
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
const result = await smtpClient.sendMail(email);
|
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.messageId).toBeDefined();
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
console.log('Successfully sent email with European characters');
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
await smtpClient.close();
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
tap.test('CEP-06: Asian characters', async () => {
|
|
|
|
|
console.log('Testing Asian characters');
|
|
|
|
|
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const smtpClient = createSmtpClient({
|
|
|
|
|
host: testServer.hostname,
|
|
|
|
|
port: testServer.port,
|
|
|
|
|
secure: false,
|
|
|
|
|
connectionTimeout: 5000,
|
|
|
|
|
debug: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
// Email with Asian characters
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const email = new Email({
|
|
|
|
|
from: 'sender@example.com',
|
|
|
|
|
to: ['recipient@example.com'],
|
2025-05-26 04:09:29 +00:00
|
|
|
|
subject: 'Asian: 你好, こんにちは, 안녕하세요',
|
|
|
|
|
text: [
|
|
|
|
|
'Chinese (Simplified): 你好世界',
|
|
|
|
|
'Chinese (Traditional): 你好世界',
|
|
|
|
|
'Japanese: こんにちは世界',
|
|
|
|
|
'Korean: 안녕하세요 세계',
|
|
|
|
|
'Thai: สวัสดีโลก',
|
|
|
|
|
'Hindi: नमस्ते संसार'
|
|
|
|
|
].join('\n'),
|
|
|
|
|
html: `
|
|
|
|
|
<h1>Asian Characters Test</h1>
|
|
|
|
|
<table>
|
|
|
|
|
<tr><td>Chinese (Simplified):</td><td>你好世界</td></tr>
|
|
|
|
|
<tr><td>Chinese (Traditional):</td><td>你好世界</td></tr>
|
|
|
|
|
<tr><td>Japanese:</td><td>こんにちは世界</td></tr>
|
|
|
|
|
<tr><td>Korean:</td><td>안녕하세요 세계</td></tr>
|
|
|
|
|
<tr><td>Thai:</td><td>สวัสดีโลก</td></tr>
|
|
|
|
|
<tr><td>Hindi:</td><td>नमस्ते संसार</td></tr>
|
|
|
|
|
</table>
|
|
|
|
|
`
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
const result = await smtpClient.sendMail(email);
|
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.messageId).toBeDefined();
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
console.log('Successfully sent email with Asian characters');
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
await smtpClient.close();
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
tap.test('CEP-06: Emojis and symbols', async () => {
|
|
|
|
|
console.log('Testing emojis and symbols');
|
|
|
|
|
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const smtpClient = createSmtpClient({
|
|
|
|
|
host: testServer.hostname,
|
|
|
|
|
port: testServer.port,
|
|
|
|
|
secure: false,
|
|
|
|
|
connectionTimeout: 5000,
|
|
|
|
|
debug: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
// Email with emojis and symbols
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const email = new Email({
|
|
|
|
|
from: 'sender@example.com',
|
|
|
|
|
to: ['recipient@example.com'],
|
2025-05-26 04:09:29 +00:00
|
|
|
|
subject: 'Emojis: 🎉 🚀 ✨ 🌈',
|
|
|
|
|
text: [
|
|
|
|
|
'Faces: 😀 😃 😄 😁 😆 😅 😂',
|
|
|
|
|
'Objects: 🎉 🚀 ✨ 🌈 ⭐ 🔥 💎',
|
|
|
|
|
'Animals: 🐶 🐱 🐭 🐹 🐰 🦊 🐻',
|
|
|
|
|
'Food: 🍎 🍌 🍇 🍓 🥝 🍅 🥑',
|
|
|
|
|
'Symbols: ✓ ✗ ⚠ ♠ ♣ ♥ ♦',
|
|
|
|
|
'Math: ∑ ∏ ∫ ∞ ± × ÷ ≠ ≤ ≥'
|
|
|
|
|
].join('\n'),
|
|
|
|
|
html: `
|
|
|
|
|
<h1>Emojis and Symbols Test 🎉</h1>
|
|
|
|
|
<p>Faces: 😀 😃 😄 😁 😆 😅 😂</p>
|
|
|
|
|
<p>Objects: 🎉 🚀 ✨ 🌈 ⭐ 🔥 💎</p>
|
|
|
|
|
<p>Animals: 🐶 🐱 🐭 🐹 🐰 🦊 🐻</p>
|
|
|
|
|
<p>Food: 🍎 🍌 🍇 🍓 🥝 🍅 🥑</p>
|
|
|
|
|
<p>Symbols: ✓ ✗ ⚠ ♠ ♣ ♥ ♦</p>
|
|
|
|
|
<p>Math: ∑ ∏ ∫ ∞ ± × ÷ ≠ ≤ ≥</p>
|
|
|
|
|
`
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await smtpClient.sendMail(email);
|
2025-05-26 04:09:29 +00:00
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.messageId).toBeDefined();
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
console.log('Successfully sent email with emojis and symbols');
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
await smtpClient.close();
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
tap.test('CEP-06: Mixed international content', async () => {
|
|
|
|
|
console.log('Testing mixed international content');
|
|
|
|
|
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const smtpClient = createSmtpClient({
|
|
|
|
|
host: testServer.hostname,
|
|
|
|
|
port: testServer.port,
|
|
|
|
|
secure: false,
|
|
|
|
|
connectionTimeout: 5000,
|
|
|
|
|
debug: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
// Email with mixed international content
|
2025-05-24 16:19:19 +00:00
|
|
|
|
const email = new Email({
|
|
|
|
|
from: 'sender@example.com',
|
|
|
|
|
to: ['recipient@example.com'],
|
2025-05-26 04:09:29 +00:00
|
|
|
|
subject: 'Mixed: Hello 你好 مرحبا こんにちは 🌍',
|
|
|
|
|
text: [
|
|
|
|
|
'English: Hello World!',
|
|
|
|
|
'Chinese: 你好世界!',
|
|
|
|
|
'Arabic: مرحبا بالعالم!',
|
|
|
|
|
'Japanese: こんにちは世界!',
|
|
|
|
|
'Russian: Привет мир!',
|
|
|
|
|
'Greek: Γεια σας κόσμε!',
|
|
|
|
|
'Mixed: Hello 世界 🌍 مرحبا こんにちは!'
|
|
|
|
|
].join('\n'),
|
|
|
|
|
html: `
|
|
|
|
|
<h1>International Mix 🌍</h1>
|
|
|
|
|
<div style="font-family: Arial, sans-serif;">
|
|
|
|
|
<p><strong>English:</strong> Hello World!</p>
|
|
|
|
|
<p><strong>Chinese:</strong> 你好世界!</p>
|
|
|
|
|
<p><strong>Arabic:</strong> مرحبا بالعالم!</p>
|
|
|
|
|
<p><strong>Japanese:</strong> こんにちは世界!</p>
|
|
|
|
|
<p><strong>Russian:</strong> Привет мир!</p>
|
|
|
|
|
<p><strong>Greek:</strong> Γεια σας κόσμε!</p>
|
|
|
|
|
<p><strong>Mixed:</strong> Hello 世界 🌍 مرحبا こんにちは!</p>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
2025-05-24 16:19:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
const result = await smtpClient.sendMail(email);
|
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
|
expect(result.messageId).toBeDefined();
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
2025-05-26 04:09:29 +00:00
|
|
|
|
console.log('Successfully sent email with mixed international content');
|
2025-05-24 16:19:19 +00:00
|
|
|
|
|
|
|
|
|
await smtpClient.close();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('cleanup test SMTP server', async () => {
|
|
|
|
|
if (testServer) {
|
2025-05-26 04:09:29 +00:00
|
|
|
|
await stopTestServer(testServer);
|
2025-05-24 16:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default tap.start();
|