/** * Real Scenario Email Test * * Test emails with realistic workflow data * Simulates: User 10 creates request, User 12 is approver */ import { emailNotificationService } from '../services/emailNotification.service'; import logger from '../utils/logger'; const appDomain = process.env.APP_DOMAIN || 'royalenfield.com'; /** * Simulate real workflow scenario */ async function testRealScenario() { console.log('๐งช Testing Real Workflow Scenario\n'); console.log('Scenario: User 10 creates request, assigns to User 12 as approver\n'); // Mock user data (simulating real database records) const user10 = { userId: 'user-10-uuid', email: `john.doe@${appDomain}`, displayName: 'John Doe', department: 'Engineering', designation: 'Senior Engineer' }; const user12 = { userId: 'user-12-uuid', email: `jane.smith@${appDomain}`, displayName: 'Jane Smith', department: 'Management', designation: 'Engineering Manager', levelNumber: 1 }; // Mock request data (simulating real workflow request) const requestData = { requestId: 'req-uuid-12345', requestNumber: 'REQ-2025-12-0013', title: 'New Equipment Purchase Request - Testing Department', description: `
Requesting approval for the following equipment for the testing department:
Total estimated cost: โน15,00,000
This purchase is critical for our Q1 2025 testing schedule and has been pre-approved by the department head.
Please review and approve at your earliest convenience.
For questions, contact: john.doe@${appDomain}
`, requestType: 'Purchase', priority: 'HIGH', createdAt: new Date(), tatHours: 48, totalApprovers: 3, initiatorName: user10.displayName, initiatorId: user10.userId }; // Mock approval chain for multi-level scenario const approvalChain = [ { levelNumber: 1, approverName: 'Jane Smith', approverEmail: `jane.smith@${appDomain}`, status: 'PENDING', approvedAt: null }, { levelNumber: 2, approverName: 'Michael Brown', approverEmail: `michael.brown@${appDomain}`, status: 'PENDING', approvedAt: null }, { levelNumber: 3, approverName: 'Sarah Johnson', approverEmail: `sarah.johnson@${appDomain}`, status: 'PENDING', approvedAt: null } ]; try { console.log('โ'.repeat(80)); console.log('๐ง Test 1: Request Created Email (to Initiator - User 10)'); console.log('โ'.repeat(80)); await emailNotificationService.sendRequestCreated( requestData, user10, user12 ); console.log('\n'); console.log('โ'.repeat(80)); console.log('๐ง Test 2: Multi-Level Approval Request Email (to Approver - User 12)'); console.log('โ'.repeat(80)); await emailNotificationService.sendApprovalRequest( requestData, user12, user10, true, // isMultiLevel approvalChain ); console.log('\n'); console.log('โ'.repeat(80)); console.log('๐ง Test 3: TAT Reminder at 40% (Configurable Threshold)'); console.log('โ'.repeat(80)); await emailNotificationService.sendTATReminder( requestData, user12, { thresholdPercentage: 40, timeRemaining: '28 hours', tatDeadline: new Date(Date.now() + 28 * 60 * 60 * 1000), assignedDate: requestData.createdAt } ); console.log('\n'); console.log('โ'.repeat(80)); console.log('๐ง Test 4: TAT Reminder at 80% (Configurable Threshold)'); console.log('โ'.repeat(80)); await emailNotificationService.sendTATReminder( requestData, user12, { thresholdPercentage: 80, timeRemaining: '9 hours', tatDeadline: new Date(Date.now() + 9 * 60 * 60 * 1000), assignedDate: requestData.createdAt } ); console.log('\n'); console.log('โ'.repeat(80)); console.log('๐ง Test 5: Approval Confirmation (User 12 approved)'); console.log('โ'.repeat(80)); const approvedUser12 = { ...user12, approvedAt: new Date(), comments: `Approved! The equipment purchase is justified for the testing schedule.
Conditions:
All equipment has been purchased and delivered to the testing department.
Total cost: โน14,85,000 (within budget)
Testing department is now fully equipped for Q1 2025 schedule. All deliverables met.`, workNotesCount: 15, documentsCount: 8 } ); console.log('\n'); console.log('โ'.repeat(80)); console.log('โ All Real Scenario Tests Complete!'); console.log('โ'.repeat(80)); console.log('\n๐ก Check the Preview URLs above to see emails with REAL data!'); console.log('๐ All emails use actual request information, rich text content, and workflow data'); console.log('\n'); } catch (error) { console.error('โ Test failed:', error); throw error; } } // Run the test console.log('\n'); console.log('โ'.repeat(80)); console.log(' REAL SCENARIO EMAIL TEST'); console.log(' User 10 (John Doe) โ Creates Request'); console.log(' User 12 (Jane Smith) โ Assigned as Approver'); console.log('โ'.repeat(80)); console.log('\n'); testRealScenario() .then(() => { console.log('โ Test completed successfully\n'); process.exit(0); }) .catch((error) => { console.error('โ Test failed:', error); process.exit(1); });