mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-02-20 19:20:32 +08:00
✨ CRM:单测暂时不写
This commit is contained in:
parent
9ea7bde751
commit
4bf4432f93
@ -1,119 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypePageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypeSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusTypeDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessStatusTypeMapper;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_STATUS_TYPE_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:后续再 review
|
||||
/**
|
||||
* {@link CrmBusinessStatusTypeServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author ljlleo
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmBusinessStatusTypeServiceImpl.class)
|
||||
public class BusinessStatusTypeServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmBusinessStatusTypeServiceImpl businessStatusTypeService;
|
||||
|
||||
@Resource
|
||||
private CrmBusinessStatusTypeMapper businessStatusTypeMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateBusinessStatusType_success() {
|
||||
// 准备参数
|
||||
CrmBusinessStatusTypeSaveReqVO createReqVO = randomPojo(CrmBusinessStatusTypeSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long businessStatusTypeId = businessStatusTypeService.createBusinessStatusType(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(businessStatusTypeId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmBusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(businessStatusTypeId);
|
||||
assertPojoEquals(createReqVO, businessStatusType, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBusinessStatusType_success() {
|
||||
// mock 数据
|
||||
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class);
|
||||
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmBusinessStatusTypeSaveReqVO updateReqVO = randomPojo(CrmBusinessStatusTypeSaveReqVO.class, o -> {
|
||||
o.setId(dbBusinessStatusType.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
businessStatusTypeService.updateBusinessStatusType(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
CrmBusinessStatusTypeDO businessStatusType = businessStatusTypeMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, businessStatusType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBusinessStatusType_notExists() {
|
||||
// 准备参数
|
||||
CrmBusinessStatusTypeSaveReqVO updateReqVO = randomPojo(CrmBusinessStatusTypeSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> businessStatusTypeService.updateBusinessStatusType(updateReqVO), BUSINESS_STATUS_TYPE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBusinessStatusType_success() {
|
||||
// mock 数据
|
||||
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class);
|
||||
businessStatusTypeMapper.insert(dbBusinessStatusType);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbBusinessStatusType.getId();
|
||||
|
||||
// 调用
|
||||
businessStatusTypeService.deleteBusinessStatusType(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(businessStatusTypeMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBusinessStatusType_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> businessStatusTypeService.deleteBusinessStatusType(id), BUSINESS_STATUS_TYPE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetBusinessStatusTypePage() {
|
||||
// mock 数据
|
||||
CrmBusinessStatusTypeDO dbBusinessStatusType = randomPojo(CrmBusinessStatusTypeDO.class, o -> { // 等会查询到
|
||||
});
|
||||
businessStatusTypeMapper.insert(dbBusinessStatusType);
|
||||
// 准备参数
|
||||
CrmBusinessStatusTypePageReqVO reqVO = new CrmBusinessStatusTypePageReqVO();
|
||||
|
||||
// 调用
|
||||
PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbBusinessStatusType, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* {@link CrmBusinessServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author ljlleo
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmBusinessServiceImpl.class)
|
||||
public class CrmBusinessServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmBusinessServiceImpl businessService;
|
||||
|
||||
@Resource
|
||||
private CrmBusinessMapper businessMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateBusiness_success() {
|
||||
// 准备参数
|
||||
CrmBusinessSaveReqVO reqVO = randomPojo(CrmBusinessSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long businessId = businessService.createBusiness(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertNotNull(businessId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmBusinessDO business = businessMapper.selectById(businessId);
|
||||
assertPojoEquals(reqVO, business);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBusiness_success() {
|
||||
// mock 数据
|
||||
CrmBusinessDO dbBusiness = randomPojo(CrmBusinessDO.class);
|
||||
businessMapper.insert(dbBusiness);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmBusinessSaveReqVO reqVO = randomPojo(CrmBusinessSaveReqVO.class, o -> {
|
||||
o.setId(dbBusiness.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
businessService.updateBusiness(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmBusinessDO business = businessMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, business);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBusiness_notExists() {
|
||||
// 准备参数
|
||||
CrmBusinessSaveReqVO reqVO = randomPojo(CrmBusinessSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> businessService.updateBusiness(reqVO), BUSINESS_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBusiness_success() {
|
||||
// mock 数据
|
||||
CrmBusinessDO dbBusiness = randomPojo(CrmBusinessDO.class);
|
||||
businessMapper.insert(dbBusiness);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbBusiness.getId();
|
||||
|
||||
// 调用
|
||||
businessService.deleteBusiness(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(businessMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBusiness_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> businessService.deleteBusiness(id), BUSINESS_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetBusinessPage() {
|
||||
// mock 数据
|
||||
CrmBusinessDO dbBusiness = randomPojo(CrmBusinessDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatusTypeId(null);
|
||||
o.setStatusId(null);
|
||||
o.setContactNextTime(null);
|
||||
o.setCustomerId(null);
|
||||
o.setDealTime(null);
|
||||
o.setPrice(null);
|
||||
o.setDiscountPercent(null);
|
||||
o.setProductPrice(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
o.setEndStatus(null);
|
||||
o.setEndRemark(null);
|
||||
o.setContactLastTime(null);
|
||||
o.setFollowUpStatus(null);
|
||||
});
|
||||
businessMapper.insert(dbBusiness);
|
||||
// 测试 name 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setName(null)));
|
||||
// 测试 statusTypeId 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setStatusTypeId(null)));
|
||||
// 测试 statusId 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setStatusId(null)));
|
||||
// 测试 contactNextTime 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setContactNextTime(null)));
|
||||
// 测试 customerId 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setCustomerId(null)));
|
||||
// 测试 dealTime 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setDealTime(null)));
|
||||
// 测试 price 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setPrice(null)));
|
||||
// 测试 discountPercent 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setDiscountPercent(null)));
|
||||
// 测试 productPrice 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setProductPrice(null)));
|
||||
// 测试 remark 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRemark(null)));
|
||||
// 测试 createTime 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setCreateTime(null)));
|
||||
// 测试 endStatus 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setEndStatus(null)));
|
||||
// 测试 endRemark 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setEndRemark(null)));
|
||||
// 测试 contactLastTime 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setContactLastTime(null)));
|
||||
// 测试 followUpStatus 不匹配
|
||||
businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setFollowUpStatus(null)));
|
||||
//// 准备参数
|
||||
//CrmBusinessPageReqVO reqVO = new CrmBusinessPageReqVO();
|
||||
//reqVO.setName(null);
|
||||
//reqVO.setStatusTypeId(null);
|
||||
//reqVO.setStatusId(null);
|
||||
//reqVO.setContactNextTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
//reqVO.setCustomerId(null);
|
||||
//reqVO.setDealTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
//reqVO.setPrice(null);
|
||||
//reqVO.setDiscountPercent(null);
|
||||
//reqVO.setProductPrice(null);
|
||||
//reqVO.setRemark(null);
|
||||
//reqVO.setOwnerUserId(null);
|
||||
//reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
//reqVO.setRoUserIds(null);
|
||||
//reqVO.setRwUserIds(null);
|
||||
//reqVO.setEndStatus(null);
|
||||
//reqVO.setEndRemark(null);
|
||||
//reqVO.setContactLastTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
//reqVO.setFollowUpStatus(null);
|
||||
//
|
||||
//// 调用
|
||||
//PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(reqVO);
|
||||
//// 断言
|
||||
//assertEquals(1, pageResult.getTotal());
|
||||
//assertEquals(1, pageResult.getList().size());
|
||||
//assertPojoEquals(dbBusiness, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,207 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.clue;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:单测后续补;
|
||||
|
||||
/**
|
||||
* {@link CrmClueServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author Wanwan
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmClueServiceImpl.class)
|
||||
public class CrmClueServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmClueServiceImpl clueService;
|
||||
|
||||
@Resource
|
||||
private CrmClueMapper clueMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateClue_success() {
|
||||
// 准备参数
|
||||
CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long clueId = clueService.createClue(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertNotNull(clueId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmClueDO clue = clueMapper.selectById(clueId);
|
||||
assertPojoEquals(reqVO, clue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClue_success() {
|
||||
// mock 数据
|
||||
CrmClueDO dbClue = randomPojo(CrmClueDO.class);
|
||||
clueMapper.insert(dbClue);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class, o -> {
|
||||
o.setId(dbClue.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
clueService.updateClue(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmClueDO clue = clueMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, clue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClue_notExists() {
|
||||
// 准备参数
|
||||
CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> clueService.updateClue(reqVO), CLUE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClue_success() {
|
||||
// mock 数据
|
||||
CrmClueDO dbClue = randomPojo(CrmClueDO.class);
|
||||
clueMapper.insert(dbClue);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbClue.getId();
|
||||
|
||||
// 调用
|
||||
clueService.deleteClue(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(clueMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClue_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> clueService.deleteClue(id), CLUE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCluePage() {
|
||||
// mock 数据
|
||||
CrmClueDO dbClue = randomPojo(CrmClueDO.class, o -> { // 等会查询到
|
||||
o.setTransformStatus(null);
|
||||
o.setFollowUpStatus(null);
|
||||
o.setName(null);
|
||||
o.setCustomerId(null);
|
||||
o.setContactNextTime(null);
|
||||
o.setTelephone(null);
|
||||
o.setMobile(null);
|
||||
o.setAddress(null);
|
||||
o.setContactLastTime(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
clueMapper.insert(dbClue);
|
||||
// 测试 transformStatus 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTransformStatus(null)));
|
||||
// 测试 followUpStatus 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setFollowUpStatus(null)));
|
||||
// 测试 name 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setName(null)));
|
||||
// 测试 customerId 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCustomerId(null)));
|
||||
// 测试 contactNextTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactNextTime(null)));
|
||||
// 测试 telephone 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTelephone(null)));
|
||||
// 测试 mobile 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
|
||||
// 测试 address 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
|
||||
// 测试 contactLastTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
|
||||
// 测试 createTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
CrmCluePageReqVO reqVO = new CrmCluePageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setTelephone(null);
|
||||
reqVO.setMobile(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CrmClueDO> pageResult = clueService.getCluePage(reqVO, 1L);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbClue, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetClueList() {
|
||||
// mock 数据
|
||||
CrmClueDO dbClue = randomPojo(CrmClueDO.class, o -> { // 等会查询到
|
||||
o.setTransformStatus(null);
|
||||
o.setFollowUpStatus(null);
|
||||
o.setName(null);
|
||||
o.setCustomerId(null);
|
||||
o.setContactNextTime(null);
|
||||
o.setTelephone(null);
|
||||
o.setMobile(null);
|
||||
o.setAddress(null);
|
||||
o.setContactLastTime(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
clueMapper.insert(dbClue);
|
||||
// 测试 transformStatus 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTransformStatus(null)));
|
||||
// 测试 followUpStatus 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setFollowUpStatus(null)));
|
||||
// 测试 name 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setName(null)));
|
||||
// 测试 customerId 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCustomerId(null)));
|
||||
// 测试 contactNextTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactNextTime(null)));
|
||||
// 测试 telephone 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setTelephone(null)));
|
||||
// 测试 mobile 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
|
||||
// 测试 address 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
|
||||
// 测试 contactLastTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
|
||||
// 测试 createTime 不匹配
|
||||
clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
CrmCluePageReqVO reqVO = new CrmCluePageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setTelephone(null);
|
||||
reqVO.setMobile(null);
|
||||
reqVO.setPageSize(PAGE_SIZE_NONE);
|
||||
// 调用
|
||||
List<CrmClueDO> list = clueService.getCluePage(reqVO, 1L).getList();
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbClue, list.get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.contract;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link CrmContractServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author dhb52
|
||||
*/
|
||||
@Import(CrmContractServiceImpl.class)
|
||||
public class ContractServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmContractServiceImpl contractService;
|
||||
|
||||
@Resource
|
||||
private CrmContractMapper contractMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateContract_success() {
|
||||
// 准备参数
|
||||
CrmContractSaveReqVO reqVO = randomPojo(CrmContractSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long contractId = contractService.createContract(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertNotNull(contractId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmContractDO contract = contractMapper.selectById(contractId);
|
||||
assertPojoEquals(reqVO, contract);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateContract_success() {
|
||||
// mock 数据
|
||||
CrmContractDO dbContract = randomPojo(CrmContractDO.class);
|
||||
contractMapper.insert(dbContract);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmContractSaveReqVO reqVO = randomPojo(CrmContractSaveReqVO.class, o -> {
|
||||
o.setId(dbContract.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
contractService.updateContract(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmContractDO contract = contractMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, contract);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateContract_notExists() {
|
||||
// 准备参数
|
||||
CrmContractSaveReqVO reqVO = randomPojo(CrmContractSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> contractService.updateContract(reqVO), CONTRACT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteContract_success() {
|
||||
// mock 数据
|
||||
CrmContractDO dbContract = randomPojo(CrmContractDO.class);
|
||||
contractMapper.insert(dbContract);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbContract.getId();
|
||||
|
||||
// 调用
|
||||
contractService.deleteContract(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(contractMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteContract_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> contractService.deleteContract(id), CONTRACT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetContractPage() {
|
||||
// mock 数据
|
||||
CrmContractDO dbContract = randomPojo(CrmContractDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setCustomerId(null);
|
||||
o.setBusinessId(null);
|
||||
o.setOrderDate(null);
|
||||
o.setNo(null);
|
||||
o.setDiscountPercent(null);
|
||||
o.setProductPrice(null);
|
||||
});
|
||||
contractMapper.insert(dbContract);
|
||||
// 测试 name 不匹配
|
||||
contractMapper.insert(cloneIgnoreId(dbContract, o -> o.setName(null)));
|
||||
// 测试 customerId 不匹配
|
||||
contractMapper.insert(cloneIgnoreId(dbContract, o -> o.setCustomerId(null)));
|
||||
// 测试 no 不匹配
|
||||
contractMapper.insert(cloneIgnoreId(dbContract, o -> o.setNo(null)));
|
||||
// 准备参数
|
||||
CrmContractPageReqVO reqVO = new CrmContractPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setCustomerId(null);
|
||||
reqVO.setBusinessId(null);
|
||||
reqVO.setNo(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CrmContractDO> pageResult = contractService.getContractPage(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbContract, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.customer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:单测后续补
|
||||
|
||||
/**
|
||||
* {@link CrmCustomerServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author Wanwan
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmCustomerServiceImpl.class)
|
||||
public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmCustomerServiceImpl customerService;
|
||||
|
||||
@Resource
|
||||
private CrmCustomerMapper customerMapper;
|
||||
@MockBean
|
||||
private CrmPermissionService permissionService;
|
||||
|
||||
@Test
|
||||
public void testCreateCustomer_success() {
|
||||
// 准备参数
|
||||
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long customerId = customerService.createCustomer(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertNotNull(customerId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmCustomerDO customer = customerMapper.selectById(customerId);
|
||||
assertPojoEquals(reqVO, customer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomer_success() {
|
||||
// mock 数据
|
||||
CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class);
|
||||
customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class, o -> {
|
||||
o.setId(dbCustomer.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
customerService.updateCustomer(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmCustomerDO customer = customerMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, customer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomer_notExists() {
|
||||
// 准备参数
|
||||
CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerService.updateCustomer(reqVO), CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomer_success() {
|
||||
// mock 数据
|
||||
CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class);
|
||||
customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbCustomer.getId();
|
||||
|
||||
// 调用
|
||||
customerService.deleteCustomer(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(customerMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomer_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerService.deleteCustomer(id), CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCustomerPage() {
|
||||
// mock 数据
|
||||
CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class, o -> { // 等会查询到
|
||||
o.setName("张三");
|
||||
o.setMobile("13888888888");
|
||||
o.setTelephone("13888888888");
|
||||
o.setWebsite("https://yudao.com");
|
||||
});
|
||||
//customerMapper.insert(dbCustomer);
|
||||
// 测试 name 不匹配
|
||||
//customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setName("")));
|
||||
// 测试 mobile 不匹配
|
||||
//customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setMobile(null)));
|
||||
// 测试 telephone 不匹配
|
||||
//customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setTelephone(null)));
|
||||
// 测试 website 不匹配
|
||||
//customerMapper.insert(cloneIgnoreId(dbCustomer, o -> o.setWebsite(null)));
|
||||
// 准备参数
|
||||
CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
|
||||
reqVO.setName("张三");
|
||||
reqVO.setMobile("13888888888");
|
||||
//reqVO.setTelephone(null);
|
||||
//reqVO.setWebsite(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CrmCustomerDO> pageResult = customerService.getCustomerPage(reqVO, 1L);
|
||||
// 断言
|
||||
//assertEquals(1, pageResult.getTotal());
|
||||
//assertEquals(1, pageResult.getList().size());
|
||||
//assertPojoEquals(dbCustomer, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:单测后面搞
|
||||
/**
|
||||
* {@link CrmCustomerLimitConfigServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author Wanwan
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmCustomerLimitConfigServiceImpl.class)
|
||||
public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmCustomerLimitConfigServiceImpl customerLimitConfigService;
|
||||
|
||||
@Resource
|
||||
private CrmCustomerLimitConfigMapper customerLimitConfigMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateCustomerLimitConfig_success() {
|
||||
// 准备参数
|
||||
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
|
||||
// 断言
|
||||
assertNotNull(customerLimitConfigId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(customerLimitConfigId);
|
||||
assertPojoEquals(reqVO, customerLimitConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomerLimitConfig_success() {
|
||||
// mock 数据
|
||||
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
|
||||
customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class, o -> {
|
||||
o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
customerLimitConfigService.updateCustomerLimitConfig(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmCustomerLimitConfigDO customerLimitConfig = customerLimitConfigMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, customerLimitConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCustomerLimitConfig_notExists() {
|
||||
// 准备参数
|
||||
CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomerLimitConfig_success() {
|
||||
// mock 数据
|
||||
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
|
||||
customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbCustomerLimitConfig.getId();
|
||||
|
||||
// 调用
|
||||
customerLimitConfigService.deleteCustomerLimitConfig(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(customerLimitConfigMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCustomerLimitConfig_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> customerLimitConfigService.deleteCustomerLimitConfig(id), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCustomerLimitConfigPage() {
|
||||
// mock 数据
|
||||
CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class, o -> { // 等会查询到
|
||||
});
|
||||
customerLimitConfigMapper.insert(dbCustomerLimitConfig);
|
||||
// 准备参数
|
||||
CrmCustomerLimitConfigPageReqVO reqVO = new CrmCustomerLimitConfigPageReqVO();
|
||||
|
||||
// 调用
|
||||
PageResult<CrmCustomerLimitConfigDO> pageResult = customerLimitConfigService.getCustomerLimitConfigPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbCustomerLimitConfig, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.receivable;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.CrmReceivablePlanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.RECEIVABLE_PLAN_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:后续,需要补充测试用例
|
||||
|
||||
/**
|
||||
* {@link CrmReceivablePlanServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmReceivablePlanServiceImpl.class)
|
||||
public class CrmCrmReceivablePlanServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmReceivablePlanServiceImpl receivablePlanService;
|
||||
|
||||
@Resource
|
||||
private CrmReceivablePlanMapper crmReceivablePlanMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateReceivablePlan_success() {
|
||||
// 准备参数
|
||||
CrmReceivablePlanCreateReqVO reqVO = randomPojo(CrmReceivablePlanCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long receivablePlanId = receivablePlanService.createReceivablePlan(reqVO, 1L);
|
||||
// 断言
|
||||
assertNotNull(receivablePlanId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmReceivablePlanDO receivablePlan = crmReceivablePlanMapper.selectById(receivablePlanId);
|
||||
assertPojoEquals(reqVO, receivablePlan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReceivablePlan_success() {
|
||||
// mock 数据
|
||||
CrmReceivablePlanDO dbReceivablePlan = randomPojo(CrmReceivablePlanDO.class);
|
||||
crmReceivablePlanMapper.insert(dbReceivablePlan);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmReceivablePlanUpdateReqVO reqVO = randomPojo(CrmReceivablePlanUpdateReqVO.class, o -> {
|
||||
o.setId(dbReceivablePlan.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
receivablePlanService.updateReceivablePlan(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmReceivablePlanDO receivablePlan = crmReceivablePlanMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, receivablePlan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReceivablePlan_notExists() {
|
||||
// 准备参数
|
||||
CrmReceivablePlanUpdateReqVO reqVO = randomPojo(CrmReceivablePlanUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> receivablePlanService.updateReceivablePlan(reqVO), RECEIVABLE_PLAN_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteReceivablePlan_success() {
|
||||
// mock 数据
|
||||
CrmReceivablePlanDO dbReceivablePlan = randomPojo(CrmReceivablePlanDO.class);
|
||||
crmReceivablePlanMapper.insert(dbReceivablePlan);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbReceivablePlan.getId();
|
||||
|
||||
// 调用
|
||||
receivablePlanService.deleteReceivablePlan(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(crmReceivablePlanMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteReceivablePlan_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> receivablePlanService.deleteReceivablePlan(id), RECEIVABLE_PLAN_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetReceivablePlanPage() {
|
||||
// mock 数据
|
||||
CrmReceivablePlanDO dbReceivablePlan = randomPojo(CrmReceivablePlanDO.class, o -> { // 等会查询到
|
||||
o.setPeriod(null);
|
||||
o.setReturnTime(null);
|
||||
o.setRemindDays(null);
|
||||
o.setRemindTime(null);
|
||||
o.setCustomerId(null);
|
||||
o.setContractId(null);
|
||||
o.setOwnerUserId(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
crmReceivablePlanMapper.insert(dbReceivablePlan);
|
||||
// 测试 customerId 不匹配
|
||||
crmReceivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCustomerId(null)));
|
||||
// 测试 contractId 不匹配
|
||||
crmReceivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setContractId(null)));
|
||||
// 准备参数
|
||||
CrmReceivablePlanPageReqVO reqVO = new CrmReceivablePlanPageReqVO();
|
||||
reqVO.setCustomerId(null);
|
||||
reqVO.setContractId(null);
|
||||
reqVO.setPageSize(PAGE_SIZE_NONE);
|
||||
// 调用
|
||||
PageResult<CrmReceivablePlanDO> pageResult = receivablePlanService.getReceivablePlanPage(reqVO, 1L);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbReceivablePlan, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.service.receivable;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.CrmReceivableMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.RECEIVABLE_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// TODO 芋艿:等实现完,在校验下;
|
||||
/**
|
||||
* {@link CrmReceivableServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 赤焰
|
||||
*/
|
||||
@Disabled // TODO 芋艿:后续 fix 补充的单测
|
||||
@Import(CrmReceivableServiceImpl.class)
|
||||
public class CrmCrmReceivableServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private CrmReceivableServiceImpl receivableService;
|
||||
|
||||
@Resource
|
||||
private CrmReceivableMapper crmReceivableMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateReceivable_success() {
|
||||
// 准备参数
|
||||
CrmReceivableCreateReqVO reqVO = randomPojo(CrmReceivableCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long receivableId = receivableService.createReceivable(reqVO, getLoginUserId());
|
||||
// 断言
|
||||
assertNotNull(receivableId);
|
||||
// 校验记录的属性是否正确
|
||||
CrmReceivableDO receivable = crmReceivableMapper.selectById(receivableId);
|
||||
assertPojoEquals(reqVO, receivable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReceivable_success() {
|
||||
// mock 数据
|
||||
CrmReceivableDO dbReceivable = randomPojo(CrmReceivableDO.class);
|
||||
crmReceivableMapper.insert(dbReceivable);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CrmReceivableUpdateReqVO reqVO = randomPojo(CrmReceivableUpdateReqVO.class, o -> {
|
||||
o.setId(dbReceivable.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
receivableService.updateReceivable(reqVO);
|
||||
// 校验是否更新正确
|
||||
CrmReceivableDO receivable = crmReceivableMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, receivable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReceivable_notExists() {
|
||||
// 准备参数
|
||||
CrmReceivableUpdateReqVO reqVO = randomPojo(CrmReceivableUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> receivableService.updateReceivable(reqVO), RECEIVABLE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteReceivable_success() {
|
||||
// mock 数据
|
||||
CrmReceivableDO dbReceivable = randomPojo(CrmReceivableDO.class);
|
||||
crmReceivableMapper.insert(dbReceivable);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbReceivable.getId();
|
||||
|
||||
// 调用
|
||||
receivableService.deleteReceivable(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(crmReceivableMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteReceivable_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> receivableService.deleteReceivable(id), RECEIVABLE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetReceivablePage() {
|
||||
// mock 数据
|
||||
CrmReceivableDO dbReceivable = randomPojo(CrmReceivableDO.class, o -> { // 等会查询到
|
||||
o.setNo(null);
|
||||
o.setPlanId(null);
|
||||
o.setCustomerId(null);
|
||||
o.setContractId(null);
|
||||
o.setProcessInstanceId(null);
|
||||
o.setReturnTime(null);
|
||||
o.setReturnType(null);
|
||||
o.setPrice(null);
|
||||
o.setOwnerUserId(null);
|
||||
o.setSort(null);
|
||||
o.setAuditStatus(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
crmReceivableMapper.insert(dbReceivable);
|
||||
// 测试 no 不匹配
|
||||
crmReceivableMapper.insert(cloneIgnoreId(dbReceivable, o -> o.setNo(null)));
|
||||
// 测试 planId 不匹配
|
||||
crmReceivableMapper.insert(cloneIgnoreId(dbReceivable, o -> o.setPlanId(null)));
|
||||
// 测试 customerId 不匹配
|
||||
crmReceivableMapper.insert(cloneIgnoreId(dbReceivable, o -> o.setCustomerId(null)));
|
||||
// 准备参数
|
||||
CrmReceivablePageReqVO reqVO = new CrmReceivablePageReqVO();
|
||||
reqVO.setNo(null);
|
||||
reqVO.setPlanId(null);
|
||||
reqVO.setCustomerId(null);
|
||||
|
||||
// 调用
|
||||
PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(reqVO, 1L);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbReceivable, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user