Li Jun
2022-03-31 3ba0123db48f8bab81ddf0913e1b95280ef545e8
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
/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditInquiryFormControllerTest {
    static testMethod void testMethod5() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        RecordType rtId1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        Account acc1 = new Account();
        acc1.Name = 'Test1 病院';
        acc1.RecordTypeId = rtId1.Id;
        insert acc1;
        RecordType rtId2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        Account acc2 = new Account();
        acc2.Name = 'Test2 戦略科室分類 呼吸科';
        acc2.RecordTypeId = rtId2.Id;
        acc2.ParentId = acc1.Id;
        acc2.Department_Class_Label__c = '呼吸科';
        acc2.Hospital_Department_Class__c = acc1.Id;
        insert acc2;
        RecordType rtId3 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科'];
        Account acc3 = new Account();
        acc3.Name = 'Test3 ';
        acc3.RecordTypeId = rtId3.Id;
        acc3.ParentId = acc2.Id;
        acc3.Department_Class__c = acc2.Id;
        acc3.Hospital__c = acc1.Id;
        insert acc3;
        Contact contact = TestDataUtility.CreateContacts(1)[0];
        contact.AccountId = acc3.Id;
        upsert contact;
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.AWS_Data_Id__c = '165';
        formTest.Hospital__c = acc1.Id;
        formTest.Department_Class__c = acc2.Id;
        formTest.Hospital_Name__c = acc3.Id;
        formTest.Contact_Name__c = contact.Id;
        System.debug('formTest: ' + formTest);
        upsert formTest;
        String url = ApexPages.currentPage().getParameters().put('CF00N1000000962n8_lkid',contact.id);
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        String jsonString = '["Department_Class__c", "Hospital__c"]';
        NewAndEditInquiryFormController.queryAccount(jsonString, contact.AccountId);
        Test.stopTest();
    }
 
    static testMethod void testMethod1() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        RecordType rtId1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        Account acc1 = new Account();
        acc1.Name = 'Test1 病院';
        acc1.RecordTypeId = rtId1.Id;
        insert acc1;
        RecordType rtId2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        Account acc2 = new Account();
        acc2.Name = 'Test2 戦略科室分類 呼吸科';
        acc2.RecordTypeId = rtId2.Id;
        acc2.ParentId = acc1.Id;
        acc2.Department_Class_Label__c = '呼吸科';
        acc2.Hospital_Department_Class__c = acc1.Id;
        insert acc2;
        RecordType rtId3 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科'];
        Account acc3 = new Account();
        acc3.Name = 'Test3 ';
        acc3.RecordTypeId = rtId3.Id;
        acc3.ParentId = acc2.Id;
        acc3.Department_Class__c = acc2.Id;
        acc3.Hospital__c = acc1.Id;
        insert acc3;
        Contact contact = TestDataUtility.CreateContacts(1)[0];
        contact.AccountId = acc3.Id;
        contact.AWS_Data_Id__c = '167895';
        upsert contact;
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.AWS_Data_Id__c = '165';
        formTest.Hospital__c = acc1.Id;
        formTest.Department_Class__c = acc2.Id;
        formTest.Hospital_Name__c = acc3.Id;
        formTest.Contact_Name__c = contact.Id;
        System.debug('formTest: ' + formTest);
        upsert formTest;
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
 
    static testMethod void testMethod2() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Account acc = TestDataUtility.CreateAccounts(1)[0];
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.Contact_Name__c = null;
        upsert formTest;
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
 
    static testMethod void testMethod3() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Account acc = TestDataUtility.CreateAccounts(1)[0];
        Inquiry_form__c formTest = new Inquiry_form__c();
        formTest.Name = 'Test InquiryForm';
        formTest.Request1__c = 'OPD'; 
        formTest.Opportunity_Division__c = '询价'; 
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
}