高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
@isTest
private class NFM611RestTest {
    static testMethod void testMethod1() {
        
    }
    @testSetup
    static void makeTestRepair() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM105TestCompany';
        upsert company;
        Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
 
        Account depart = new Account();
        depart.RecordTypeId        = rectDpt[0].Id;
        depart.Name                = '*';
        depart.Department_Name__c  = 'NFM105TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
 
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM105Prd1';
        prd1.ProductCode            = 'NFM105Prd1';
        prd1.Repair_Product_Code__c = 'NFM105Prd1_RP';
        prd1.Name                   = 'NFM105Prd1';
        prd1.Manual_Entry__c        = false;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM105Prd2';
        prd2.ProductCode            = 'NFM105Prd2';
        prd2.Repair_Product_Code__c = 'NFM105Prd2_RP';
        prd2.Name                   = 'NFM105Prd2';
        prd2.Manual_Entry__c        = false;
        prdList.add(prd2);
        insert prdList;
 
        Asset ast = new Asset();
        ast.Name                   = 'NFM105Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.SerialNumber           = 'NFM105SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
               from Asset
               where Id = :ast.Id];
 
        // User testUser = new U1
 
        Repair__c rpr = new Repair__c();
        rpr.PAE_Determine__c = 'PAE' ;   //-- 
        rpr.ifDeadHurt__c = '有';        //-- R1
        rpr.PAE_DetermineAC__c = null;   //--
        rpr.SAPRepairNo__c   = 'NFM105Rpr1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.Status__c              = '1.受理完毕';
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Repair_Detail__c = 'test';
        rpr.GeneratedPDFField__c = null;
        rpr.AsyncData__c    = true;
        rpr.Complaint_Number__c = null;
        rpr.ReportAdverseEvents__c = '有';
        rpr.ProblemOccurred__c = '到货验收';
        rpr.ifDeadHurt__c = '有';
        rpr.ASReportedCode__c = 'TEST01,TEST02';
        rpr.ASReportedCodeAC__c = 'TEST02,TEST04';
        rpr.DateReceiptQuestions__c = Date.today();
        rpr.Failure_Occurrence_Date__c = Date.today();
        rpr.Repair_Ordered_Date__c = Date.today();
        System.runAs(new User(Id = Userinfo.getUserId())){
            insert rpr;
 
            LogisticsInformation__c logistics = new LogisticsInformation__c();
            logistics.Name = 'DF00001';
            
            logistics.LogisticsNo__c = 'DF00001'; //物流单号
            logistics.LogisticsCompany__c = 'DF'; //承运商
            logistics.LogisticsSendTime__c = Datetime.now();
            logistics.LogisticsSignTime__c = Datetime.now();//NFMUtil.parseStr2DateTime(ged.LogisticsInfo.logisticsReceiveTime); //物流签收日期
            logistics.LogisticsLatestStatus__c = '已签收';
            logistics.LogisticsType__c = '返品物流';//物流分类
            logistics.LogisticsRepair__c = rpr.Id;
            insert logistics;
        }
 
    }
    @isTest static void test_method1() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":"2021081900000022","repairNo":"'+repair.Name+'","api_type":1},"quotationInfo":{"PlanQuotationDate":"20210820120000","ActualQuotationEndTime":"20210820181717","ActualQuotationDate":"20210820140000"},"logisticsInfo":{"logisticsSendTime":"20210823120000","logisticsReceiveTime":"20210824153000","logisticsNo":"20210822001","logisticsLatestStatus":"已签收","carrier":"快递公司"},"equipReturnInfo":{"PlanReturnDate":"20210821120000","engineerType":"人员角色","ActualReturnStartTime":"20210821130000","ActualReturnDate":"20210821163000"}}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method2() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":"2021081900000022","repairNo":"'+repair.Name+'","api_type":2},"quotationInfo":{"PlanQuotationDate":"20210820120000","ActualQuotationEndTime":"20210820181717","ActualQuotationDate":"20210820140000"},"logisticsInfo":{"logisticsSendTime":"20210823120000","logisticsReceiveTime":"20210824153000","logisticsNo":"20210822001","logisticsLatestStatus":"已签收","carrier":"快递公司"},"equipReturnInfo":{"PlanReturnDate":"20210821120000","engineerType":"人员角色","ActualReturnStartTime":"20210821130000","ActualReturnDate":"20210821163000"}}]';        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method3() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":"2021081900000022","repairNo":"'+repair.Name+'","api_type":3},"quotationInfo":{"PlanQuotationDate":"20210820120000","ActualQuotationEndTime":"20210820181717","ActualQuotationDate":"20210820140000"},"logisticsInfo":{"logisticsSendTime":"20210823120000","logisticsReceiveTime":"20210824153000","logisticsNo":"20210822001","logisticsLatestStatus":"已签收","carrier":"快递公司"},"equipReturnInfo":{"PlanReturnDate":"20210821120000","engineerType":"人员角色","ActualReturnStartTime":"20210821130000","ActualReturnDate":"20210821163000"}}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method4() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":"2021081900000022","repairNo":"'+repair.Name+'","api_type":4},"quotationInfo":{"PlanQuotationDate":"20210820120000","ActualQuotationEndTime":"20210820181717","ActualQuotationDate":"20210820140000"},"logisticsInfo":{"logisticsSendTime":"20210823120000","logisticsReceiveTime":"20210824153000","logisticsNo":"20210822001","logisticsLatestStatus":"已签收","carrier":"快递公司"},"equipReturnInfo":{"PlanReturnDate":"20210821120000","engineerType":"人员角色","ActualReturnStartTime":"20210821130000","ActualReturnDate":"20210821163000"}}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method5() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":"2021081900000022","repairNo":"'+repair.Name+'","api_type":5},"quotationInfo":{"PlanQuotationDate":"20210820120000","ActualQuotationEndTime":"20210820181717","ActualQuotationDate":"20210820140000"},"logisticsInfo":{"logisticsSendTime":"202108231200111111100","logisticsReceiveTime":"2021082411111153000","logisticsNo":"20210822122222222222222222222222001","logisticsLatestStatus":"已签1111111111111111111111111111111111111111111111111111111111111111112222222211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111收","carrier":"快递公司"},"equipReturnInfo":null}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method6() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{"repairOrderInfo":{"repairOrderNo":null,"repairNo":null,"api_type":null},"quotationInfo":null,"logisticsInfo":null,"equipReturnInfo":null}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
    @isTest static void test_method7() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        Repair__c repair = [select Name from Repair__c];
 
        String JsonMsg = '[{}]';
        req.requestURI = 'services/apexrest/NFM611/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM611Rest.doPost();
        Test.stopTest();
    }
}