Backup_FME_personal/force-app/main/default/classes/OrgWideEmailHandlerTest.cls

126 lines
3.9 KiB
OpenEdge ABL

@IsTest
public with sharing class OrgWideEmailHandlerTest {
@IsTest
static void testGetAllFromEmailOptions() {
System.debug('===== START testGetAllFromEmailOptions =====');
Test.startTest();
List<Map<String, String>> result =
OrgWideEmailHandler.getAllFromEmailOptions();
Test.stopTest();
System.debug('Result: ' + result);
System.assertNotEquals(null, result);
System.assert(result.size() >= 1);
// First item should ALWAYS be current user
System.assertEquals(UserInfo.getUserId(), result[0].get('value'));
System.assert(result[0].get('label').contains(UserInfo.getName()));
// If OrgWideEmailAddress exists in org, size will be > 1
if(result.size() > 1){
System.debug('OrgWideEmailAddress exists in this org');
System.assertNotEquals(null, result[1].get('value'));
} else {
System.debug('No OrgWideEmailAddress exists in this org');
System.assertEquals(1, result.size());
}
System.debug('===== END testGetAllFromEmailOptions =====');
}
@IsTest
static void testWithoutOrgWideEmail() {
System.debug('===== START testWithoutOrgWideEmail =====');
// Do NOT insert any OrgWideEmailAddress
Test.startTest();
List<Map<String, String>> result =
OrgWideEmailHandler.getAllFromEmailOptions();
Test.stopTest();
System.debug('Result without OrgWideEmail: ' + result);
// System.assertEquals(1, result.size());
// Only current user should exist
// System.assertEquals(UserInfo.getUserId(), result[0].get('value'));
// System.assert(result[0].get('label').contains(UserInfo.getName()));
System.debug('===== END testWithoutOrgWideEmail =====');
}
@IsTest
static void testSendEmailFromLwc_WithAttachment() {
System.debug('===== START testSendEmailFromLwc_WithAttachment =====');
// Create test file
ContentVersion cv = new ContentVersion();
cv.Title = 'TestFile';
cv.PathOnClient = 'TestFile.txt';
cv.VersionData = Blob.valueOf('Test file content');
insert cv;
// Get ContentDocumentId
cv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id];
String currentUserEmail = [SELECT Email FROM User WHERE Id = :UserInfo.getUserId()].Email;
Test.startTest();
OrgWideEmailHandler.sendEmailFromLwc(
currentUserEmail, // fromEmail (same as user)
'testto@test.com', // toEmail
'testcc@test.com', // ccEmail
'testbcc@test.com', // bccEmail
'Unit Test Subject',
'<p>Unit Test Body</p>',
cv.ContentDocumentId, // fileId
'TestFile.txt'
);
Test.stopTest();
System.debug('===== END testSendEmailFromLwc_WithAttachment =====');
// Verify email invocation happened
// System.assertEquals(1, Limits.getEmailInvocations());
}
@IsTest
static void testSendEmailFromLwc_WithoutAttachment() {
System.debug('===== START testSendEmailFromLwc_WithoutAttachment =====');
String currentUserEmail = [SELECT Email FROM User WHERE Id = :UserInfo.getUserId()].Email;
Test.startTest();
OrgWideEmailHandler.sendEmailFromLwc(
currentUserEmail,
'testto@test.com',
null, // No CC
null, // No BCC
'No Attachment Subject',
'<p>No Attachment Body</p>',
null, // No file
null
);
Test.stopTest();
System.debug('===== END testSendEmailFromLwc_WithoutAttachment =====');
//System.assertEquals(1, Limits.getEmailInvocations());
}
}