高章伟
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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@isTest
private class ReceivingNoteStockInControllerTest {
    static ReceivingNoteTestDataFactory factory;
    /**
    @description 安装master数据
    */
    @testSetup static void setupMasterData(){
        factory = new ReceivingNoteTestDataFactory();
        factory.setupMasterData();
    }
    /**
    @param typeStringListString 格式:'备品类型,管理种类;备品类型,管理种类...'
    @description 造出指定类型的清单数据,并插入数据库
    */
    static void setupTestData(String typeStringListString){
        factory = new ReceivingNoteTestDataFactory();
        if(String.isBlank(typeStringListString)){
            typeStringListString = '固定资产,个体管理;附属品,个体管理;附属品,数量管理;耗材,数量管理;低值易耗品,数量管理';
        }
        List<String> typeStringList = typeStringListString.split(';');
        factory.setupReceivingNoteData(typeStringList);
    }
 
    /**
    @description 测试初始化页面
    */
    static testMethod void unitTestInit() {
        setupTestData('固定资产,个体管理');
        ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理');
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        Test.startTest();
        controller.init();
        System.assertEquals(1, controller.esdList.size());
        Test.stopTest();
    }
 
    /**
    @description 测试保存功能
    */
    static testMethod void unitTestSave() {
        // 状态调整为已入库指示
        setupTestData('固定资产,个体管理');
        // 数据确认
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.unknow_serial_NO_product__c = 'FALSE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
        upsert rnd Product_Serial_No__c;
 
        // 收货
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('固定资产,个体管理');
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
        // 清点
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        // 验收
        rnd.Inspection_result_after__c = 'OK';
        // 再确认
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
 
        upsert rnd Product_Serial_No__c;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        controller.init();
        System.assertEquals(1, controller.esdList.size());
        // 保存前
        ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0];
        System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo.rec.WH_location__c);
        System.assertEquals(true, esdInfo.editable);
        // 修改
        Test.startTest();
        esdInfo.rec.Arrival_in_wh__c = true;
        esdInfo.rec.WH_location__c = '123';
        controller.save();
        Test.stopTest();
        // 检查保存结果
        List<ReceivingNoteDetail__c> rndList = [
                SELECT Arrival_in_wh__c
                     , WH_location__c
                  FROM ReceivingNoteDetail__c
              ORDER BY SerialNumber__c
            ];
        System.assertEquals(true,rndList[0].Arrival_in_wh__c);
        System.assertEquals('123',rndList[0].WH_location__c);
        System.assertEquals(false, controller.esdList[0].editable);
    }
    /**
    @description 一对一入库
    */
    static testMethod void unitTestSaveOneToOne() {
        setupTestData('固定资产,个体管理');
        // 修改成一对一配套
        Fixture_Set_Detail__c fsd0 = factory.fsdList[0];
        Fixture_Set_Detail__c fsd1 = factory.fsdList[1];
        fsd0.Is_Body__c = true;
        fsd1.Is_Body__c = false;
        fsd1.Is_OneToOne__c = true;
 
        update new Fixture_Set_Detail__c[] {fsd0, fsd1};
 
        // 状态调整为已入库指示
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('固定资产,个体管理');
 
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.unknow_serial_NO_product__c = 'TRUE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
 
        ReceivingNoteDetail__c rnd1 = new ReceivingNoteDetail__c();
        rnd1.DataMigration_Flag__c = true;
        rnd1.ReceivingNoteSummary__c = rns.Id;
        rnd1.FSD_Id__c = factory.fsdList[1].Id;
        rnd1.unknow_serial_NO_product__c = 'TRUE';
        rnd1.Loaner_accsessary__c = 'TRUE';
        rnd1.Fixture_Set_Detail__c = factory.fsdList[1].Id;
        rnd1.Product_Serial_No__c = 'SB-PRO-SERIAL-'+2;
        rnd1.passNo2__c = '02';
        rnd1.passNo3__c = '2';
        rnd1.SerialNumber__c = 'SB-ASSET-SERIAL-6';
        rnd1.DataConfirmation__c = true;
        upsert new ReceivingNoteDetail__c[] {rnd, rnd1} Product_Serial_No__c;
 
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
 
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        rnd.Inspection_result_after__c = 'OK';
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
 
        rnd1.AcceptanceTime__c = System.Now();
        rnd1.AcceptanceResult__c = 'OK';
        rnd1.Inspection_result_after__c = 'OK';
        rnd1.DataConfirmationAgain__c = true;
        rnd1.Arrival_wh_Request_time__c = System.Now();
        rnd1.Salesdepartment__c = '1.华北营业本部';
        rnd1.Product_category__c = 'GI';
        rnd1.Equipment_Type__c = '产品试用';
 
        update new ReceivingNoteDetail__c[] {rnd, rnd1};
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        controller.init();
        System.assertEquals(2, controller.esdList.size());
        // 保存前
        ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0];
        System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo.rec.WH_location__c);
        System.assertEquals(true, esdInfo.editable);
        ReceivingNoteStockInController.EsdInfo esdInfo1 = controller.esdList[1];
        System.assertEquals(false,esdInfo1.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo1.rec.WH_location__c);
        System.assertEquals(true, esdInfo1.editable);
        // 修改
        Test.startTest();
        esdInfo.rec.Arrival_in_wh__c = true;
        esdInfo.rec.WH_location__c = '123';
        esdInfo1.rec.Arrival_in_wh__c = true;
        esdInfo1.rec.WH_location__c = '321';
        controller.save();
        Test.stopTest();
        // 检查保存结果
        List<ReceivingNoteDetail__c> rndList = [
                SELECT Arrival_in_wh__c
                     , WH_location__c
                  FROM ReceivingNoteDetail__c
              ORDER BY Product_Serial_No__c
            ];
        System.assertEquals(true,rndList[0].Arrival_in_wh__c);
        System.assertEquals('123',rndList[0].WH_location__c);
        System.assertEquals(false, controller.esdList[0].editable);
 
        System.assertEquals(true,rndList[1].Arrival_in_wh__c);
        System.assertEquals('321',rndList[1].WH_location__c);
        System.assertEquals(false, controller.esdList[1].editable);
    }
    /**
    @description 取照片
    */
    static testMethod void unitTestFetchPhotoStatus() {
        setupTestData('固定资产,个体管理');
        ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理');
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.Arrival_wh_Request_time__c = Datetime.now();
        update rnd;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        Test.startTest();
        controller.init();
        controller.fetchPhotoStatus();
        Test.stopTest();
 
        System.assertEquals(1, controller.esdList.size());
        System.assertEquals(true, controller.esdList[0].editable);
 
    }
    /**
    @description 耗材入库
    */
    static testMethod void unitTestSaveConsum() {
        // 状态调整为已入库指示
        setupTestData('耗材,数量管理');
        // 数据确认
        ReceivingNoteDetail__c rnd = factory.rndMap.get('耗材,数量管理');
        rnd.unknow_serial_NO_product__c = 'FALSE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
        upsert rnd Product_Serial_No__c;
 
        // 收货
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('耗材,数量管理');
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
        // 清点
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        // 验收
        rnd.Inspection_result_after__c = 'OK';
        // 再确认
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
 
        upsert rnd Product_Serial_No__c;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        controller.init();
        System.assertEquals(1, controller.esdList.size());
        // 保存前
        ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0];
        System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo.rec.WH_location__c);
        System.assertEquals(true, esdInfo.editable);
        // 修改
        Test.startTest();
        esdInfo.rec.Arrival_in_wh__c = true;
        esdInfo.rec.WH_location__c = '123';
        controller.save();
        Test.stopTest();
        // 检查保存结果
        List<ReceivingNoteDetail__c> rndList = [
                SELECT Arrival_in_wh__c
                     , WH_location__c
                  FROM ReceivingNoteDetail__c
              ORDER BY SerialNumber__c
            ];
        System.assertEquals(true,rndList[0].Arrival_in_wh__c);
        System.assertEquals('123',rndList[0].WH_location__c);
        System.assertEquals(false, controller.esdList[0].editable);
    }
    /**
    @description 个体变体入库,直接对接口Asset修改
    */
    static testMethod void unitTestBiantiSave() {
        // 状态调整为已入库指示
        setupTestData('固定资产,个体管理');
        // 数据确认
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.unknow_serial_NO_product__c = 'FALSE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
        rnd.Fixture_Arrival_Process__c = '变体';
        rnd.Fixture_Arrival_Product__c = factory.proList[2].Id;
        upsert rnd Product_Serial_No__c;
 
        // 收货
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('固定资产,个体管理');
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
        // 清点
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        // 验收
        rnd.Inspection_result_after__c = 'OK';
        // 再确认
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
 
        upsert rnd Product_Serial_No__c;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        controller.init();
        System.assertEquals(1, controller.esdList.size());
        // 保存前
        ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0];
        System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo.rec.WH_location__c);
        System.assertEquals(true, esdInfo.editable);
        // 入库前的Asset
        List<Asset> assList = [SELECT Id,Fixture_Model_No_F__c,AccountId,Product2Id,Product_Old__c FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c];
        System.assertEquals(factory.accountMap.get('备品(待收货)').Id, assList[0].AccountId) ;
        System.assertEquals(null, assList[0].Product_Old__c) ;
        System.assertEquals(factory.proList[0].Id, assList[0].Product2Id) ;
 
        // 修改
        Test.startTest();
        esdInfo.rec.Arrival_in_wh__c = true;
        esdInfo.rec.WH_location__c = '123';
        controller.save();
        Test.stopTest();
        // 检查保存结果
        List<ReceivingNoteDetail__c> rndList = [
                SELECT Arrival_in_wh__c
                     , WH_location__c
                  FROM ReceivingNoteDetail__c
              ORDER BY SerialNumber__c
            ];
        System.assertEquals(true,rndList[0].Arrival_in_wh__c);
        System.assertEquals('123',rndList[0].WH_location__c);
        System.assertEquals(false, controller.esdList[0].editable);
        // 入库后Asset
        assList = [SELECT Id,Fixture_Model_No_F__c,AccountId,Product2Id,Product_Old__c FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c];
        System.assertEquals(factory.accountMap.get('备品').Id, assList[0].AccountId) ;
        System.assertEquals(factory.proList[0].Id, assList[0].Product_Old__c) ;
        System.assertEquals(factory.proList[2].Id, assList[0].Product2Id) ;
 
    }
 
    /**
    @description 合并入库
    */
    static testMethod void unitTestHebingSave() {
        // 状态调整为已入库指示
        setupTestData('固定资产,个体管理');
        // 数据确认
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.unknow_serial_NO_product__c = 'FALSE';
        rnd.Loaner_accsessary__c = 'TRUE';
        rnd.DataConfirmation__c = true;
        rnd.Fixture_Arrival_Process__c = '合并';
        upsert rnd Product_Serial_No__c;
 
        // 收货
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('固定资产,个体管理');
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
        // 清点
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        // 验收
        rnd.Inspection_result_after__c = 'OK';
        // 再确认
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
 
        upsert rnd Product_Serial_No__c;
 
        PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id);
        Test.setCurrentPage(ref);
 
        ReceivingNoteStockInController controller = new ReceivingNoteStockInController();
 
        controller.init();
        System.assertEquals(1, controller.esdList.size());
        // 保存前
        ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0];
        System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c);
        System.assertEquals(null,esdInfo.rec.WH_location__c);
        System.assertEquals(true, esdInfo.editable);
        // 变体前的Asset
        List<Asset> assList = [SELECT Id,Fixture_Model_No_F__c,AccountId FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c];
        System.assertEquals(factory.accountMap.get('备品(待收货)').Id, assList[0].AccountId) ;
 
        // 修改
        Test.startTest();
        esdInfo.rec.Arrival_in_wh__c = true;
        esdInfo.rec.WH_location__c = '123';
        controller.save();
        Test.stopTest();
        // 检查保存结果
        List<ReceivingNoteDetail__c> rndList = [
                SELECT Arrival_in_wh__c
                     , WH_location__c
                  FROM ReceivingNoteDetail__c
              ORDER BY SerialNumber__c
            ];
        System.assertEquals(true,rndList[0].Arrival_in_wh__c);
        System.assertEquals('123',rndList[0].WH_location__c);
        System.assertEquals(false, controller.esdList[0].editable);
        // 变体前的Asset
        assList = [SELECT Id,Fixture_Model_No_F__c,AccountId FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c];
        System.assertEquals(factory.accountMap.get('备品(已收货)').Id, assList[0].AccountId) ;
 
    }
}