@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);
    }
}