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
@isTest
private class lexLostCancelReportControllerTest {
    static testMethod void test1(){
        // recode type を取得
        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, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 recodetype');
        }
        List<RecordType> rectLost = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Lost_cancel_report__c' and DeveloperName IN ('PCL_Lost_report', 'PCL_Cancel_report') order by DeveloperName desc];
        if (rectLost.size() == 0) {
            throw new ControllerUtil.myException('not found Lost_cancel_report recodetype');
        }
 
        // insert
        Account company1 = new Account();
        Account company2 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company2.RecordTypeId = rectCo[0].Id;
        company2.Name = '病院テスト2';
        insert new Account[] {company1, company2};
 
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        List<Account> dc2s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company2.Id order by Department_Class_Label__c];
 
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
 
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dc2s[1].Id;
        depart2.Department_Class__c = dc2s[1].Id;
        depart2.Hospital__c         = company2.Id;
 
        insert new Account[] {depart1, depart2};
 
        // まずひとつ追加
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = true;
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'HistoryPrd2';
        prd2.ProductCode            = 'HistoryPrd2';
        prd2.Repair_Product_Code__c = 'HistoryPrd2_RP';
        prd2.Name                   = 'HistoryPrd2';
        prd2.Manual_Entry__c        = true;
        insert new Product2[] {prd1, prd2};
 
        // 商談
        Opportunity opp1 = new Opportunity(Name='aiueo', StageName='contact', CloseDate=Date.today(),
            Hospital__c = company1.Id,
            Department_Class__c = dc1s[0].Id,
            AccountId = depart1.Id
        );
        Opportunity opp2 = new Opportunity(Name='aiueo', StageName='contact', CloseDate=Date.today(),
            Hospital__c = company2.Id,
            Department_Class__c = dc2s[0].Id,
            AccountId = depart2.Id
        );
        insert new Opportunity[] {opp1, opp2};
 
        // 失单
        Lost_cancel_report__c lcr1 = new Lost_cancel_report__c(
            Opportunity__c = opp1.Id, 
            RecordTypeId = rectLost[0].Id
        );
        // 取消
        Lost_cancel_report__c lcr2 = new Lost_cancel_report__c(
            Opportunity__c = opp2.Id, 
            RecordTypeId = rectLost[1].Id
        );
        insert new Lost_cancel_report__c[] {lcr1, lcr2};
        Test.startTest();
        lexLostCancelReportController.initForEditCancelReport(lcr2.Id);
        lexLostCancelReportController.initSubmitReportButton(lcr2.Id);
        lexLostCancelReportController.updateSubmitReportButton(lcr2.Id);
        lexLostCancelReportController.updateSubmitReportButton(rectLost[0].Id);
        Test.stopTest();
    }
}