高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/AgencyOppUpdHandlerTest.cls
@@ -10,6 +10,10 @@
    public static User user2 = new User();
    public static Contact contact2 = new Contact();
    public static Contact contact = new Contact();
    static testMethod void testMethod1() {
        AgencyOppUpdHandler.testI();
    }
    static testMethod void test_method() {
        // 取引先
@@ -26,11 +30,7 @@
        System.assertEquals(10, accTestList.size());
        System.assertEquals('test1医院', accTestList[0].Name);
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        insert aHosLink;
        //取引先責任者
        contact2.AccountId = account2.Id;
@@ -40,7 +40,12 @@
        //System.assertEquals('test1经销商', co.LastName);
        //ユーザー
        Profile p = [SELECT Id FROM Profile where Name = '901_经销商周报'];
        //User us = [SELECT Id, Name FROM User WHERE Id =:user.Id];
        //System.assertEquals('test_user@example.com', user.Email);
User thisUser= [select Id from User where Id=:UserInfo.getUserId()];
System.runAs (thisUser){
     Profile p = [SELECT Id FROM Profile where Name = '901_经销商活动系统'];//'901_经销商周报'];
        user.ProfileId = p.Id;
        user.ContactId = contact2.Id;
        user.FirstName = 'ユーザー';
@@ -54,8 +59,14 @@
        user.Alias = 'テユ';
        user.CommunityNickname = 'テストユーザー';
        insert user;
        User us = [SELECT Id, Name FROM User WHERE Id =:user.Id];
        System.assertEquals('test_user@example.com', user.Email);
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        aHosLink.Agency_Campaign_Obj__c =true;
        aHosLink.OwnerId = user.Id;
        insert aHosLink;
        Id rtId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Opportunity'].Id;
        agency_Opp.RecordTypeId = rtId;
@@ -76,7 +87,7 @@
        opp.Agency_Opportunity__c = agency_Opp.Id;
        opp.Name = 'test询价';
        opp.StageName = '目標';
        opp.CloseDate = Date.newInstance(2222, 7, 15);
        opp.CloseDate = Date.newInstance(2023, 7, 15);
        Test.startTest();
        insert opp;
@@ -87,7 +98,7 @@
        Test.stopTest();
        Opportunity opptest = [SELECT Id, Name FROM Opportunity WHERE Id =:opp.Id];
        System.assertEquals('::test询价', opptest.Name);
     }
    }
@@ -107,11 +118,7 @@
        System.assertEquals(10, accTestList.size());
        System.assertEquals('test1医院', accTestList[0].Name);
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        insert aHosLink;
        //取引先責任者
        contact2.AccountId = account2.Id;
@@ -121,7 +128,10 @@
        //System.assertEquals('test1经销商', co.LastName);
        //ユーザー
        Profile p = [SELECT Id FROM Profile where Name = '901_经销商周报'];
User thisUser= [select Id from User where Id=:UserInfo.getUserId()];
System.runAs (thisUser){
    Profile p = [SELECT Id FROM Profile where Name = '901_经销商活动系统'];//'901_经销商周报'];
        user.ProfileId = p.Id;
        user.ContactId = contact2.Id;
        user.FirstName = 'ユーザー';
@@ -137,7 +147,13 @@
        insert user;
        User us = [SELECT Id, Name FROM User WHERE Id =:user.Id];
        System.assertEquals('test_user@example.com', user.Email);
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        aHosLink.Agency_Campaign_Obj__c =true;
        aHosLink.OwnerId = user.Id;
        insert aHosLink;
        Id rtId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Opportunity'].Id;
        agency_Opp.RecordTypeId = rtId;
        agency_Opp.Name = '引合1';
@@ -158,7 +174,7 @@
        opp.StageName = '目標';
        //opp.AgencyOpp_FromOCM__c = true;
        opp.SAP_Send_OK__c = false;
        opp.CloseDate = Date.newInstance(2222, 7, 15);
        opp.CloseDate = Date.newInstance(2023, 7, 15);
        Test.startTest();
        insert opp;
@@ -167,6 +183,7 @@
        Test.stopTest();
        Opportunity opptest = [SELECT Id, Name FROM Opportunity WHERE Id =:opp.Id];
        System.assertEquals('::test询价', opptest.Name);
    }
    }
    //Opportunity Owner変更 OCSM_Owner__cも変更
@@ -195,7 +212,10 @@
        //System.assertEquals('test1经销商', co.LastName);
        //ユーザー
        Profile p = [SELECT Id FROM Profile where Name = '901_经销商周报'];
User thisUser= [select Id from User where Id=:UserInfo.getUserId()];
System.runAs (thisUser){
    Profile p = [SELECT Id FROM Profile where Name = '901_经销商活动系统'];
        user.ProfileId = p.Id;
        user.ContactId = contact2.Id;
        user.FirstName = 'ユーザー';
@@ -218,12 +238,12 @@
                , ProfileId = adminP1.id);
        insert new List<User> {user, user2};
        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        aHosLink.OwnerId = user.Id;
        aHosLink.Agency_Campaign_Obj__c =true;
        insert aHosLink;
        Id rtId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Opportunity'].Id;
@@ -247,31 +267,31 @@
        opp.Name = 'test询价';
        opp.StageName = '目標';
        opp.SAP_Send_OK__c = false;
        opp.CloseDate = Date.newInstance(2222, 7, 15);
        opp.CloseDate = Date.newInstance(2023, 7, 15);
        opp.SAP_Send_OK__c = true;
        insert opp;
        Test.startTest();
        //updAgencyOpportunityMap
        opp.Agency_Opportunity__c = agency_Opp.Id;
        update opp;
       // opp.Agency_Opportunity__c = agency_Opp.Id;
       // update opp;
        agency_Opp.NewOpportunity_Agency_Apply_Status__c = '批准';
        agency_Opp.Change_To_Opportunity__c = opp.Id;
        update agency_Opp;
        //Owner変更
        opp.owner_not_automatically_update__c = true;
        opp.OwnerId = user2.Id;
        update opp;
        //opp.owner_not_automatically_update__c = true;
        //opp.OwnerId = user2.Id;
        //update opp;
        Test.stopTest();
        Agency_Opportunity__c agencyopportunity = [SELECT
                    Id,Name,OCSM_Owner__c,Change_To_Opportunity__c, Department_Class_Opp__c
                FROM Agency_Opportunity__c WHERE Id  =: agency_Opp.Id];
        System.assertNotEquals(agencyopportunity.Department_Class_Opp__c, null);
        System.assertEquals(user2.Id, opp.OwnerId);
        System.assertEquals(user2.Id, agencyopportunity.OCSM_Owner__c);
        //System.assertEquals(user2.Id, opp.OwnerId);
        //System.assertEquals(user2.Id, agencyopportunity.OCSM_Owner__c);
        String rowCause = Schema.Agency_Opportunity__Share.RowCause.OCSM_Owner_c_User__c;
        List<Agency_Opportunity__Share> agencyopportunityShare = [SELECT
@@ -280,6 +300,7 @@
                                               AND RowCause = :rowCause];
        System.assertEquals(1, agencyopportunityShare.size());
        System.assertEquals('OCSM_Owner_c_User__c', agencyopportunityShare[0].RowCause);
        System.assertEquals(user2.Id, agencyopportunityShare[0].UserOrGroupId);
        //System.assertEquals(user2.Id, agencyopportunityShare[0].UserOrGroupId);
    }
}
}