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
@isTest
private class CloseInventoryTaskBatchTest {
    static testMethod void testMethod1() {
        try{
            StaticParameter.EscapeContactToUser = true;
            Oly_TriggerHandler.bypass('UserProfileHandler');
            Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName());
            List<RecordType> records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划'];
 
            List<task__c> tasks = new List<task__c>();
            task__c t1 = new task__c();
            t1.Name = 'test1';
            t1.taskDifferent__c = '主动任务';
            t1.taskStatus__c = '01 分配';
            t1.assignee__c = Userinfo.getUserId();
            t1.delayToDate__c=Date.today();
            if(records.size()>0){
                t1.RecordTypeId=records.get(0).Id;
            }
            tasks.add(t1);
            task__c t2 = new task__c();
            t2.Name = 'test1';
            t2.taskDifferent__c = '主动任务';
            t2.taskStatus__c = '05 延期';
            t2.assignee__c = Userinfo.getUserId();
            t2.delayToDate__c=SYstem.today();
            if(records.size()>0){
                t2.RecordTypeId=records.get(0).Id;
            }
            tasks.add(t2);
            task__c t3 = new task__c();
            t3.Name = 'test1';
            t3.taskDifferent__c = '主动任务';
            t3.taskStatus__c = '05 延期';
            t3.assignee__c = Userinfo.getUserId();
            t3.delayToDate__c=SYstem.today();
            if(records.size()>0){
                t3.RecordTypeId=records.get(0).Id;
            }
            tasks.add(t3);
 
            System.runAs(new User(Id = Userinfo.getUserId())) {
                System.Test.startTest();
                insert tasks;
                // List<task__c> taskList=[
                //     SELECT Id, taskStatus__c 
                //     FROM task__c 
                //     WHERE taskStatus__c = '01 分配' 
                //     AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')];
                Database.executeBatch(new CloseInventoryTaskBatch(), 100);
                System.Test.stopTest();
            }
        }catch(Exception e){
 
        }
        
    }
    static testMethod void testMethod2() {
        StaticParameter.EscapeContactToUser = true;
        Oly_TriggerHandler.bypass('UserProfileHandler');
        Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName());
        List<RecordType> records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划'];
 
        List<task__c> tasks = new List<task__c>();
        task__c t1 = new task__c();
        t1.Name = 'test1';
        t1.taskDifferent__c = '主动任务';
        t1.taskStatus__c = '01 分配';
        t1.assignee__c = Userinfo.getUserId();
        if(records.size()>0){
            t1.RecordTypeId=records.get(0).Id;
        }
        tasks.add(t1);
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            System.Test.startTest();
            insert tasks;
            // List<task__c> taskList=[
            //     SELECT Id, taskStatus__c 
            //     FROM task__c 
            //     WHERE taskStatus__c = '01 分配' 
            //     AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')];
            Database.executeBatch(new CloseInventoryTaskBatch(), 100);
            System.Test.stopTest();
        }
    }
 
    static testMethod void testMethod3() {
        StaticParameter.EscapeContactToUser = true;
        Oly_TriggerHandler.bypass('UserProfileHandler');
        Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName());
        List<RecordType> records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划'];
 
        List<task__c> tasks = new List<task__c>();
        task__c t1 = new task__c();
        t1.Name = 'test1';
        t1.taskDifferent__c = '被动任务';
        t1.taskStatus__c = '01 分配';
        t1.assignee__c = Userinfo.getUserId();
        t1.taskTypeFlow__c='中标结果确认';
        t1.Task_After_3_WorkDay__c=SYstem.today();
        if(records.size()>0){
            t1.RecordTypeId=records.get(0).Id;
        }
        tasks.add(t1);
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            System.Test.startTest();
            insert tasks;
 
            // List<task__c> taskList=[
            //     SELECT Id, taskStatus__c 
            //     FROM task__c 
            //     WHERE taskStatus__c = '01 分配' 
            //     AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')];
            Database.executeBatch(new CloseInventoryTaskBatch(), 100);
            System.Test.stopTest();
        }
    }
}