GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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 OpportunityWebServiceTest {
 
    static testMethod void myUnitTest() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Account acc1 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            PostCode__c='000000'
        );
        insert acc1;
        
        Opportunity opp1 = new Opportunity(
            name = 'test opp1',
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            AccountId = acc1.Id,
            StageName = 'Prospect Created',
            SalesChannel__c = 'direct',
            CloseDate = Date.valueof('1900-01-01')
        );
        insert opp1;
        
        String rs = '';
        rs = OpportunityWebService.UpdateStageName(opp1.Id, 'Phase1');
        System.assertEquals('1', rs);
        
        List<Opportunity> oppList = [select Id, StageName from Opportunity where Id = :opp1.Id];
        System.assertEquals('Phase1', oppList[0].StageName);
    }
    
    static testMethod void myUnitTest2() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Account acc1 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            PostCode__c='000000'
        );
        insert acc1;
        
        Opportunity opp1 = new Opportunity(
            name = 'test opp1',
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            AccountId = acc1.Id,
            StageName = 'Prospect Created',
            SalesChannel__c = 'direct',
            CloseDate = Date.valueof('1900-01-01')
        );
        insert opp1;
        
        User user = new User();
        user.LastName = 'test';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'test@test.com';
        user.Username = 'test111@test222.com';
        user.CommunityNickname = 'test';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.SystemAdmin;
        insert user;
        
        OpportunityTeamMember otm = new OpportunityTeamMember(
            opportunityId = opp1.Id,
            userId = user.Id,
            teamMemberRole = 'Sales Manager'
        );
        insert otm;
        
        String rs = '';
        rs = OpportunityWebService.UpdateShare(opp1.Id, user.Id);
        System.assertEquals('1', rs);
        
        List<OpportunityTeamMember> otmList = [select Id, OpportunityAccessLevel from OpportunityTeamMember where Id = :otm.Id];
        System.assertEquals('Edit', otmList[0].OpportunityAccessLevel);
 
        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp1.Id
        );
        insert quo;
 
        rs = '';
        rs = OpportunityWebService.Upload2Sap(opp1.Id, quo.Name, quo.Id);
        System.assertEquals('1', rs);
    }
}