Commit d5fe12ebd6c20374dadaf5d15966e4bcfa9bfd7d
1 parent
2a1fc61d
fix(crm): 校验回款计划关联合同
Showing
2 changed files
with
64 additions
and
1 deletions
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImpl.java
| ... | ... | @@ -116,7 +116,7 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService { |
| 116 | 116 | } |
| 117 | 117 | // 校验合同存在 |
| 118 | 118 | if (reqVO.getContractId() != null) { |
| 119 | - CrmContractDO contract = contractService.getContract(reqVO.getContractId()); | |
| 119 | + CrmContractDO contract = contractService.validateContract(reqVO.getContractId()); | |
| 120 | 120 | reqVO.setCustomerId(contract.getCustomerId()); |
| 121 | 121 | } |
| 122 | 122 | } | ... | ... |
yudao-module-crm/src/test/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivablePlanServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.receivable; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanSaveReqVO; | |
| 5 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; | |
| 6 | +import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO; | |
| 7 | +import cn.iocoder.yudao.module.crm.dal.mysql.receivable.CrmReceivablePlanMapper; | |
| 8 | +import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; | |
| 9 | +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | |
| 10 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 11 | +import org.junit.jupiter.api.Test; | |
| 12 | +import org.mockito.InjectMocks; | |
| 13 | +import org.mockito.Mock; | |
| 14 | + | |
| 15 | +import java.util.Objects; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 19 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS; | |
| 20 | +import static org.mockito.ArgumentMatchers.argThat; | |
| 21 | +import static org.mockito.Mockito.*; | |
| 22 | + | |
| 23 | +public class CrmReceivablePlanServiceImplTest extends BaseMockitoUnitTest { | |
| 24 | + | |
| 25 | + @InjectMocks | |
| 26 | + private CrmReceivablePlanServiceImpl receivablePlanService; | |
| 27 | + @Mock | |
| 28 | + private CrmReceivablePlanMapper receivablePlanMapper; | |
| 29 | + @Mock | |
| 30 | + private CrmContractService contractService; | |
| 31 | + @Mock | |
| 32 | + private CrmPermissionService permissionService; | |
| 33 | + @Mock | |
| 34 | + private AdminUserApi adminUserApi; | |
| 35 | + | |
| 36 | + @Test | |
| 37 | + public void testCreateReceivablePlan_contractNotExists() { | |
| 38 | + // 准备参数 | |
| 39 | + CrmReceivablePlanSaveReqVO reqVO = new CrmReceivablePlanSaveReqVO().setContractId(9L); | |
| 40 | + // mock 合同不存在 | |
| 41 | + when(contractService.validateContract(9L)).thenThrow(exception(CONTRACT_NOT_EXISTS)); | |
| 42 | + | |
| 43 | + // 调用,并断言异常 | |
| 44 | + assertServiceException(() -> receivablePlanService.createReceivablePlan(reqVO), CONTRACT_NOT_EXISTS); | |
| 45 | + // 断言未写入回款计划和数据权限 | |
| 46 | + verifyNoInteractions(receivablePlanMapper, permissionService); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Test | |
| 50 | + public void testCreateReceivablePlan_useContractCustomerId() { | |
| 51 | + // 准备参数:入参的客户编号应以合同为准 | |
| 52 | + CrmReceivablePlanSaveReqVO reqVO = new CrmReceivablePlanSaveReqVO() | |
| 53 | + .setContractId(9L).setCustomerId(999L); | |
| 54 | + // mock 合同 | |
| 55 | + when(contractService.validateContract(9L)).thenReturn(new CrmContractDO().setId(9L).setCustomerId(20L)); | |
| 56 | + | |
| 57 | + // 调用 | |
| 58 | + receivablePlanService.createReceivablePlan(reqVO); | |
| 59 | + // 断言 | |
| 60 | + verify(receivablePlanMapper).insert(argThat((CrmReceivablePlanDO row) -> | |
| 61 | + Objects.equals(row.getCustomerId(), 20L) && Objects.equals(row.getPeriod(), 1))); | |
| 62 | + } | |
| 63 | +} | ... | ... |