Skip to content

Instantly share code, notes, and snippets.

@winniecluk
Created February 23, 2018 19:16
Show Gist options
  • Save winniecluk/c62638f412e6170ed90fdb022b7721ee to your computer and use it in GitHub Desktop.
Save winniecluk/c62638f412e6170ed90fdb022b7721ee to your computer and use it in GitHub Desktop.
static TestMethod void dealApprovalHandler_Tests_UnitTest(){
Account acc = test_Helper.createAccount();
Contact cont = test_Helper.createContact( acc );
Opportunity deal = test_Helper.createOpportunity( acc, cont );
// create a new email and envelope object
Messaging.InboundEmail.Header h = new Messaging.InboundEmail.Header();
h.Name = 'Test';
h.Value = ' 1 1 2000';
Messaging.InboundEmail email = new Messaging.InboundEmail();
email.headers = new List<Messaging.InboundEmail.Header>();
email.headers.add(h);
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// setup the data for the email
email.subject = 'Create Contact';
email.fromAddress = 'someaddress@email.com';
email.plainTextBody = 'email body\n2225256325\nTitle';
String body = '<wbr>';
body += '--DEALIDSTART--'+deal.id+'--DEALIDEND--';
body += '--CONTENTIDSTART--'+''+'--CONTENTIDEND--';
body += '--ATTACHMENTIDSTART--'+''+'--ATTACHMENTIDEND--';
body += 'CoreVest American Finance Lender LLC. All Rights Reserved.';
email.htmlBody = body;
/* add an Binary attachment
Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
attachment.body = blob.valueOf(test);
attachment.fileName = 'textfileone.txt';
attachment.mimeTypeSubType = 'text/plain';
email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
// add an Text attachment
Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
attachmenttext.body = 'my attachment text';
attachmenttext.fileName = 'textfiletwo3.txt';
attachmenttext.mimeTypeSubType = 'texttwo/plain';
email.textAttachments = new Messaging.inboundEmail.TextAttachment[] { attachmenttext };
*/
// call the email service class and test it with the data in the testMethod
dealApprovalHandler cls = new dealApprovalHandler();
Test.startTest();
deal = dealApprovalHandler.queryOpportunity(deal.Id);
email.fromAddress = deal.Owner.email;
email.toAddresses = new List<String>{'test@test.com'};
cls.handleInboundEmail(email, env);
dealApprovalHandler.postToChatter(deal,'test');
Messaging.InboundEmail.TextAttachment t = new Messaging.InboundEmail.TextAttachment();
t.fileName = 'Test';
t.mimeTypeSubType = 'Test';
t.body = 'Test';
dealApprovalHandler.constructFileAttachment(t);
Messaging.InboundEmail.BinaryAttachment b = new Messaging.InboundEmail.BinaryAttachment();
b.fileName = 'Test';
b.mimeTypeSubType = 'Test';
b.body = blob.valueOf('Test');
dealApprovalHandler.constructFileAttachment(b);
dealApprovalHandler.queryContentVersions(new List<Id>{UserInfo.getUserId()});
dealApprovalHandler.sendReply(deal.Id, UserInfo.getUserId());
dealApprovalHandler.createAttachment(email,deal);
Test.stopTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment