/**
 * IpscapeHelperTest
 **/
@IsTest
public class IpscapeHelperTest {
    public static Lead createLead(Boolean doInsert){
        Lead newLead = new Lead() ;
        newLead.FirstName = 'Cole';
        newLead.LastName = 'Swain';
        newLead.Company = 'BlueWave';
        newLead.Status = 'contacted';
        if(doInsert){
            insert newLead;
        }
        return newLead;
    }

    public static Account createAccount(Boolean doInsert){
        Account acc = new Account();
        acc.Name = 'Test Account';
        if(doInsert){
            insert acc;
        }
        return acc;
    }

    public static Void convertLead(Lead newLead ){
        database.leadConvert lc = new database.leadConvert();
        lc.setLeadId(newLead.id);
        leadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        lc.setOpportunityName('Cole Swain');
    }

    public static List<Opportunity>createOpportunity(Id accountId, Integer numOpps) {
        List<Opportunity> opps = new List<Opportunity>();
        for(Integer i = 1; i <= numOpps; i++) {
            Opportunity opp = new Opportunity();
            opp.name = 'Account ' + i;
            opp.accountId = accountid;
            opp.amount = 1000;
            opp.closeDate = Date.today().addDays(5);
            opp.stageName = 'Prospecting';
            opps.add(opp);
        }
        return opps;
    }

    public static Task createTask(Boolean doInsert){
        Task newTask = new Task() ;
        newTask.Subject = 'Call';
        newTask.callObject = '909987';
        newTask.ActivityDate = Date.today();
        newTask.Status = 'Completed';
        if(doInsert){
            insert newTask;
        }
        return newTask;
    }

    @IsTest
    static void testIpscapeCapabilities() {
        String capabilities = IpscapeHelper.getCapabilities();
        Assert.isInstanceOfType(capabilities, String.class);
    }

    @IsTest
    static void testIpscapeLead() {
        Lead testLead = createLead(true);
        String leadData = IpscapeHelper.getLead(testLead.id);
        Assert.isInstanceOfType(leadData, String.class);
    }

    @IsTest
    static void testIpscapeOpportunity() {
        Lead testLead = createLead(true);
        Account acc = createAccount(true);
        List<Opportunity> oppList = createOpportunity(acc.id, 1);

        String oppData = IpscapeHelper.getOpportunity(oppList[0].id);
        Assert.isInstanceOfType(oppData, String.class);
    }

    @IsTest
    static void testIpscapeTask() {
        Task testTask = createTask(true);
        String taskData = IpscapeHelper.getTask('909987');
        Assert.isInstanceOfType(taskData, String.class);
    }
}