Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.0 kB
3
Indexable
/**
 * @description       : 
 * @author            : Harsit Garg
 * @group             : 
 * @last modified on  : 03-30-2023
 * @last modified by  : Harsit Garg
**/
@isTest
public class B2BProductListHelperTest 
{
    @TestSetup
    public static void testSetupData()
    {
        B2BTestFactory.initialStorefrontSetup();
    }
    
    @isTest
    public static void testproductSearch()
    {
        List<ProductAttributeSet> attributeSets = [SELECT Id FROM ProductAttributeSet WHERE DeveloperName = 'Region_Condition_Mill'];
        if(!attributeSets.isEmpty()){
            B2BTestFactory.createVariantProduct(attributeSets[0].Id);
        }
        Map<String,Object> testMap = new Map<String,Object>();
        String accountId = [SELECT id FROM Account WHERE name = 'TestClass Account'].id;
        String searchTerm = '4-1/2" 11.36# P110-EC R-1';
        Map<String,object> searchQuery = new Map<String,object>();
        searchQuery.put('searchTerm',searchTerm);
        String communityId = [SELECT Id, Name FROM Network LIMIT 1].Id;
        testMap.put(B2BConstant.EFFECTIVE_ACCOUNT_ID,accountId);
        testMap.put(B2BConstant.COMMUNITY_ID,communityId);
        testMap.put(B2BConstant.SEARCH_QUERY,JSON.serialize(searchQuery));
        
        test.startTest();
        Map<String,Object> dataMap = B2BProductListHelper.productSearch(testMap);
        Map<String, B2BProductListVO> variationInfo = (Map<String, B2BProductListVO>)dataMap.get(B2BConstant.VARIATION_INFO);
        System.assertEquals(false, variationInfo.isEmpty(), 'Invalid Data');
        test.stopTest();
    }
    
    @isTest
    public static void testGetSortRules()
    {
        Map<String,Object> testMap = new Map<String,Object>();
        String communityId = [SELECT Id, Name FROM Network LIMIT 1].Id;
        testMap.put(B2BConstant.COMMUNITY_ID,communityId);
        test.startTest();
        Map<String,Object> dataMap = B2BProductListHelper.getSortRules(testMap);
        List<ConnectApi.SortRule> rules = (List<ConnectApi.SortRule>)dataMap.get(B2BConstant.SORT_RULES);
        System.assertEquals(false, rules.isEmpty(), 'Invalid Data');
        test.stopTest();
    }

    @isTest
    public static void testGetCategoryPath()
    {
        Map<String,Object> testMap = new Map<String,Object>();
        String communityId = [SELECT Id, Name FROM Network LIMIT 1].Id;
        String categoryId = [SELECT Id FROM ProductCategory WHERE Name = 'Products' LIMIT 1].Id;
        testMap.put(B2BConstant.COMMUNITY_ID,communityId);
        testMap.put(B2BConstant.CATEGORY_ID,categoryId);
        test.startTest();
        Map<String,Object> dataMap = B2BProductListHelper.getCategoryPath(testMap);
        List<ConnectApi.ProductCategoryData> paths = (List<ConnectApi.ProductCategoryData>)dataMap.get(B2BConstant.CATEGORY_PATH);
        System.assertEquals(false, paths.isEmpty(), 'Invalid Data');
        test.stopTest();
    }

}