You need to sign in to do that
Don't have an account?
Procurement Executive
Test class for the following code
public with sharing class CancelMembership_ctrl {
@AuraEnabled
public Static Account cancelMembership(String accountId){
try {
Account objAccount = [SELECT Id,Membership_Level__c,Membership_Type__c,Home_Clinic__c,
Patient_Type__c,Membership_Add_On__c,
Member_Status__c,Cancellation_Date__c, Signature_Date__c
FROM Account
WHERE Id = :accountId LIMIT 1];
objAccount.Cancelled_membership__c = true;
objAccount.Patient_Type__c = 'Registered';
objAccount.Membership_Type__c = null;
objAccount.Membership_Level__c = null;
objAccount.Membership_Add_On__c = null;
objAccount.Member_Status__c = 'Membership Cancelled';
objAccount.Cancellation_Date__c = system.Today();
update objAccount;
return objAccount;
}catch(Exception e){
throw e;
}
}
@AuraEnabled
public static List < String > getPicklistValue() {
List < String > options = new List < String > ();
Schema.DescribeFieldResult fieldResult = Account.Cancellation_Reason__c.getDescribe();
List < Schema.PicklistEntry > ple = fieldResult.getPicklistValues();
for (Schema.PicklistEntry f: ple) {
options.add(f.getLabel());
}
return options;
}
}
@AuraEnabled
public Static Account cancelMembership(String accountId){
try {
Account objAccount = [SELECT Id,Membership_Level__c,Membership_Type__c,Home_Clinic__c,
Patient_Type__c,Membership_Add_On__c,
Member_Status__c,Cancellation_Date__c, Signature_Date__c
FROM Account
WHERE Id = :accountId LIMIT 1];
objAccount.Cancelled_membership__c = true;
objAccount.Patient_Type__c = 'Registered';
objAccount.Membership_Type__c = null;
objAccount.Membership_Level__c = null;
objAccount.Membership_Add_On__c = null;
objAccount.Member_Status__c = 'Membership Cancelled';
objAccount.Cancellation_Date__c = system.Today();
update objAccount;
return objAccount;
}catch(Exception e){
throw e;
}
}
@AuraEnabled
public static List < String > getPicklistValue() {
List < String > options = new List < String > ();
Schema.DescribeFieldResult fieldResult = Account.Cancellation_Reason__c.getDescribe();
List < Schema.PicklistEntry > ple = fieldResult.getPicklistValues();
for (Schema.PicklistEntry f: ple) {
options.add(f.getLabel());
}
return options;
}
}
@isTest
private class CancelMembership_ctrl_Test{
@testSetup
public static void setUpMockData(){
Account acc = new Account(
FirstName='Test FName',
LastName='Test LName',
PersonMailingStreet='test@yahoo.com',
PersonMailingPostalCode='12345',
PersonMailingCity='SFO',
PersonEmail='test@yahoo.com',
PersonHomePhone='1234567',
PersonMobilePhone='12345678',
Relation_With_Payer__c='Brother',
Cancelled_membership__c = true,
Patient_Type__c = 'Member',
Membership_Type__c = '2019 MHC GP',
Membership_Level__c = 'Adult - Main Payer',
Membership_Add_On__c = 'Healthscreen',
Member_Status__c = 'Member',
Cancellation_Date__c = system.Today(),
Signature_Date__c = system.Today(),
Cancellation_Reason__c= 'Died',
Date_of_Birth__c = system.Today(),
Gender__c = 'Male',
Home_Clinic__c='Wandsworth'
);
insert acc;
acc.Cancelled_membership__c = true;
acc.Patient_Type__c = 'Registered';
acc.Membership_Type__c = null;
acc.Membership_Level__c = null;
acc.Membership_Add_On__c = null;
acc.Member_Status__c = 'Membership Cancelled';
acc.Cancellation_Date__c = system.Today();
acc.Signature_Date__c = system.Today();
acc.Cancellation_Reason__c= 'Moving Away';
acc.Home_Clinic__c='Wandsworth';
Update acc;
}
CancelMembership_ctrl cancelM = new CancelMembership_ctrl();
// cancelM.cancelMembership(acc.Id);
//Test.startTest();
//List < String > options = CancelMembership_ctrl.getPicklistValue();
//Test.stopTest();
//system.assertNotEquals(null, options, 'The collection should be instantiated');
//system.assertEquals(options.get(0).getvalue(),'The collection should be instantiated');
// system.assert(!options.isEmpty(),'The collection should be populated');
}
Try this code for test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
But I am still struck with this test class as it is giving me error for restricted picklist. Like Home Clinic I am providing exact data as per the picklist values for the Custom Field.