liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
@isTest
private class ConsumApplyTriggerHandlerTest {
 
    //deloitte-zhj 20231023 增加覆盖率 start
    // @TestSetup
    // static void setup(){
    //     TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Consum_Apply__c'});
    // } 
 
    class HttpMock implements HttpCalloutMock{   
        public HTTPResponse respond(HTTPRequest request) {
            // 创建一个假的回应
            System.debug('------------------------------------------------------');
            HttpResponse response = new HttpResponse();
            string body = '';
            system.debug(request.getEndpoint());
            if(request.getEndpoint().contains('token')){
                system.debug('url=token');
                response.setHeader('Content-Type', 'application/json');
                body='{ "message": "", "object": "freqfewqfewewfewfew", "status": "", "success": true, "timestamp": 0, "txId": "" }';          
            } else if(request.getEndpoint().contains('insert')){
                system.debug('url=Insert');
                response.setHeader('Content-Type', 'application/json');
                body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';          
            } else if(request.getEndpoint().contains('update')){
                system.debug('url=update');
                response.setHeader('Content-Type', 'application/json');
                body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';          
            } else{
            
            }
            response.setBody(body);
            response.setStatus('OK');
            response.setStatusCode(200);
            return response;
        }
    }
 
    // @isTest
    static testMethod void Test1(){
        Test.startTest();
        TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Consum_Apply__c'});
        Test.setMock(HttpCalloutMock.class, new HttpMock());
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User u = new User( Alias = 'test213123',
                Email = 'testuser'+'zhj'+'@olympus.com',
                Emailencodingkey = 'UTF-8', 
                Lastname = 'TestUser'+'zhj123', 
                Languagelocalekey = 'zh_CN',
                Localesidkey = 'zh_CN', 
                Profileid = p.id, 
                Country = 'China',
                IsActive = true,
                Timezonesidkey = 'America/Sao_Paulo', 
                Username = 'testuser'+'zhj123'+'@olympus.com',
                Job_Category__c = '销售服务'
        );
        Consum_Apply__c oldCa = TestDataUtility.CreateConsumApply(1)[0];
        Consum_Apply__c newCa = new Consum_Apply__c();
        newCa.Name = 'Test_20231023';
        newCa.Status__c = '草案中';
        newCa.Person_In_Charge__c = u.Id;//备品出借担当
        newCa.Old_Consum_Apply__c = oldCa.Id;
        insert newCa;
        // List<Consum_Apply__c> fendanList = new List<Consum_Apply__c>();
        // fendanList.add(newCa);
        // ConsumApplyTriggerHandler.decryptInsertFuture(JSON.serialize(fendanList));
        Test.stopTest();
    }
    //deloitte-zhj 20231023 增加覆盖率 end
 
    static testMethod void testMethod1() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
    }
 
    // static ConsumTestDataFactory factory;
    // // 造 两个一览,各一条明细,草案中
    // @testSetup static void setupTestData(){
    //     ConsumTestDataFactory factory = new ConsumTestDataFactory();
    //     factory.setupTestData();
    //     factory.selectDetails(2);
    //     TestDataUtility.CreatePIPolicyConfiguration();
    // }
    // 䓍案中分单
    static testMethod void testSaveSplitError() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails(2);
        TestDataUtility.CreatePIPolicyConfiguration();
        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c];
        List<Consum_Apply_Equipment_Set__c> caesList = [SELECT Id FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c=:ca.Id];
        System.assertEquals(2, caesList .size());
 
        PageReference ref = new PageReference('/apex/ConsumApplySplit');
        ref.getParameters().put('objId', ca.Id);
        ref.getParameters().put('raesIds', caesList[0].Id);
        Test.setCurrentPage(ref);
        ConsumApplySplitController controller = new ConsumApplySplitController();
        controller.init();
 
        Test.startTest();
        controller.cloneRas.Split_Apply_Reason__c = '分批发货分单';
        controller.saveSplit();
        Test.stopTest();
 
        // 分单失败,只有一个申请
        List<Consum_Apply__c> caList = [SELECT Id FROM Consum_Apply__c];
        System.assertEquals(1, caList.size());
    }
 
    // 批准后分单
    static testMethod void testSaveSplit() {
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails(2);
        TestDataUtility.CreatePIPolicyConfiguration();
        // 变成已批准
        // ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.approve();
 
        List<Consum_Apply_Equipment_Set__c> caesList = [SELECT Id FROM Consum_Apply_Equipment_Set__c WHERE Consum_Apply__c=:factory.ca.Id];
        System.assertEquals(2, caesList .size());
 
        PageReference ref = new PageReference('/apex/ConsumApplySplit');
        ref.getParameters().put('objId', factory.ca.Id);
        ref.getParameters().put('raesIds', caesList[0].Id);
        Test.setCurrentPage(ref);
        ConsumApplySplitController controller = new ConsumApplySplitController();
        controller.init();
 
        Test.startTest();
        controller.cloneRas.Split_Apply_Reason__c = '分批发货分单';
        controller.saveSplit();
        Test.stopTest();
 
        // 分单成功,有两个申请
        List<Consum_Apply__c> caList = [SELECT Id FROM Consum_Apply__c];
        System.assertEquals(2, caList.size());
    }
 
    static testMethod void testCoverUp() {
        ConsumApplyTriggerHandler.test();
    }
}