From bf5ee2cfbef0c47d4ff2690754b985e6ba8240b8 Mon Sep 17 00:00:00 2001 From: Jadonamite Date: Sun, 29 Mar 2026 19:09:52 +0100 Subject: [PATCH] test: add process exit and safe chaining to notification smoke tests Updates the custom NotificationSystemTest runner to explicitly call process.exit(0) upon successful completion, preventing the script from hanging indefinitely due to open service connections in the event loop. Adds optional chaining to assertions to prevent uncaught TypeErrors if the manager or service methods return null or undefined. --- tests/notificationSystem.test.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/notificationSystem.test.js b/tests/notificationSystem.test.js index b0a9f84c..ead34c8f 100644 --- a/tests/notificationSystem.test.js +++ b/tests/notificationSystem.test.js @@ -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); @@ -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'); } } @@ -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'); } } @@ -143,4 +150,4 @@ if (require.main === module) { test.runTests().catch(console.error); } -module.exports = NotificationSystemTest; \ No newline at end of file +module.exports = NotificationSystemTest;