function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RahulRahul 

Hello friends, Iam new with test classes. Can you help me with this test class?

public class caseController {
    @AuraEnabled
    public static List<Organizational_Payment__c> getCaseList(Id recordId){
        
        Id orgId;
        List<Case> org = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:org){
            orgId=c.ContactId;
        }
        
        List<Organizational_Payment__c> orgPaylst = [SELECT Id,Name,Receiving_organization__r.Name,Payment_Status__c,Payment_Date__c,Payable_Amount__c,  Bank_Account_Number__c,Concerning_Person_ID__c
                              FROM Organizational_Payment__c WHERE Concerning_Person_ID__c = :orgId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_date__c DESC];
        return orgPaylst;
    }
    
    @AuraEnabled
    public static void updateRecord(List<String> lstRecordId) {
        List<Organizational_Payment__c> lstOrgPayUpdate = new   List<Organizational_Payment__c>() ;
        for(Organizational_Payment__c orgPay :[SELECT Id,Payment_Status__c FROM  Organizational_Payment__c where id = : lstRecordId] ){
            orgPay.Payment_Status__c= 'Bounced payment';
            lstOrgPayUpdate.add(orgPay);
            System.debug('Success');
            
        }
       
        if(!lstOrgPayUpdate.isEmpty()){
            update lstOrgPayUpdate;
        }
       
    }
     @AuraEnabled
    public static List<Payment_Result__c> getPayResultList(Id recordId){
        
        Id perId;
        List<Case> per = [select ContactId from Case WHERE Id=:recordId];
        for(Case c:per){
            perId=c.ContactId;
        }
        
        List<Payment_Result__c> PayReslst = [SELECT Id,Name,Payment_Status__c,Payment_Date__c,Person_ID__c,Bank_Number__c,Total_Amount_Net__c
                              FROM Payment_Result__c WHERE Person_ID__c = :perId and Payment_Date__c > LAST_N_MONTHS:6
                                                    ORDER BY Payment_Date__c DESC];
        return PayReslst;
    }
     @AuraEnabled
    public static void updatePaymentRecord(List<String> lstPayId) {
        List<Payment_Result__c> lstPayResUpdate = new   List<Payment_Result__c>() ;
        for(Payment_Result__c Pay :[SELECT Id,Payment_Status__c FROM  Payment_Result__c where id = : lstPayId] ){
            Pay.Payment_Status__c= 'Bounced payment';
            lstPayResUpdate.add(Pay);
            System.debug('Success');
            
        }
       
        if(!lstPayResUpdate.isEmpty()){
            update lstPayResUpdate;
        }
       
    }
}

What i have implemented is this :-
@isTest
public class CaseAuraControllerTest {
    public static void setupData(){   
        Account acc = TestDataFactory.createAccount();
        Contact con = TestDataFactory.createContactWithBasicInfo(acc.Id);
        Case cas = TestDataFactory.createCase(con.Id);
  
    }

}

Can you help what to do after this?
                   
Best Answer chosen by Rahul
CharuDuttCharuDutt
Hii Rahul
try below Code
@isTest
Public Class caseControllerTest{
@isTest
public Static Void UnitTest(){
	Account Acc = New Account();
	Acc.Name = 'test Account';
	insert Acc;
	
	Contact Con = new Contact();
	Con.FirstName = 'Test';
	Con.LastName = 'Contact';
	Con.AcountId = Acc.id;
	Insert Con;
	
	Case C = new Case();
	c.ContactId = Con.Id;
	c.Origin  = 'Web';
	c.Status = 'New'
	c.Subject = 'Test Case';
	insert c;
	
	Organizational_Payment__c op = new Organizational_Payment__c();
	op.Concerning_Person_ID__c  = c.ContactId;
	//Fill All Required Fields
	insert op;
	
	Payment_Result__c pr = new Payment_Result__c();
	pr.Person_ID__c   = c.ContactId;
	//Fill All Required Fields
	insert pr;
	
	caseController.getCaseList(c.Id);
	caseController.updateRecord(op.Id);
	caseController.getPayResultList(c.id);
	caseController.updatePaymentRecord(pr.Id);
	}
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Rahul
try below Code
@isTest
Public Class caseControllerTest{
@isTest
public Static Void UnitTest(){
	Account Acc = New Account();
	Acc.Name = 'test Account';
	insert Acc;
	
	Contact Con = new Contact();
	Con.FirstName = 'Test';
	Con.LastName = 'Contact';
	Con.AcountId = Acc.id;
	Insert Con;
	
	Case C = new Case();
	c.ContactId = Con.Id;
	c.Origin  = 'Web';
	c.Status = 'New'
	c.Subject = 'Test Case';
	insert c;
	
	Organizational_Payment__c op = new Organizational_Payment__c();
	op.Concerning_Person_ID__c  = c.ContactId;
	//Fill All Required Fields
	insert op;
	
	Payment_Result__c pr = new Payment_Result__c();
	pr.Person_ID__c   = c.ContactId;
	//Fill All Required Fields
	insert pr;
	
	caseController.getCaseList(c.Id);
	caseController.updateRecord(op.Id);
	caseController.getPayResultList(c.id);
	caseController.updatePaymentRecord(pr.Id);
	}
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
RahulRahul
Thank you so much :)