高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@isTest
private class RentalApplyOtherTriggerTest {
    private static final RecordType campaignRC = [SELECT Id, DeveloperName FROM RecordType WHERE DeveloperName = 'Internal_training' AND SObjectType = 'Campaign'];
 
    static testMethod void myUnitTest() {
        String loginUserId = UserInfo.getUserId();
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();
        user.Dept__c = '医疗西北营业本部';
 
        // システム管理者
        User user2 = new User(Test_staff__c = true);
        user2.LastName = '_サンブリッジ';
        user2.FirstName = 'う';
        user2.Alias = 'う';
        user2.Email = 'olympusTest04@sunbridge.com';
        user2.Username = 'olympusTest04@sunbridge.com';
        user2.CommunityNickname = 'う1';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = System.Label.ProfileId_SystemAdmin;
        user2.Job_Category__c = '销售推广';
        user2.Province__c = '上海市';
        user2.Use_Start_Date__c = Date.today().addMonths(-6);
        user2.SalesManager__c = UserInfo.getUserId();
        user2.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user2.JingliApprovalManager__c = UserInfo.getUserId();
        user2.BuchangApprovalManager__c = UserInfo.getUserId();
        user2.ZongjianApprovalManager__c = UserInfo.getUserId();
        user2.Dept__c = '医疗西北营业本部';
 
        insert new User[] {user, user2};
        System.runAs(user) {
            System.Test.startTest();
            Campaign target = new Campaign();
            target.Name = 'test campaign';
            target.RecordTypeId = campaignRC.Id;    // 内部トレーニング
            insert target;
 
            // recode type を取得
            List<RecordType> recthp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
            if (recthp.size() == 0) {
                return;
            }
            List<RecordType> rectdc = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
            if (rectdc.size() == 0) {
                return;
            }
            List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
            if (rectDpt.size() == 0) {
                return;
            }
 
            // insert
            Account hp1 = new Account();
            hp1.RecordTypeId = recthp[0].Id;
            hp1.Name = '病院テスト1';
 
            Account hp2 = new Account();
            hp2.RecordTypeId = recthp[0].Id;
            hp2.Name = '病院テスト2';
 
            insert new Account[] {hp1, hp2};
 
            List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id order by Department_Class_Label__c];
            List<Account> dc2s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp2.Id order by Department_Class_Label__c];
 
            Account depart1 = new Account();
            depart1.RecordTypeId = rectDpt[0].Id;
            depart1.Name         = '*';
            depart1.Department_Name__c  = '診療科1';
            depart1.ParentId            = dc1s[0].Id;
            depart1.Department_Class__c = dc1s[0].Id;
            depart1.Hospital__c         = hp1.Id;
 
            Account depart2 = new Account();
            depart2.RecordTypeId = rectDpt[1].Id;
            depart2.Name         = '*';
            depart2.Department_Name__c  = '診療科2';
            depart2.ParentId            = dc2s[1].Id;
            depart2.Department_Class__c = dc2s[1].Id;
            depart2.Hospital__c         = hp2.Id;
 
            insert new Account[] {depart1, depart2};
            System.Test.stopTest();
 
 
            Rental_Apply__c raObj = new Rental_Apply__c(Account__c = depart1.Id
                    , Hospital__c = hp1.Id
                                    , Strategic_dept__c = dc1s[0].Id);
            raObj.Name = 'test';
            raObj.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
            raObj.Request_shipping_day__c = Date.today().addDays(3);
            raObj.Request_return_day__c = Date.today().addDays(30);
            raObj.Person_In_Charge__c = user.Id;
            raObj.demo_purpose1__c = '其他';
            raObj.demo_purpose2__c = '其他';
            raObj.Campaign__c = target.Id;
            raObj.direct_shippment_address__c = 'test';
            raObj.applyUser__c = UserInfo.getUserId();
            insert raObj;
            raObj.direct_shippment_address__c = 'test2';
            upsert raObj;
        }
    }
 
}