|
@@ -0,0 +1,156 @@
|
|
|
+package com.citu.module.menduner.system.service.interview;
|
|
|
+
|
|
|
+
|
|
|
+import com.citu.framework.common.pojo.PageResult;
|
|
|
+import com.citu.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+import com.citu.module.menduner.system.controller.base.interview.InterviewInvitePageReqVO;
|
|
|
+import com.citu.module.menduner.system.controller.base.interview.InterviewInviteSaveReqVO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.interview.InterviewInviteDO;
|
|
|
+import com.citu.module.menduner.system.dal.mysql.interview.InterviewInviteMapper;
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.context.annotation.Import;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import static com.citu.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
|
|
+import static com.citu.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
|
+import static com.citu.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
|
+import static com.citu.framework.test.core.util.AssertUtils.assertServiceException;
|
|
|
+import static com.citu.framework.test.core.util.RandomUtils.randomLongId;
|
|
|
+import static com.citu.framework.test.core.util.RandomUtils.randomPojo;
|
|
|
+import static com.citu.module.menduner.system.enums.ErrorCodeConstants.INTERVIEW_INVITE_NOT_EXISTS;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link InterviewInviteServiceImpl} 的单元测试类
|
|
|
+ *
|
|
|
+ * @author Rayson
|
|
|
+ */
|
|
|
+@Import(InterviewInviteServiceImpl.class)
|
|
|
+public class InterviewInviteServiceImplTest extends BaseDbUnitTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private InterviewInviteServiceImpl interviewInviteService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private InterviewInviteMapper interviewInviteMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreateInterviewInvite_success() {
|
|
|
+ // 准备参数
|
|
|
+ InterviewInviteSaveReqVO createReqVO = randomPojo(InterviewInviteSaveReqVO.class).setId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ Long interviewInviteId = interviewInviteService.createInterviewInvite(createReqVO);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(interviewInviteId);
|
|
|
+ // 校验记录的属性是否正确
|
|
|
+ InterviewInviteDO interviewInvite = interviewInviteMapper.selectById(interviewInviteId);
|
|
|
+ assertPojoEquals(createReqVO, interviewInvite, "id");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateInterviewInvite_success() {
|
|
|
+ // mock 数据
|
|
|
+ InterviewInviteDO dbInterviewInvite = randomPojo(InterviewInviteDO.class);
|
|
|
+ interviewInviteMapper.insert(dbInterviewInvite);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ InterviewInviteSaveReqVO updateReqVO = randomPojo(InterviewInviteSaveReqVO.class, o -> {
|
|
|
+ o.setId(dbInterviewInvite.getId()); // 设置更新的 ID
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ interviewInviteService.updateInterviewInvite(updateReqVO);
|
|
|
+ // 校验是否更新正确
|
|
|
+ InterviewInviteDO interviewInvite = interviewInviteMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+ assertPojoEquals(updateReqVO, interviewInvite);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateInterviewInvite_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ InterviewInviteSaveReqVO updateReqVO = randomPojo(InterviewInviteSaveReqVO.class);
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> interviewInviteService.updateInterviewInvite(updateReqVO), INTERVIEW_INVITE_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteInterviewInvite_success() {
|
|
|
+ // mock 数据
|
|
|
+ InterviewInviteDO dbInterviewInvite = randomPojo(InterviewInviteDO.class);
|
|
|
+ interviewInviteMapper.insert(dbInterviewInvite);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbInterviewInvite.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ interviewInviteService.deleteInterviewInvite(id);
|
|
|
+ // 校验数据不存在了
|
|
|
+ assertNull(interviewInviteMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteInterviewInvite_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ Long id = randomLongId();
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> interviewInviteService.deleteInterviewInvite(id), INTERVIEW_INVITE_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+ public void testGetInterviewInvitePage() {
|
|
|
+ // mock 数据
|
|
|
+ InterviewInviteDO dbInterviewInvite = randomPojo(InterviewInviteDO.class, o -> { // 等会查询到
|
|
|
+ o.setEnterpriseId(null);
|
|
|
+ o.setUserId(null);
|
|
|
+ o.setInviteUserId(null);
|
|
|
+ o.setJobId(null);
|
|
|
+ o.setType(null);
|
|
|
+ o.setTime(null);
|
|
|
+ o.setPhone(null);
|
|
|
+ o.setStatus(null);
|
|
|
+ o.setCreateTime(null);
|
|
|
+ });
|
|
|
+ interviewInviteMapper.insert(dbInterviewInvite);
|
|
|
+ // 测试 enterpriseId 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setEnterpriseId(null)));
|
|
|
+ // 测试 userId 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setUserId(null)));
|
|
|
+ // 测试 inviteUserId 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setInviteUserId(null)));
|
|
|
+ // 测试 jobId 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setJobId(null)));
|
|
|
+ // 测试 type 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setType(null)));
|
|
|
+ // 测试 time 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setTime(null)));
|
|
|
+ // 测试 phone 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setPhone(null)));
|
|
|
+ // 测试 status 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setStatus(null)));
|
|
|
+ // 测试 createTime 不匹配
|
|
|
+ interviewInviteMapper.insert(cloneIgnoreId(dbInterviewInvite, o -> o.setCreateTime(null)));
|
|
|
+ // 准备参数
|
|
|
+ InterviewInvitePageReqVO reqVO = new InterviewInvitePageReqVO();
|
|
|
+ reqVO.setEnterpriseId(null);
|
|
|
+ reqVO.setUserId(null);
|
|
|
+ reqVO.setInviteUserId(null);
|
|
|
+ reqVO.setJobId(null);
|
|
|
+ reqVO.setType(null);
|
|
|
+ reqVO.setTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+ reqVO.setPhone(null);
|
|
|
+ reqVO.setStatus(null);
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ PageResult<InterviewInviteDO> pageResult = interviewInviteService.getInterviewInvitePage(reqVO);
|
|
|
+ // 断言
|
|
|
+ assertEquals(1, pageResult.getTotal());
|
|
|
+ assertEquals(1, pageResult.getList().size());
|
|
|
+ assertPojoEquals(dbInterviewInvite, pageResult.getList().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|