Write a test class for the below class
Budget: $10 – $15 USD
public class Countyratecontroller {
@AuraEnabled(cacheable=true )
public static CCS_COUNTY_RATE__c fetchCountyPlan(string recordId) {
CCS_COUNTY_RATE__c cr = new CCS_COUNTY_RATE__c();
if(recordId != null){
cr = [ SELECT Id,County_Name__c,CCS_DTE_BEGIN_EFFV_RATE__c,CCS_DTE_END_EFFV_RATE__c,County__c FROM CCS_COUNTY_RATE__c where Id =:recordId Limit 1];
}
return cr;
}
@AuraEnabled( cacheable=true )
public static List<countyWrapper> fetchCountyRate(string recordId) {
Map<String,Map<String,Double>>countyAgeMap = new Map<String,Map<String,Double>>();
List<CCS_COUNTY_RATE_AMT__c> cntyratelst = new List<CCS_COUNTY_RATE_AMT__c>();
List<countyWrapper> cwrapLst = new List<countyWrapper>();
try{
system.debug('recordId is'+recordId);
CCS_COUNTY_RATE__c cr = [ SELECT Id,County_Name__c FROM CCS_COUNTY_RATE__c where Id =:recordId Limit 1];
//system.debug('cr is'+cr);
//system.debug('cr city is'+cr.County_Name__c);
cntyratelst =[Select Id,Rate__c,CCS_AGE_GROUP__c,Provider_Name__c,Name,County__c,CCS_COUNTY_RATE__c from CCS_COUNTY_RATE_AMT__c where County__c =:cr.County_Name__c AND CCS_COUNTY_RATE__c =:recordId];
if(cntyratelst != null && cntyratelst.size()>0){
for(CCS_COUNTY_RATE_AMT__c C : cntyratelst){
if(countyAgeMap.containsKey(C.Provider_Name__c)){
countyAgeMap.get(C.Provider_Name__c).put(C.CCS_AGE_GROUP__c,C.Rate__c);
}else{
Map<String,Double> cMap = new Map<String,Double>();
cMap.put(C.CCS_AGE_GROUP__c,C.Rate__c);
countyAgeMap.put(C.Provider_Name__c,cMap);
}
}
}
for(String S:countyAgeMap.Keyset()){
Map<String,Double> cMap = countyAgeMap.get(S);
countyWrapper cw = new countyWrapper();
cw.providerName = S;
for(String T : cMap.Keyset()){
if(T=='Infant'){
cw.infantAge = cMap.get(T);
}
if(T=='Toddler'){
cw.toddlerAge = cMap.get(T);
}
if(T=='Kindergarten'){
cw.kindergarten = cMap.get(T);
}
if(T=='3-4-5 Years'){
cw.preschool = cMap.get(T);
}
if(T=='School Age Before/After'){
cw.schoolage = cMap.get(T);
}
if(T=='School age All Other'){
cw.schoolageall = cMap.get(T);
}
}
cwrapLst.add(cw);
}
system.debug(' cwrapLst is '+ cwrapLst);
system.debug(' cwrapLst size is '+ cwrapLst.size());
// return [Select Id,Age__c,Age_Group__c,Provider_type__c,Name,County__c from County_rate__c where County__c =:cr.County_Name__c];
return cwrapLst;
}catch(Exception e){
system.debug('error msg'+e.getMessage());
throw new AuraHandledException(e.getMessage());
}
}
public class countyWrapper{
@AuraEnabled
public String providerName{get;set;}
@AuraEnabled
public Double infantAge{get;set;}
@AuraEnabled
public Double toddlerAge{get;set;}
@AuraEnabled
public Double preschool{get;set;}
@AuraEnabled
public Double kindergarten{get;set;}
@AuraEnabled
public Double schoolage{get;set;}
@AuraEnabled
public Double schoolageall{get;set;}
}
}
@AuraEnabled(cacheable=true )
public static CCS_COUNTY_RATE__c fetchCountyPlan(string recordId) {
CCS_COUNTY_RATE__c cr = new CCS_COUNTY_RATE__c();
if(recordId != null){
cr = [ SELECT Id,County_Name__c,CCS_DTE_BEGIN_EFFV_RATE__c,CCS_DTE_END_EFFV_RATE__c,County__c FROM CCS_COUNTY_RATE__c where Id =:recordId Limit 1];
}
return cr;
}
@AuraEnabled( cacheable=true )
public static List<countyWrapper> fetchCountyRate(string recordId) {
Map<String,Map<String,Double>>countyAgeMap = new Map<String,Map<String,Double>>();
List<CCS_COUNTY_RATE_AMT__c> cntyratelst = new List<CCS_COUNTY_RATE_AMT__c>();
List<countyWrapper> cwrapLst = new List<countyWrapper>();
try{
system.debug('recordId is'+recordId);
CCS_COUNTY_RATE__c cr = [ SELECT Id,County_Name__c FROM CCS_COUNTY_RATE__c where Id =:recordId Limit 1];
//system.debug('cr is'+cr);
//system.debug('cr city is'+cr.County_Name__c);
cntyratelst =[Select Id,Rate__c,CCS_AGE_GROUP__c,Provider_Name__c,Name,County__c,CCS_COUNTY_RATE__c from CCS_COUNTY_RATE_AMT__c where County__c =:cr.County_Name__c AND CCS_COUNTY_RATE__c =:recordId];
if(cntyratelst != null && cntyratelst.size()>0){
for(CCS_COUNTY_RATE_AMT__c C : cntyratelst){
if(countyAgeMap.containsKey(C.Provider_Name__c)){
countyAgeMap.get(C.Provider_Name__c).put(C.CCS_AGE_GROUP__c,C.Rate__c);
}else{
Map<String,Double> cMap = new Map<String,Double>();
cMap.put(C.CCS_AGE_GROUP__c,C.Rate__c);
countyAgeMap.put(C.Provider_Name__c,cMap);
}
}
}
for(String S:countyAgeMap.Keyset()){
Map<String,Double> cMap = countyAgeMap.get(S);
countyWrapper cw = new countyWrapper();
cw.providerName = S;
for(String T : cMap.Keyset()){
if(T=='Infant'){
cw.infantAge = cMap.get(T);
}
if(T=='Toddler'){
cw.toddlerAge = cMap.get(T);
}
if(T=='Kindergarten'){
cw.kindergarten = cMap.get(T);
}
if(T=='3-4-5 Years'){
cw.preschool = cMap.get(T);
}
if(T=='School Age Before/After'){
cw.schoolage = cMap.get(T);
}
if(T=='School age All Other'){
cw.schoolageall = cMap.get(T);
}
}
cwrapLst.add(cw);
}
system.debug(' cwrapLst is '+ cwrapLst);
system.debug(' cwrapLst size is '+ cwrapLst.size());
// return [Select Id,Age__c,Age_Group__c,Provider_type__c,Name,County__c from County_rate__c where County__c =:cr.County_Name__c];
return cwrapLst;
}catch(Exception e){
system.debug('error msg'+e.getMessage());
throw new AuraHandledException(e.getMessage());
}
}
public class countyWrapper{
@AuraEnabled
public String providerName{get;set;}
@AuraEnabled
public Double infantAge{get;set;}
@AuraEnabled
public Double toddlerAge{get;set;}
@AuraEnabled
public Double preschool{get;set;}
@AuraEnabled
public Double kindergarten{get;set;}
@AuraEnabled
public Double schoolage{get;set;}
@AuraEnabled
public Double schoolageall{get;set;}
}
}