Skip to content

Instantly share code, notes, and snippets.

@Feldstrom
Created March 7, 2020 00:24
Show Gist options
  • Save Feldstrom/91a5810a10b6a564622e5f7574321915 to your computer and use it in GitHub Desktop.
Save Feldstrom/91a5810a10b6a564622e5f7574321915 to your computer and use it in GitHub Desktop.
@isTest
public class CasePBTestClass{
//New Retention Created
//This should stamp the date/time a new Retention case type is created as well as mark Open_Retention_Case__c as true on the associated Contact
@isTest
static void new_retention_created(){
//assemble
Contact retentionContact = new Contact();
retentionContact.lastName = 'Stacy';
retentionContact.Open_Retention_Case__c = false;
retentionContact.Retention_Case_Created_Date__c = dateTime.newInstance(2001, 05, 02, 00,00,00);
retentionContact.RecordTypeId = Contact.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Customer').getRecordTypeId();
insert retentionContact;
//act
Case newRetentionCase = new Case();
newRetentionCase.ContactId = retentionContact.Id;
newRetentionCase.Status = 'New';
newRetentionCase.Subject = 'Retention Case';
newRetentionCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Retention_Case').getRecordTypeId();
insert newRetentionCase;
retentionContact = [SELECT Retention_Case_Created_Date__c, Open_Retention_Case__c FROM Contact WHERE Id =: retentionContact.Id];
//assert
System.assertEquals(Datetime.now(), retentionContact.Retention_Case_Created_Date__c);
System.assertEquals(true, retentionContact.Open_Retention_Case__c);
}
// Retention Case Closed
//when a Retention case type is closed the associated Contact should have Last_Retention_Closed_Date__c marked with the case closed date
//and Open_Retention_Case__c on the Contact should be set to False
@isTest
static void retention_case_closed(){
//assemble
Contact retentionContact = new Contact();
retentionContact.lastName = 'Stacy';
retentionContact.RecordTypeId = Contact.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Customer').getRecordTypeId();
insert retentionContact;
Case newRetentionCase = new Case();
newRetentionCase.ContactId = retentionContact.Id;
newRetentionCase.Status = 'New';
newRetentionCase.Subject = 'Retention Case';
newRetentionCase.Reason__c = 'No response';
newRetentionCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Retention_Case').getRecordTypeId();
insert newRetentionCase;
newRetentionCase.ContactID = retentionContact.Id;
newRetentionCase.Reason__c = 'No response';
newRetentionCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Retention_Case').getRecordTypeId();
newRetentionCase.Status = 'Closed Won';
//act
update newRetentionCase;
//assert
retentionContact = [SELECT Last_Retention_Closed_Date__c, Open_Retention_Case__c FROM Contact WHERE Id =:retentionContact.Id];
System.assertEquals(Date.today(), retentionContact.Last_Retention_Closed_Date__c);
System.assertEquals(false, retentionContact.Open_Retention_Case__c);
}
//this should create a new task with the same date as Last_Faxed__c on the case
//PCF Fax Attempts Changes
@isTest
static void pcf_fax_attempts_change(){
//assemble
Case pcfCase = new Case();
pcfCase.Faxes_Sent__c = 0;
pcfCase.Last_Faxed__c = Date.today();
pcfCase.PCF_Approval_Fax__c = true;
pcfCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('PCF_Collection').getRecordTypeId();
insert pcfCase;
Task newTask = new Task();
//act
pcfCase.Faxes_Sent__c = 1;
update pcfCase;
//assert
newTask = [SELECT OwnerId, ActivityDate, Status, Subject, WhatId, isPCFApprovalFax__c FROM Task];
System.assertEquals('Fax', newTask.Subject);
System.assertEquals(pcfCase.Id, newTask.WhatId);
System.assertEquals('Completed', newTask.Status);
System.assertEquals(true, newTask.isPCFApprovalFax__c);
System.assertEquals(pcfCase.Last_Faxed__c, newTask.ActivityDate.addDays(1));
}
//MRF Approved
@isTest
static void mrf_approved(){
//assemble
Account mrfAccount = new Account();
mrfAccount.Name = 'Stacy';
insert mrfAccount;
Contact mrfContact = new Contact();
mrfContact.lastName = 'Stacy';
insert mrfContact;
Case mrfCase = new Case();
mrfCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('MRF_Verification').getRecordTypeId();
mrfCase.Status = 'Pending';
mrfCase.AccountId = mrfAccount.Id;
mrfCase.ContactId = mrfContact.Id;
insert mrfCase;
//act
mrfCase.Status = 'Closed - Approved';
update mrfCase;
Case pcfCase = new Case();
//assert
pcfCase = [SELECT Id,AccountId, ContactId, RecordTypeId, Status, Subject FROM Case WHERE Subject =: 'PCF Collection'];
System.assertEquals(mrfAccount.Id, pcfCase.AccountId);
System.assertEquals(mrfContact.Id, pcfCase.ContactId);
System.assertEquals('Pending', pcfCase.Status);
System.assertEquals(Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('PCF_Collection').getRecordTypeId(), pcfCase.RecordTypeId);
mrfContact = [SELECT Id, Latest_PCF_Collection__c FROM Contact WHERE Id =:mrfContact.Id];
System.assertEquals(pcfCase.Id, mrfContact.Latest_PCF_Collection__c);
}
//If MRF is Approved - Update Contact
@isTest
static void if_mrf_is_approved(){
//assemble
Contact mrfContact = new Contact();
mrfContact.lastName = 'Stacy';
mrfContact.RecordTypeId = Contact.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Customer').getRecordTypeId();
insert mrfContact;
Customer_Document__c custDoc = new Customer_Document__c();
insert custDoc;
Case mrfCase = new Case();
mrfCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('MRF_Verification').getRecordTypeId();
mrfCase.ContactId = mrfContact.Id;
mrfCase.Customer_Document_Id__c = custDoc.Id;
mrfCase.Status = 'Pending';
insert mrfCase;
//act
mrfCase.Status = 'Closed - Approved';
update mrfCase;
mrfContact.firstName = 'Gwen';
update mrfContact;
//assert
mrfContact = [SELECT Id, Medical_Release_Form__c FROM Contact WHERE Id =:mrfContact.Id];
System.assertEquals(custDoc.Id, mrfContact.Medical_Release_Form__c);
}
//PCF verification is Approved
@isTest
static void pcf_verification_is_approved(){
//assemble
Contact pcfContact = new Contact();
pcfContact.lastName = 'Stacy';
insert pcfContact;
Case pcfCase = new Case();
pcfCase.Status = 'Pending';
pcfCase.ContactId = pcfContact.Id;
pcfCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('PCF_Verification').getRecordTypeId();
insert pcfCase;
//act
pcfCase.Status = 'Closed - Approved';
update pcfCase;
//assert
pcfContact = [SELECT Id, PCF_Approved__c FROM Contact WHERE Id=:pcfContact.Id];
System.assertEquals(true, pcfContact.PCF_Approved__c);
}
//Record is PCF Collection
@isTest
static void record_is_pcf_collection(){
//assemble
Case firstCase = new Case();
insert firstCase;
Contact relatedContact = new Contact();
relatedContact.firstName = 'Bob';
relatedContact.lastName = 'Bobsen';
relatedContact.Latest_PCF_Collection__c = firstCase.Id;
insert relatedContact;
Case pbCase = new Case();
pbCase.Subject = 'PCF Collection Case';
pbCase.Status = 'Pending';
pbCase.ContactID = relatedContact.Id;
pbCase.RecordTypeId = Case.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('PCF_Collection').getRecordTypeId();
//act
insert pbCase;
//assert
relatedContact = [SELECT Latest_PCF_Collection__c FROM Contact WHERE Id=:relatedContact.Id];
System.assertEquals(pbCase.Id, relatedContact.Latest_PCF_Collection__c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment