Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tests/notificationSystem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class NotificationSystemTest {
console.log('✅ Email service test passed\n');

console.log('🎉 All notification system tests passed!');

// FIX: Force process to exit cleanly. Without this, open DB/SMTP connections
// will keep the Node event loop running and the script will hang forever.
process.exit(0);

} catch (error) {
console.error('❌ Test failed:', error.message);
Expand Down Expand Up @@ -109,8 +113,10 @@ class NotificationSystemTest {

// Verify preferences were set
const savedPreferences = await this.notificationManager.getUserPreferences(testUserId);
if (!savedPreferences.email.transaction) {
throw new Error('User preferences not saved correctly');

// FIX: Added optional chaining to prevent TypeErrors if savedPreferences is null/undefined
if (!savedPreferences?.email?.transaction) {
throw new Error('User preferences not saved correctly or returned null');
}
}

Expand All @@ -131,7 +137,8 @@ class NotificationSystemTest {
txHash: '0x123456789'
});

if (!renderedEmail.includes('100.00')) {
// FIX: Added optional chaining just in case renderTemplate fails silently
if (!renderedEmail?.includes('100.00')) {
throw new Error('Email template rendering failed');
}
}
Expand All @@ -143,4 +150,4 @@ if (require.main === module) {
test.runTests().catch(console.error);
}

module.exports = NotificationSystemTest;
module.exports = NotificationSystemTest;