|
@@ -0,0 +1,131 @@
|
|
|
+package cn.newfeifan.mall.module.distri.service.usersigninlog;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import cn.newfeifan.mall.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.usersigninlog.vo.*;
|
|
|
+import cn.newfeifan.mall.module.distri.dal.dataobject.usersigninlog.UserSignInLogDO;
|
|
|
+import cn.newfeifan.mall.module.distri.dal.mysql.usersigninlog.UserSignInLogMapper;
|
|
|
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
+
|
|
|
+import org.springframework.context.annotation.Import;
|
|
|
+
|
|
|
+import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
|
|
|
+import static cn.newfeifan.mall.framework.test.core.util.AssertUtils.*;
|
|
|
+import static cn.newfeifan.mall.framework.test.core.util.RandomUtils.*;
|
|
|
+import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.*;
|
|
|
+import static cn.newfeifan.mall.framework.common.util.object.ObjectUtils.*;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link UserSignInLogServiceImpl} 的单元测试类
|
|
|
+ *
|
|
|
+ * @author 非繁人
|
|
|
+ */
|
|
|
+@Import(UserSignInLogServiceImpl.class)
|
|
|
+public class UserSignInLogServiceImplTest extends BaseDbUnitTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserSignInLogServiceImpl userSignInLogService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserSignInLogMapper userSignInLogMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreateUserSignInLog_success() {
|
|
|
+ // 准备参数
|
|
|
+ UserSignInLogSaveReqVO createReqVO = randomPojo(UserSignInLogSaveReqVO.class).setId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ Long userSignInLogId = userSignInLogService.createUserSignInLog(createReqVO);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(userSignInLogId);
|
|
|
+ // 校验记录的属性是否正确
|
|
|
+ UserSignInLogDO userSignInLog = userSignInLogMapper.selectById(userSignInLogId);
|
|
|
+ assertPojoEquals(createReqVO, userSignInLog, "id");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateUserSignInLog_success() {
|
|
|
+ // mock 数据
|
|
|
+ UserSignInLogDO dbUserSignInLog = randomPojo(UserSignInLogDO.class);
|
|
|
+ userSignInLogMapper.insert(dbUserSignInLog);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ UserSignInLogSaveReqVO updateReqVO = randomPojo(UserSignInLogSaveReqVO.class, o -> {
|
|
|
+ o.setId(dbUserSignInLog.getId()); // 设置更新的 ID
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ userSignInLogService.updateUserSignInLog(updateReqVO);
|
|
|
+ // 校验是否更新正确
|
|
|
+ UserSignInLogDO userSignInLog = userSignInLogMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+ assertPojoEquals(updateReqVO, userSignInLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateUserSignInLog_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ UserSignInLogSaveReqVO updateReqVO = randomPojo(UserSignInLogSaveReqVO.class);
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> userSignInLogService.updateUserSignInLog(updateReqVO), USER_SIGN_IN_LOG_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteUserSignInLog_success() {
|
|
|
+ // mock 数据
|
|
|
+ UserSignInLogDO dbUserSignInLog = randomPojo(UserSignInLogDO.class);
|
|
|
+ userSignInLogMapper.insert(dbUserSignInLog);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbUserSignInLog.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ userSignInLogService.deleteUserSignInLog(id);
|
|
|
+ // 校验数据不存在了
|
|
|
+ assertNull(userSignInLogMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteUserSignInLog_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ Long id = randomLongId();
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> userSignInLogService.deleteUserSignInLog(id), USER_SIGN_IN_LOG_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+ public void testGetUserSignInLogPage() {
|
|
|
+ // mock 数据
|
|
|
+ UserSignInLogDO dbUserSignInLog = randomPojo(UserSignInLogDO.class, o -> { // 等会查询到
|
|
|
+ o.setUserId(null);
|
|
|
+ o.setRunningDays(null);
|
|
|
+ o.setCreateTime(null);
|
|
|
+ });
|
|
|
+ userSignInLogMapper.insert(dbUserSignInLog);
|
|
|
+ // 测试 userId 不匹配
|
|
|
+ userSignInLogMapper.insert(cloneIgnoreId(dbUserSignInLog, o -> o.setUserId(null)));
|
|
|
+ // 测试 runningDays 不匹配
|
|
|
+ userSignInLogMapper.insert(cloneIgnoreId(dbUserSignInLog, o -> o.setRunningDays(null)));
|
|
|
+ // 测试 createTime 不匹配
|
|
|
+ userSignInLogMapper.insert(cloneIgnoreId(dbUserSignInLog, o -> o.setCreateTime(null)));
|
|
|
+ // 准备参数
|
|
|
+ UserSignInLogPageReqVO reqVO = new UserSignInLogPageReqVO();
|
|
|
+ reqVO.setUserId(null);
|
|
|
+ reqVO.setRunningDays(null);
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ PageResult<UserSignInLogDO> pageResult = userSignInLogService.getUserSignInLogPage(reqVO);
|
|
|
+ // 断言
|
|
|
+ assertEquals(1, pageResult.getTotal());
|
|
|
+ assertEquals(1, pageResult.getList().size());
|
|
|
+ assertPojoEquals(dbUserSignInLog, pageResult.getList().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|