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
RaffusRaffus 

How to write a test class for below method

@AuraEnabled
    public static String loadData(String strCaseInfo) {
        System.debug('caseInfo ' + strCaseInfo);
        CaseInfoWrapper caseInfo = (CaseInfoWrapper)JSON.deserialize(strCaseInfo, CaseInfoWrapper.class);

        rand_App_Customer__c customer = getCustomerInfo2(caseInfo.emailId);
        Case cse = new Case();
        cse.subject = 'tan One Problem Report';
        cse.Origin = rand_APP;
        cse.Status = 'Awaiting Approval';
        cse.Priority = 'Medium';
        cse.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get(rand_APP).getRecordTypeId();
        cse.Description = caseInfo.description;
        cse.rand_App_Customer__c = customer?.Id;
        cse.Issue_category__c = caseInfo.category;
        cse.Issue_Sub_Category__c = caseInfo.subCategory;
        insert cse;
        // for skip the triggers of ContentDocumentLink && ContentDocument
        ContentDocumentLinkTriggerUtil.skipTrigger = true;
        ContentDocumentTriggerUtil.skipTrigger = true;
        List<ContentVersion> cVersions = new List<ContentVersion>();
        for (FileInfoWrapper file : caseInfo.files) {
            System.debug('fileInfo ' + file);
            if (String.isNotBlank(file.base64Data)) {
                ContentVersion cv = new ContentVersion();
                cv.ContentLocation = 'S';
                cv.PathOnClient = file.fileName;
                cv.VersionData = EncodingUtil.base64Decode(file.base64Data);
                cv.Title = file.fileName;
                cVersions.add(cv);
            }
        }

 
PriyaPriya (Salesforce Developers) 
Hey Raffus,
 

It would be difficult for the community to provide the complete implementation of test class. However, we can help you with errors if you face any in your test code.

 

Thanks & Regards,

Priya Ranjan



 
RaffusRaffus
@isTest
    public static void loadDataTest(){
        
        randAppController.CaseInfoWrapper csInfoWp = new randAppController.CaseInfoWrapper();
        csInfoWp.partyId = '12133';
        csInfoWp.longitude = 26.8767631;
        csInfoWp.locationName = '54, Jaipur Municipal Corporation, Jaipur Tehsil, Jaipur district, Rajasthan, India';
        csInfoWp.latitude = 75.8156308;
        csInfoWp.emailid = 'test@gmail.com';
       
        randAppController.FileInfoWrapper file = new randAppController.FileInfoWrapper();
        file.base64Data = EncodingUtil.base64Encode(Blob.valueOf('Test'));
        file.fileName = 'Test.txt';
        csInfoWp.files = new List<randAppController.FileInfoWrapper>{ file };
        csInfoWp.description = 'Test000101';
        csInfoWp.category = 'fountain show';
        csInfoWp.mobile = '1234567890';
        csInfoWp.subCategory = 'fountain';
        String caseData = JSON.serialize(csInfoWp);
       
        String fileData = JSON.serialize(file);

        String uploadDataResult = randAppController.uploadData(caseData);
        randAppController.uploadData(uploadDataResult);
This is my implementation, but getting an error - System.JSONException: Invalid numeric value: Leading zeroes not allowed at input location [1,2],
On this line -  CaseInfoWrapper caseInfo = (CaseInfoWrapper)JSON.deserialize(strCaseInfo, CaseInfoWrapper.class);