I'm trying to deploy my Apex class to my production environment. I was having difficulty writing and organizing my Tests. Here is the Apex Rest Class I created
@RestResource(urlMapping='/convertlead/*')
global class LeadConvert extends Auth.ConnectedAppPlugin{
@HttpPost
global static string convertLead(string leadId, string accountId, string newUser, string email)
{
Lead lead = [select Id from Lead where Id = :leadId];
Database.LeadConvert lc = new Database.LeadConvert();
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setLeadId(lead.Id);
lc.setAccountId(accountId);
if(newUser == 'true' || newUser =='True'){
lc.setDoNotCreateOpportunity(false);
lc.setOpportunityName(email);
}
else{
lc.setDoNotCreateOpportunity(true);
}
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
if (lcr.isSuccess())
{
return 'success';
}
else
{
return 'failed';
}
}
@isTest
static void leadConvertClassTest(){
LeadConvert lct = new LeadConvert();
string LCResult = lct.convertLead("123", "123", "false", "[email protected]");
System.assertEquals("failed", LCResult);
}
}
I want to write a mock unit test that will just let me deploy to my production environment. It doesn't need to validate anything at this point. How can I do that?
I've created another apex Test Class with the following method, still getting 0% test coverage?
@isTest
private class LeadConverTest {
static testMethod void testconvertLead() {
//LeadConvert lct = new LeadConvert();
//string LCResult = convertLead("123", "123", "false", "[email protected]");
string LCResult = LeadConvert.convertLead("123", "123", "false", "[email protected]");
System.assertEquals("failed", LCResult);
}
}