Commit c5633a37c92eb5975d19ac32c126ccf5e493b076
1 parent
d7288b89
fix(oa): 对齐点评长度边界并支持清空车辆部门
点评测试按累计 1000 字符校验,车辆完整编辑允许清空部门。 补充非法部门校验失败时不更新车辆数据的单元测试。
Showing
3 changed files
with
26 additions
and
4 deletions
yudao-module-oa/src/main/java/cn/iocoder/yudao/module/oa/dal/dataobject/vehicle/OaVehicleDO.java
yudao-module-oa/src/test/java/cn/iocoder/yudao/module/oa/service/plan/OaPlanServiceImplTest.java
| ... | ... | @@ -190,13 +190,13 @@ public class OaPlanServiceImplTest extends BaseDbUnitTest { |
| 190 | 190 | // mock 数据:已有点评与本次追加内容按字符数计算 |
| 191 | 191 | Long ownerId = randomLongId(); |
| 192 | 192 | Long managerId = randomLongId(); |
| 193 | - OaPlanDO plan = buildPlanDO(ownerId).setComment(StrUtil.repeat("a", 65533 - System.lineSeparator().length())); | |
| 193 | + OaPlanDO plan = buildPlanDO(ownerId).setComment(StrUtil.repeat("a", 998 - System.lineSeparator().length())); | |
| 194 | 194 | planMapper.insert(plan); |
| 195 | 195 | // mock 方法 |
| 196 | 196 | when(adminUserApi.getUserListBySubordinate(managerId)).thenReturn( |
| 197 | 197 | Collections.singletonList(new AdminUserRespDTO().setId(ownerId))); |
| 198 | 198 | |
| 199 | - // 调用:包含换行后恰好达到 65535 个字符 | |
| 199 | + // 调用:包含换行后恰好达到 1000 个字符 | |
| 200 | 200 | planService.addPlanComment(plan.getId(), "ab", managerId); |
| 201 | 201 | |
| 202 | 202 | // 断言 |
| ... | ... | @@ -209,7 +209,7 @@ public class OaPlanServiceImplTest extends BaseDbUnitTest { |
| 209 | 209 | // mock 数据:已有点评与本次追加内容按字符数计算 |
| 210 | 210 | Long ownerId = randomLongId(); |
| 211 | 211 | Long managerId = randomLongId(); |
| 212 | - OaPlanDO plan = buildPlanDO(ownerId).setComment(StrUtil.repeat("a", 65533 - System.lineSeparator().length())); | |
| 212 | + OaPlanDO plan = buildPlanDO(ownerId).setComment(StrUtil.repeat("a", 998 - System.lineSeparator().length())); | |
| 213 | 213 | planMapper.insert(plan); |
| 214 | 214 | // mock 方法 |
| 215 | 215 | when(adminUserApi.getUserListBySubordinate(managerId)).thenReturn( |
| ... | ... | @@ -220,7 +220,7 @@ public class OaPlanServiceImplTest extends BaseDbUnitTest { |
| 220 | 220 | () -> planService.addPlanComment(plan.getId(), "abc", managerId)); |
| 221 | 221 | assertTrue(exception.getConstraintViolations().stream().anyMatch(violation -> |
| 222 | 222 | "comment".equals(violation.getPropertyPath().toString()) |
| 223 | - && "点评内容长度不能超过 65535 个字符".equals(violation.getMessage()))); | |
| 223 | + && "点评内容长度不能超过 1000 个字符".equals(violation.getMessage()))); | |
| 224 | 224 | assertEquals(plan.getComment(), planMapper.selectById(plan.getId()).getComment()); |
| 225 | 225 | } |
| 226 | 226 | ... | ... |
yudao-module-oa/src/test/java/cn/iocoder/yudao/module/oa/service/vehicle/OaVehicleServiceImplTest.java
| ... | ... | @@ -16,9 +16,11 @@ import java.math.BigDecimal; |
| 16 | 16 | import java.time.LocalDateTime; |
| 17 | 17 | import java.util.Collections; |
| 18 | 18 | |
| 19 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 19 | 20 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 20 | 21 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 21 | 22 | import static cn.iocoder.yudao.module.oa.enums.ErrorCodeConstants.*; |
| 23 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.DEPT_NOT_FOUND; | |
| 22 | 24 | import static org.junit.jupiter.api.Assertions.*; |
| 23 | 25 | import static org.mockito.Mockito.*; |
| 24 | 26 | |
| ... | ... | @@ -187,6 +189,25 @@ public class OaVehicleServiceImplTest extends BaseDbUnitTest { |
| 187 | 189 | } |
| 188 | 190 | |
| 189 | 191 | @Test |
| 192 | + public void testUpdateVehicle_deptInvalid() { | |
| 193 | + // mock 数据 | |
| 194 | + OaVehicleDO vehicle = randomVehicleDO().setDeptId(103L).setPicUrl("https://example.com/old.png"); | |
| 195 | + vehicleMapper.insert(vehicle); | |
| 196 | + // 准备参数 | |
| 197 | + OaVehicleSaveReqVO reqVO = BeanUtils.toBean(vehicle, OaVehicleSaveReqVO.class) | |
| 198 | + .setDeptId(104L).setPicUrl("https://example.com/new.png"); | |
| 199 | + // mock 方法 | |
| 200 | + doThrow(exception(DEPT_NOT_FOUND)).when(deptApi).validateDeptList(Collections.singleton(104L)); | |
| 201 | + | |
| 202 | + // 调用,并断言异常 | |
| 203 | + assertServiceException(() -> vehicleService.updateVehicle(reqVO), DEPT_NOT_FOUND); | |
| 204 | + // 断言:部门校验失败时不更新车辆 | |
| 205 | + OaVehicleDO dbVehicle = vehicleMapper.selectById(vehicle.getId()); | |
| 206 | + assertEquals(103L, dbVehicle.getDeptId()); | |
| 207 | + assertEquals("https://example.com/old.png", dbVehicle.getPicUrl()); | |
| 208 | + } | |
| 209 | + | |
| 210 | + @Test | |
| 190 | 211 | public void testCreateVehicle_deletedPlateCanBeReused() { |
| 191 | 212 | // mock 数据 |
| 192 | 213 | OaVehicleDO vehicle = randomVehicleDO(); | ... | ... |