@isTest public with sharing class salesforceAuthenticationController_Test { @testSetup static void testData(){ HIC_ShopifySync__Configuration__c conf =new HIC_ShopifySync__Configuration__c(); conf.Name='Default'; conf.HIC_ShopifySync__Account_Contact__c = true; conf.HIC_ShopifySync__API_Key__c = 'test'; conf.HIC_ShopifySync__Batch_Is_Processing__c = true; conf.HIC_ShopifySync__ClientId__c = 'tsdytud'; conf.HIC_ShopifySync__ClientSecret__c = 'ddcdcd'; insert conf; } @isTest static void testSalesforceAuthentication(){ Organization org = new Organization(); SalesforceAuthenticationController sa = new SalesforceAuthenticationController(); sa.authenticate(); system.assert(!org.issandbox); } @isTest static void testSalesforceAuthentication1(){ Organization org = new Organization(); String code = ApexPages.currentPage().getParameters().get('code'); HIC_ShopifySync__Configuration__c conf = [SELECT Id, HIC_ShopifySync__Account_Contact__c, HIC_ShopifySync__API_Key__c, HIC_ShopifySync__Batch_Is_Processing__c, HIC_ShopifySync__ClientId__c, HIC_ShopifySync__ClientSecret__c FROM HIC_ShopifySync__Configuration__c]; Test.startTest(); // Mock the HTTP Callout HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('{"access_token":"test_access_token","refresh_token":"test_refresh_token"}'); response.setStatusCode(200); // Mock Parameters ApexPages.currentPage().getParameters().put('code', 'testCode'); ApexPages.currentPage().getParameters().put('viewmode', 'testViewMode'); SalesforceAuthenticationController sa = new SalesforceAuthenticationController(); sa.authenticate(); pageReference response1 = sa.authenticateSalesforce(); pageReference response2 = sa.redirectToApp(); pageReference response3 = sa.handleAuthentication(); Test.stopTest(); system.assert(!org.issandbox); } @isTest static void testUpdateCredentials(){ String accessToken = 'jclfieunucnc38737583298'; String refreshToken = 'dhlbhencehlnnehjlexfxle'; HIC_ShopifySync__Configuration__c conf = [SELECT Id, HIC_ShopifySync__Account_Contact__c, HIC_ShopifySync__API_Key__c, HIC_ShopifySync__Batch_Is_Processing__c, HIC_ShopifySync__ClientId__c, HIC_ShopifySync__ClientSecret__c FROM HIC_ShopifySync__Configuration__c]; Test.startTest(); salesforceAuthenticationController.updateCredentials(accessToken, refreshToken); Test.stopTest(); } @isTest static void testMakeCallout(){ Organization org = new Organization(); system.assert(!org.issandbox); String code = ApexPages.currentPage().getParameters().get('code'); // Expected values based on the logic String expectedSandboxUrl = 'https://test.salesforce.com/apex/HIC_ShopifySync__SalesforceAuthentication'; String expectedProductionUrl = 'https://login.salesforce.com/apex/HIC_ShopifySync__SalesforceAuthentication'; String expectedEndPointSandbox = 'https://test.salesforce.com/services/oauth2/token'; String expectedEndPointProduction = 'https://login.salesforce.com/services/oauth2/token'; // Call the method (replace with your actual method call if applicable) Map headerMap = new Map(); headerMap.put('Content-Type', 'application/x-www-form-urlencoded'); headerMap.put('Accept', 'application/json'); headerMap.put('Content-length', '307'); String body = 'grant_type=authorization_code&code=' + code + '&redirect_uri='; String endPoint; if (org.isSandbox) { body += expectedSandboxUrl; endPoint = expectedEndPointSandbox; body += '&client_id=TestClientId&client_secret=TestClientSecret&islwcapp=true&state=testislwcapp'; } else { body += expectedProductionUrl; endPoint = expectedEndPointProduction; body += '&client_id=TestClientId&client_secret=TestClientSecret&islwcapp=true&state=prodislwcapp'; } Test.startTest(); salesforceAuthenticationController.makeCallout(body, endpoint, headerMap, 'POST'); salesforceAuthenticationController.updateAppServer(); Test.stopTest(); } @isTest static void testSalesforceAuthentication2(){ Organization org = new Organization(); //String code = ApexPages.currentPage().getParameters().get('code'); HIC_ShopifySync__Configuration__c conf = [SELECT Id, HIC_ShopifySync__Account_Contact__c, HIC_ShopifySync__API_Key__c, HIC_ShopifySync__Batch_Is_Processing__c, HIC_ShopifySync__ClientId__c, HIC_ShopifySync__ClientSecret__c FROM HIC_ShopifySync__Configuration__c]; Test.startTest(); // Mock the HTTP Callout HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('{"access_token":"test_access_token","refresh_token":"test_refresh_token"}'); response.setStatusCode(200); // Mock Parameters ApexPages.currentPage().getParameters().put('islwcapp', 'testlwcApp'); ApexPages.currentPage().getParameters().put('viewmode', 'testViewMode'); ApexPages.currentPage().getParameters().put('storeName', 'testStoreName'); SalesforceAuthenticationController sa = new SalesforceAuthenticationController(); sa.authenticate(); pageReference response1 = sa.authenticateSalesforce(); pageReference response2 = sa.redirectToApp(); pageReference response3 = sa.handleAuthentication(); Test.stopTest(); system.assert(!org.issandbox); } }