高章伟
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@isTest
private class OncallFinalStatusManagerTester {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    private static Account hospital = null;
    private static List<Account> strategicDep = null;
    private static Product2 productA = null;
    private static Account dep = null;
    private static PricebookEntry entry = null;
    private static Asset asset = null;
    private static Maintenance_Contract__c contract = null;
    static {
 
        Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
 
        // 病院を作る
        hospital = new Account();
        hospital.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        hospital.Name = 'test hospital';
        insert hospital;
        /*
        为了对应0914的Opptrigger改变,新增
            测试User
        */
        //RecordType rt = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Target').getRecordTypeId();
        
        // システム管理者
       
       
        // 戦略科室を得る
        strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        // 診療科を作る
        dep = new Account();
        dep.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 製品を作る
        productA = new Product2( Name='テスト商品');
        insert productA;
        
        // 価格表エントリを作成する     
        entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
        
        // 納入機器を作成する
        asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep[0].Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.Guarantee_period_for_products__c = Date.today();
        asset.InstallDate                      = Date.today();
        insert asset;
        
        // 维修合同を作成する
        contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        insert contract;
    }
 
    static testMethod void test01() {
System.debug( '-----:test01');
      
        // On-Callをつくる
        On_Call__c onCall = new On_Call__c();
        onCall.segment__c = dep.Id;
        onCall.Hospital__c = hospital.Id;
        insert onCall;
        
        OncallFinalStatusManager.callCount = 0;
        
        // 修理を作成する
        Repair__c repair = new Repair__c();
        repair.Account__c = dep.Id;
        repair.Department_Class__c = strategicDep[0].Id;
        repair.Hospital__c = hospital.Id;
        repair.On_Call_ID__c = onCall.Id;
        repair.Delivered_Product__c = asset.Id;
        insert repair;
 
        OncallFinalStatusManager.callCount = 0;
 
        // QISを作る
        QIS_Report__c qis = new QIS_Report__c();
        qis.Source_OnCall__c = onCall.Id;
        qis.nonyushohin__c = asset.Id;
        qis.Hospital__c = hospital.Id;
        qis.RC__c = UserInfo.getUserId();
        qis.Department_Class__c = strategicDep[0].Id;
        qis.Hospital_Department__c = dep.Id;
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        insert qis;
    
    }
 
    static testMethod void test02() {
System.debug( '-----:test02');
        // On-Callをつくる
        System.Test.startTest();
        On_Call__c onCall = new On_Call__c();
        onCall.segment__c = dep.Id;
        onCall.Hospital__c = hospital.Id;
        insert onCall;
        
        OncallFinalStatusManager.callCount = 0;
        
        // QISを作る
        QIS_Report__c qis = new QIS_Report__c();
        qis.Source_OnCall__c = onCall.Id;
        qis.nonyushohin__c = asset.Id;
        qis.Hospital__c = hospital.Id;
        qis.RC__c = UserInfo.getUserId();
        qis.Department_Class__c = strategicDep[0].Id;
        qis.Hospital_Department__c = dep.Id;
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        insert qis;
 
        OncallFinalStatusManager.callCount = 0;
 
        // 修理を作成する
        Repair__c repair = new Repair__c();
        repair.Account__c = dep.Id;
        repair.Department_Class__c = strategicDep[0].Id;
        repair.Hospital__c = hospital.Id;
        repair.On_Call_ID__c = onCall.Id;
        repair.Delivered_Product__c = asset.Id;
        insert repair;
 
        delete repair;
        delete qis;
        update onCall;
        System.Test.stopTest();
}
    static testMethod void test03() {
System.debug( '-----:test03');
        // On-Callをつくる
        On_Call__c onCall = new On_Call__c();
        onCall.segment__c = dep.Id;
        onCall.Hospital__c = hospital.Id;
        insert onCall;
        OncallFinalStatusManager.callCount = 0;
        update onCall;
    }
}