@isTest
|
private class AccountWebServiceTest {
|
|
static testMethod void myUnitTest() {
|
List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
|
Account acc1 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
AccountStatus__c = 'Cancel',
|
PostCode__c = '123456'
|
);
|
Account acc2 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
PostCode__c = '123456'
|
);
|
Account acc3 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
CancelReason__c = 'test',
|
PostCode__c = '123456'
|
);
|
insert new List<Account> {acc1,acc2,acc3};
|
|
String rs = '';
|
rs = AccountWebService.AccountCancel('12345678');
|
System.assertEquals('无效的客户', rs);
|
|
rs = AccountWebService.AccountCancel(acc1.Id);
|
System.assertEquals('客户已经取消', rs);
|
|
rs = AccountWebService.AccountCancel(acc2.Id);
|
System.assertEquals('必须输入取消理由', rs);
|
|
rs = AccountWebService.AccountCancel(acc3.Id);
|
System.assertEquals('1', rs);
|
List<Account> accList = [select Id,AccountStatus__c from Account where Id = :acc3.Id];
|
System.assertEquals('Cancel', accList[0].AccountStatus__c);
|
}
|
|
static testMethod void myUnitTest2() {
|
List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
|
String localid = UserInfo.getUserId();
|
|
Account acc1 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
AccountStatus__c = 'Cancel',
|
PostCode__c = '123456'
|
);
|
insert acc1;
|
|
User user = new User();
|
user.LastName = 'test20201014';
|
user.FirstName = 'test';
|
user.Alias = 'test';
|
user.Email = 'test@test.com';
|
user.Username = 'test111@test222.com';
|
user.CommunityNickname = 'test20201014';
|
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;
|
|
AccountTeamMember atm = new AccountTeamMember(
|
AccountId = acc1.Id,
|
userId = localid,
|
teamMemberRole = 'Sales Manager'
|
);
|
AccountTeamMember atm2 = new AccountTeamMember(
|
AccountId = acc1.Id,
|
userId = user.Id,
|
teamMemberRole = 'Sales Manager'
|
);
|
insert new AccountTeamMember[] {atm,atm2};
|
|
String rs = '';
|
rs = AccountWebService.UpdateShare(acc1.Id, localid, user.Id);
|
System.assertEquals('1', rs);
|
|
List<AccountTeamMember> atmList = [select Id, AccountAccessLevel from AccountTeamMember where Id = :atm.Id];
|
System.assertEquals('Edit', atmList[0].AccountAccessLevel);
|
}
|
// 技术服务部客户与联系人申请提交时字段验证
|
static testMethod void TechnicalServiceCreated() {
|
List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
|
List<RecordType> rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
|
Account acc1 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
AccountStatus__c = 'Cancel',
|
PostCode__c = '123456',
|
serviceCreate__c = true
|
);
|
Account acc2 = new Account(
|
name = '*',
|
RecordTypeId = rectBS[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
//DivisionName__c = 'Customer BS',
|
FacilityName__c = 'abc'
|
);
|
Account acc3 = new Account(
|
name = '*',
|
RecordTypeId = rectIE[0].Id,
|
OwnerId = UserInfo.getUserId(),
|
DivisionName__c = 'Customer IE',
|
FacilityName__c = 'abc',
|
DivisionName_D__c = 'Customer IE',
|
FacilityNameD__c = 'abc',
|
CancelReason__c = 'test',
|
PostCode__c = '123456'
|
);
|
User hpOwner = new User( LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.SystemAdmin2,MarketingStrategy__c =true);
|
insert hpOwner;
|
System.runAs(hpOwner){
|
insert new List<Account> {acc1,acc2,acc3};
|
|
// insert dealer;
|
Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=acc1.id);
|
insert core;
|
|
String rs = '';
|
// rs = AccountWebService.AccountCancel('12345678');
|
// System.assertEquals('无效的客户', rs);
|
|
rs = AccountWebService.RequiredField(acc1.Id);
|
// System.assertEquals('客户已经取消', rs);
|
|
rs = AccountWebService.RequiredField(acc2.Id);
|
// System.assertEquals('必须输入取消理由', rs);
|
rs = AccountWebService.ContactRequiredField(core.Id);
|
// rs = AccountWebService.AccountCancel(acc3.Id);
|
// System.assertEquals('1', rs);
|
// List<Account> accList = [select Id,AccountStatus__c from Account where Id = :acc3.Id];
|
// System.assertEquals('Cancel', accList[0].AccountStatus__c);
|
}
|
}
|
}
|