Complete testing framework for all email and SMS templates.
test-email-templates.js- Test email templates usingsendEmailfrommail.servicetest-sms-templates.js- Test SMS templates usingsendSMSfromsms.servicetest-all-templates.js- Combined suite withnotification-dispatcher.utilfor testing both
Uses sendEmail from src/services/common/mail.service.js:
node testing/test-email-templates.jsUses sendSMS from src/services/common/sms.service.js:
node testing/test-sms-templates.jsUses sendNotification from src/utils/notification-dispatcher.util.js:
# Test both email and SMS together
node testing/test-all-templates.js --combined verification
node testing/test-all-templates.js --combined welcome# Run all email + SMS tests
node testing/test-all-templates.js# All email templates
node testing/test-email-templates.js
# Specific email template
node testing/test-all-templates.js verification# All SMS templates
node testing/test-sms-templates.js
# Specific SMS template
node testing/test-all-templates.js passwordChanged# Test all security-related templates
node testing/test-all-templates.js --category security
# Test all 2FA templates
node testing/test-all-templates.js --category twoFactor
# Test all profile update templates
node testing/test-all-templates.js --category profilenode testing/test-all-templates.js --help- Imports
sendEmailfrom@/services/common/mail.service - Imports
generateEmailHtmlfrom@utils/email-generator.util - Imports email templates from
@services/templates/emailTemplate - Generates HTML using template + data
- Sends email using
sendEmail(email, subject, html) - Fire-and-forget pattern (no await)
- Imports
sendSMSfrom@/services/common/sms.service - Imports
generateSmsMessagefrom@utils/sms-generator.util - Imports SMS templates from
@services/templates/smsTemplate - Generates message using template + OTP
- Sends SMS using
sendSMS(phone, message) - Fire-and-forget pattern (no await)
- Imports
sendNotificationfrom@utils/notification-dispatcher.util - Imports both email and SMS templates
- Prepares
contactInfowith email, phone, andContactModes.BOTH - Calls
sendNotification({ contactInfo, emailTemplate, smsTemplate, data }) - Dispatcher handles both email and SMS sending internally
| Category | Templates Included |
|---|---|
| verification | verification, welcome_super_admin, welcome |
| security | forgotPassword, passwordChanged, newDeviceLogin, logoutAllDevices |
| account | accountDeactivated, accountReactivated |
| profile | verifyNewEmail, verifyNewPhone, profileUpdated, emailChangeAlert, phoneChangeAlert |
| twoFactor | twoFactorLoginOTP, twoFactorEnabled, twoFactorDisabled |
| device | deviceVerification |
- ✅
verification- Email verification OTP/link - ✅
welcome_super_admin- Super admin welcome email - ✅
welcome- Welcome email after verification
- ✅
forgotPassword- Password reset request - ✅
passwordChanged- Password change confirmation - ✅
newDeviceLogin- New device login alert - ✅
logoutAllDevices- Logout all devices confirmation
- ✅
accountDeactivated- Account deactivation notice - ✅
accountReactivated- Account reactivation welcome
- ✅
verifyNewEmail- New email verification - ✅
profileUpdated- Profile update confirmation - ✅
emailChangeAlert- Email change security alert
- ✅
twoFactorLoginOTP- 2FA login OTP - ✅
twoFactorEnabled- 2FA enabled confirmation - ✅
twoFactorDisabled- 2FA disabled alert
- ✅
deviceVerification- New device authorization
All above templates also have SMS versions with:
- Concise message format (160 chars max)
- OTP placeholder support
- DLT template IDs (for India)
# Email Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
EMAIL_FROM=your-email@gmail.com
# SMS Configuration
SMS_MODE=mock # or termux-ssh or real
SMS_ENABLED=true
TEST_PHONE_NUMBER=+919876543210
# App URLs
FRONTEND_URL=http://localhost:3030
COMPANY_NAME="Your App Name"The test suite uses mock user data:
{
userId: "TEST_USER_001",
email: "test@example.com",
phone: "+919876543210",
firstName: "Test",
userType: "CUSTOMER"
}Each test:
- ✅ Creates notification data with template name
- ✅ Calls
sendNotification()with fire-and-forget pattern - ✅ Logs success/failure to console
- ✅ Validates template exists and data is passed correctly
============================================================
📧 EMAIL TEMPLATE TESTING STARTED
============================================================
📋 CATEGORY 1: REGISTRATION & VERIFICATION
🧪 Testing Email Template: verification
================================================
✅ verification - Email sent successfully
🧪 Testing Email Template: welcome
================================================
✅ welcome - Email sent successfully
============================================================
✅ ALL EMAIL TEMPLATE TESTS COMPLETED
============================================================
📝 Note: Check your email inbox for all test emails
⚠️ Templates use fire-and-forget pattern - check logs for any errors
- Monitor your inbox at configured email
- Check spam/junk folder
- Review SMTP logs in console
- If
SMS_MODE=mock, check console logs - If
SMS_MODE=termux-ssh, check Termux device - Review SMS service logs
- No emails received: Check SMTP credentials and Gmail App Password
- SMS not sent: Verify SMS_MODE and phone number format
- Template not found: Check template name spelling
- Fire-and-forget errors: Check console logs for async errors
- Run tests in development only - Don't spam production users
- Use mock SMS mode for local testing
- Check logs - Fire-and-forget pattern means errors logged, not thrown
- Test incrementally - Use single template tests during development
- Verify all templates before deployment
Add to package.json:
{
"scripts": {
"test:templates": "node testing/test-all-templates.js",
"test:email": "node testing/test-email-templates.js",
"test:sms": "node testing/test-sms-templates.js"
}
}Run with npm:
npm run test:templates
npm run test:email
npm run test:smsBefore deployment:
- All email templates tested
- All SMS templates tested
- Email received successfully
- SMS received successfully (if enabled)
- No console errors
- Templates render correctly
- Links work properly
- OTPs displayed correctly
- Branding appears correctly
- Fire-and-forget pattern working
If you encounter issues:
- Check environment variables
- Verify SMTP/SMS configuration
- Review console logs
- Test individual templates
- Check notification.factory.js implementation