充值记录
parent
d59775eb86
commit
39e87b3701
|
@ -1,207 +0,0 @@
|
|||
package cn.iocoder.yudao.module.shop.service.recharge;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*;
|
||||
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.PhoneRecordDO;
|
||||
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.PhoneRecordMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.shop.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link PhoneRecordServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 创盈云
|
||||
*/
|
||||
@Import(PhoneRecordServiceImpl.class)
|
||||
public class PhoneRecordServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PhoneRecordServiceImpl phoneRecordService;
|
||||
|
||||
@Resource
|
||||
private PhoneRecordMapper phoneRecordMapper;
|
||||
|
||||
@Test
|
||||
public void testCreatePhoneRecord_success() {
|
||||
// 准备参数
|
||||
PhoneRecordCreateReqVO reqVO = randomPojo(PhoneRecordCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long phoneRecordId = phoneRecordService.createPhoneRecord(reqVO);
|
||||
// 断言
|
||||
assertNotNull(phoneRecordId);
|
||||
// 校验记录的属性是否正确
|
||||
PhoneRecordDO phoneRecord = phoneRecordMapper.selectById(phoneRecordId);
|
||||
assertPojoEquals(reqVO, phoneRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePhoneRecord_success() {
|
||||
// mock 数据
|
||||
PhoneRecordDO dbPhoneRecord = randomPojo(PhoneRecordDO.class);
|
||||
phoneRecordMapper.insert(dbPhoneRecord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
PhoneRecordUpdateReqVO reqVO = randomPojo(PhoneRecordUpdateReqVO.class, o -> {
|
||||
o.setId(dbPhoneRecord.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
phoneRecordService.updatePhoneRecord(reqVO);
|
||||
// 校验是否更新正确
|
||||
PhoneRecordDO phoneRecord = phoneRecordMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, phoneRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePhoneRecord_notExists() {
|
||||
// 准备参数
|
||||
PhoneRecordUpdateReqVO reqVO = randomPojo(PhoneRecordUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> phoneRecordService.updatePhoneRecord(reqVO), PHONE_RECORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePhoneRecord_success() {
|
||||
// mock 数据
|
||||
PhoneRecordDO dbPhoneRecord = randomPojo(PhoneRecordDO.class);
|
||||
phoneRecordMapper.insert(dbPhoneRecord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbPhoneRecord.getId();
|
||||
|
||||
// 调用
|
||||
phoneRecordService.deletePhoneRecord(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(phoneRecordMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePhoneRecord_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> phoneRecordService.deletePhoneRecord(id), PHONE_RECORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetPhoneRecordPage() {
|
||||
// mock 数据
|
||||
PhoneRecordDO dbPhoneRecord = randomPojo(PhoneRecordDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null);
|
||||
o.setRechargeOrderId(null);
|
||||
o.setPhone(null);
|
||||
o.setRefundFeeAmount(null);
|
||||
o.setRechargeGearId(null);
|
||||
o.setRefundFeeEndDate(null);
|
||||
o.setRefundFeeNumber(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
phoneRecordMapper.insert(dbPhoneRecord);
|
||||
// 测试 userId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setUserId(null)));
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 phone 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setPhone(null)));
|
||||
// 测试 refundFeeAmount 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeAmount(null)));
|
||||
// 测试 rechargeGearId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRechargeGearId(null)));
|
||||
// 测试 refundFeeEndDate 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeEndDate(null)));
|
||||
// 测试 refundFeeNumber 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeNumber(null)));
|
||||
// 测试 createTime 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
PhoneRecordPageReqVO reqVO = new PhoneRecordPageReqVO();
|
||||
reqVO.setUserId(null);
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setPhone(null);
|
||||
reqVO.setRefundFeeAmount(null);
|
||||
reqVO.setRechargeGearId(null);
|
||||
reqVO.setRefundFeeEndDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setRefundFeeNumber(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<PhoneRecordDO> pageResult = phoneRecordService.getPhoneRecordPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbPhoneRecord, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetPhoneRecordList() {
|
||||
// mock 数据
|
||||
PhoneRecordDO dbPhoneRecord = randomPojo(PhoneRecordDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null);
|
||||
o.setRechargeOrderId(null);
|
||||
o.setPhone(null);
|
||||
o.setRefundFeeAmount(null);
|
||||
o.setRechargeGearId(null);
|
||||
o.setRefundFeeEndDate(null);
|
||||
o.setRefundFeeNumber(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
phoneRecordMapper.insert(dbPhoneRecord);
|
||||
// 测试 userId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setUserId(null)));
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 phone 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setPhone(null)));
|
||||
// 测试 refundFeeAmount 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeAmount(null)));
|
||||
// 测试 rechargeGearId 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRechargeGearId(null)));
|
||||
// 测试 refundFeeEndDate 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeEndDate(null)));
|
||||
// 测试 refundFeeNumber 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setRefundFeeNumber(null)));
|
||||
// 测试 createTime 不匹配
|
||||
phoneRecordMapper.insert(cloneIgnoreId(dbPhoneRecord, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
PhoneRecordExportReqVO reqVO = new PhoneRecordExportReqVO();
|
||||
reqVO.setUserId(null);
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setPhone(null);
|
||||
reqVO.setRefundFeeAmount(null);
|
||||
reqVO.setRechargeGearId(null);
|
||||
reqVO.setRefundFeeEndDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setRefundFeeNumber(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
List<PhoneRecordDO> list = phoneRecordService.getPhoneRecordList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbPhoneRecord, list.get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,231 +0,0 @@
|
|||
package cn.iocoder.yudao.module.shop.service.recharge;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*;
|
||||
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderInfoDO;
|
||||
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderInfoMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.shop.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link RechargeOrderInfoServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 创盈云
|
||||
*/
|
||||
@Import(RechargeOrderInfoServiceImpl.class)
|
||||
public class RechargeOrderInfoServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private RechargeOrderInfoServiceImpl rechargeOrderInfoService;
|
||||
|
||||
@Resource
|
||||
private RechargeOrderInfoMapper rechargeOrderInfoMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateRechargeOrderInfo_success() {
|
||||
// 准备参数
|
||||
RechargeOrderInfoCreateReqVO reqVO = randomPojo(RechargeOrderInfoCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Integer rechargeOrderInfoId = rechargeOrderInfoService.createRechargeOrderInfo(reqVO);
|
||||
// 断言
|
||||
assertNotNull(rechargeOrderInfoId);
|
||||
// 校验记录的属性是否正确
|
||||
RechargeOrderInfoDO rechargeOrderInfo = rechargeOrderInfoMapper.selectById(rechargeOrderInfoId);
|
||||
assertPojoEquals(reqVO, rechargeOrderInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRechargeOrderInfo_success() {
|
||||
// mock 数据
|
||||
RechargeOrderInfoDO dbRechargeOrderInfo = randomPojo(RechargeOrderInfoDO.class);
|
||||
rechargeOrderInfoMapper.insert(dbRechargeOrderInfo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
RechargeOrderInfoUpdateReqVO reqVO = randomPojo(RechargeOrderInfoUpdateReqVO.class, o -> {
|
||||
o.setId(dbRechargeOrderInfo.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
rechargeOrderInfoService.updateRechargeOrderInfo(reqVO);
|
||||
// 校验是否更新正确
|
||||
RechargeOrderInfoDO rechargeOrderInfo = rechargeOrderInfoMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, rechargeOrderInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRechargeOrderInfo_notExists() {
|
||||
// 准备参数
|
||||
RechargeOrderInfoUpdateReqVO reqVO = randomPojo(RechargeOrderInfoUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> rechargeOrderInfoService.updateRechargeOrderInfo(reqVO), RECHARGE_ORDER_INFO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRechargeOrderInfo_success() {
|
||||
// mock 数据
|
||||
RechargeOrderInfoDO dbRechargeOrderInfo = randomPojo(RechargeOrderInfoDO.class);
|
||||
rechargeOrderInfoMapper.insert(dbRechargeOrderInfo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Integer id = dbRechargeOrderInfo.getId();
|
||||
|
||||
// 调用
|
||||
rechargeOrderInfoService.deleteRechargeOrderInfo(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(rechargeOrderInfoMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRechargeOrderInfo_notExists() {
|
||||
// 准备参数
|
||||
Integer id = randomIntegerId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> rechargeOrderInfoService.deleteRechargeOrderInfo(id), RECHARGE_ORDER_INFO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRechargeOrderInfoPage() {
|
||||
// mock 数据
|
||||
RechargeOrderInfoDO dbRechargeOrderInfo = randomPojo(RechargeOrderInfoDO.class, o -> { // 等会查询到
|
||||
o.setRechargeOrderId(null);
|
||||
o.setRechargeGearId(null);
|
||||
o.setCreateTime(null);
|
||||
o.setOrderNo(null);
|
||||
o.setProductName(null);
|
||||
o.setPrice(null);
|
||||
o.setPayNum(null);
|
||||
o.setGiveIntegral(null);
|
||||
o.setIsSub(null);
|
||||
o.setVipPrice(null);
|
||||
o.setProductType(null);
|
||||
});
|
||||
rechargeOrderInfoMapper.insert(dbRechargeOrderInfo);
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 rechargeGearId 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setRechargeGearId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setCreateTime(null)));
|
||||
// 测试 orderNo 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setOrderNo(null)));
|
||||
// 测试 productName 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setProductName(null)));
|
||||
// 测试 price 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setPrice(null)));
|
||||
// 测试 payNum 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setPayNum(null)));
|
||||
// 测试 giveIntegral 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setGiveIntegral(null)));
|
||||
// 测试 isSub 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setIsSub(null)));
|
||||
// 测试 vipPrice 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setVipPrice(null)));
|
||||
// 测试 productType 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setProductType(null)));
|
||||
// 准备参数
|
||||
RechargeOrderInfoPageReqVO reqVO = new RechargeOrderInfoPageReqVO();
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setRechargeGearId(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setOrderNo(null);
|
||||
reqVO.setProductName(null);
|
||||
reqVO.setPrice(null);
|
||||
reqVO.setPayNum(null);
|
||||
reqVO.setGiveIntegral(null);
|
||||
reqVO.setIsSub(null);
|
||||
reqVO.setVipPrice(null);
|
||||
reqVO.setProductType(null);
|
||||
|
||||
// 调用
|
||||
PageResult<RechargeOrderInfoDO> pageResult = rechargeOrderInfoService.getRechargeOrderInfoPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRechargeOrderInfo, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRechargeOrderInfoList() {
|
||||
// mock 数据
|
||||
RechargeOrderInfoDO dbRechargeOrderInfo = randomPojo(RechargeOrderInfoDO.class, o -> { // 等会查询到
|
||||
o.setRechargeOrderId(null);
|
||||
o.setRechargeGearId(null);
|
||||
o.setCreateTime(null);
|
||||
o.setOrderNo(null);
|
||||
o.setProductName(null);
|
||||
o.setPrice(null);
|
||||
o.setPayNum(null);
|
||||
o.setGiveIntegral(null);
|
||||
o.setIsSub(null);
|
||||
o.setVipPrice(null);
|
||||
o.setProductType(null);
|
||||
});
|
||||
rechargeOrderInfoMapper.insert(dbRechargeOrderInfo);
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 rechargeGearId 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setRechargeGearId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setCreateTime(null)));
|
||||
// 测试 orderNo 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setOrderNo(null)));
|
||||
// 测试 productName 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setProductName(null)));
|
||||
// 测试 price 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setPrice(null)));
|
||||
// 测试 payNum 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setPayNum(null)));
|
||||
// 测试 giveIntegral 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setGiveIntegral(null)));
|
||||
// 测试 isSub 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setIsSub(null)));
|
||||
// 测试 vipPrice 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setVipPrice(null)));
|
||||
// 测试 productType 不匹配
|
||||
rechargeOrderInfoMapper.insert(cloneIgnoreId(dbRechargeOrderInfo, o -> o.setProductType(null)));
|
||||
// 准备参数
|
||||
RechargeOrderInfoExportReqVO reqVO = new RechargeOrderInfoExportReqVO();
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setRechargeGearId(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setOrderNo(null);
|
||||
reqVO.setProductName(null);
|
||||
reqVO.setPrice(null);
|
||||
reqVO.setPayNum(null);
|
||||
reqVO.setGiveIntegral(null);
|
||||
reqVO.setIsSub(null);
|
||||
reqVO.setVipPrice(null);
|
||||
reqVO.setProductType(null);
|
||||
|
||||
// 调用
|
||||
List<RechargeOrderInfoDO> list = rechargeOrderInfoService.getRechargeOrderInfoList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRechargeOrderInfo, list.get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,407 +0,0 @@
|
|||
package cn.iocoder.yudao.module.shop.service.recharge;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*;
|
||||
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO;
|
||||
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.shop.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link RechargeOrderServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 创盈云
|
||||
*/
|
||||
@Import(RechargeOrderServiceImpl.class)
|
||||
public class RechargeOrderServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private RechargeOrderServiceImpl rechargeOrderService;
|
||||
|
||||
@Resource
|
||||
private RechargeOrderMapper rechargeOrderMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateRechargeOrder_success() {
|
||||
// 准备参数
|
||||
RechargeOrderCreateReqVO reqVO = randomPojo(RechargeOrderCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Integer rechargeOrderId = rechargeOrderService.createRechargeOrder(reqVO);
|
||||
// 断言
|
||||
assertNotNull(rechargeOrderId);
|
||||
// 校验记录的属性是否正确
|
||||
RechargeOrderDO rechargeOrder = rechargeOrderMapper.selectById(rechargeOrderId);
|
||||
assertPojoEquals(reqVO, rechargeOrder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRechargeOrder_success() {
|
||||
// mock 数据
|
||||
RechargeOrderDO dbRechargeOrder = randomPojo(RechargeOrderDO.class);
|
||||
rechargeOrderMapper.insert(dbRechargeOrder);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
RechargeOrderUpdateReqVO reqVO = randomPojo(RechargeOrderUpdateReqVO.class, o -> {
|
||||
o.setId(dbRechargeOrder.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
rechargeOrderService.updateRechargeOrder(reqVO);
|
||||
// 校验是否更新正确
|
||||
RechargeOrderDO rechargeOrder = rechargeOrderMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, rechargeOrder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRechargeOrder_notExists() {
|
||||
// 准备参数
|
||||
RechargeOrderUpdateReqVO reqVO = randomPojo(RechargeOrderUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> rechargeOrderService.updateRechargeOrder(reqVO), RECHARGE_ORDER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRechargeOrder_success() {
|
||||
// mock 数据
|
||||
RechargeOrderDO dbRechargeOrder = randomPojo(RechargeOrderDO.class);
|
||||
rechargeOrderMapper.insert(dbRechargeOrder);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Integer id = dbRechargeOrder.getId();
|
||||
|
||||
// 调用
|
||||
rechargeOrderService.deleteRechargeOrder(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(rechargeOrderMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRechargeOrder_notExists() {
|
||||
// 准备参数
|
||||
Integer id = randomIntegerId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> rechargeOrderService.deleteRechargeOrder(id), RECHARGE_ORDER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRechargeOrderPage() {
|
||||
// mock 数据
|
||||
RechargeOrderDO dbRechargeOrder = randomPojo(RechargeOrderDO.class, o -> { // 等会查询到
|
||||
o.setOrderId(null);
|
||||
o.setUid(null);
|
||||
o.setRealName(null);
|
||||
o.setUserPhone(null);
|
||||
o.setConfirmPhone(null);
|
||||
o.setTotalNum(null);
|
||||
o.setTotalPrice(null);
|
||||
o.setPayPrice(null);
|
||||
o.setPaid(null);
|
||||
o.setPayTime(null);
|
||||
o.setPayEndTime(null);
|
||||
o.setPayType(null);
|
||||
o.setCreateTime(null);
|
||||
o.setStatus(null);
|
||||
o.setRefundStatus(null);
|
||||
o.setRefundReasonWapImg(null);
|
||||
o.setRefundReasonWapExplain(null);
|
||||
o.setRefundReasonWap(null);
|
||||
o.setRefundReason(null);
|
||||
o.setRefundReasonTime(null);
|
||||
o.setRefundPrice(null);
|
||||
o.setMark(null);
|
||||
o.setRemark(null);
|
||||
o.setCost(null);
|
||||
o.setIsChannel(null);
|
||||
o.setIsRemind(null);
|
||||
o.setIsSystemDel(null);
|
||||
o.setType(null);
|
||||
o.setProTotalPrice(null);
|
||||
o.setBeforePayPrice(null);
|
||||
o.setIsAlterPrice(null);
|
||||
o.setOutTradeNo(null);
|
||||
o.setPaySerialNumber(null);
|
||||
});
|
||||
rechargeOrderMapper.insert(dbRechargeOrder);
|
||||
// 测试 orderId 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setOrderId(null)));
|
||||
// 测试 uid 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setUid(null)));
|
||||
// 测试 realName 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRealName(null)));
|
||||
// 测试 userPhone 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setUserPhone(null)));
|
||||
// 测试 confirmPhone 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setConfirmPhone(null)));
|
||||
// 测试 totalNum 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setTotalNum(null)));
|
||||
// 测试 totalPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setTotalPrice(null)));
|
||||
// 测试 payPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayPrice(null)));
|
||||
// 测试 paid 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPaid(null)));
|
||||
// 测试 payTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayTime(null)));
|
||||
// 测试 payEndTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayEndTime(null)));
|
||||
// 测试 payType 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayType(null)));
|
||||
// 测试 createTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setCreateTime(null)));
|
||||
// 测试 status 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setStatus(null)));
|
||||
// 测试 refundStatus 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundStatus(null)));
|
||||
// 测试 refundReasonWapImg 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWapImg(null)));
|
||||
// 测试 refundReasonWapExplain 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWapExplain(null)));
|
||||
// 测试 refundReasonWap 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWap(null)));
|
||||
// 测试 refundReason 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReason(null)));
|
||||
// 测试 refundReasonTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonTime(null)));
|
||||
// 测试 refundPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundPrice(null)));
|
||||
// 测试 mark 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setMark(null)));
|
||||
// 测试 remark 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRemark(null)));
|
||||
// 测试 cost 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setCost(null)));
|
||||
// 测试 isChannel 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsChannel(null)));
|
||||
// 测试 isRemind 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsRemind(null)));
|
||||
// 测试 isSystemDel 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsSystemDel(null)));
|
||||
// 测试 type 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setType(null)));
|
||||
// 测试 proTotalPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setProTotalPrice(null)));
|
||||
// 测试 beforePayPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setBeforePayPrice(null)));
|
||||
// 测试 isAlterPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsAlterPrice(null)));
|
||||
// 测试 outTradeNo 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setOutTradeNo(null)));
|
||||
// 测试 paySerialNumber 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPaySerialNumber(null)));
|
||||
// 准备参数
|
||||
RechargeOrderPageReqVO reqVO = new RechargeOrderPageReqVO();
|
||||
reqVO.setOrderId(null);
|
||||
reqVO.setUid(null);
|
||||
reqVO.setRealName(null);
|
||||
reqVO.setUserPhone(null);
|
||||
reqVO.setConfirmPhone(null);
|
||||
reqVO.setTotalNum(null);
|
||||
reqVO.setTotalPrice(null);
|
||||
reqVO.setPayPrice(null);
|
||||
reqVO.setPaid(null);
|
||||
reqVO.setPayTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPayEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPayType(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setRefundStatus(null);
|
||||
reqVO.setRefundReasonWapImg(null);
|
||||
reqVO.setRefundReasonWapExplain(null);
|
||||
reqVO.setRefundReasonWap(null);
|
||||
reqVO.setRefundReason(null);
|
||||
reqVO.setRefundReasonTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setRefundPrice(null);
|
||||
reqVO.setMark(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setCost(null);
|
||||
reqVO.setIsChannel(null);
|
||||
reqVO.setIsRemind(null);
|
||||
reqVO.setIsSystemDel(null);
|
||||
reqVO.setType(null);
|
||||
reqVO.setProTotalPrice(null);
|
||||
reqVO.setBeforePayPrice(null);
|
||||
reqVO.setIsAlterPrice(null);
|
||||
reqVO.setOutTradeNo(null);
|
||||
reqVO.setPaySerialNumber(null);
|
||||
|
||||
// 调用
|
||||
PageResult<RechargeOrderDO> pageResult = rechargeOrderService.getRechargeOrderPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRechargeOrder, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRechargeOrderList() {
|
||||
// mock 数据
|
||||
RechargeOrderDO dbRechargeOrder = randomPojo(RechargeOrderDO.class, o -> { // 等会查询到
|
||||
o.setOrderId(null);
|
||||
o.setUid(null);
|
||||
o.setRealName(null);
|
||||
o.setUserPhone(null);
|
||||
o.setConfirmPhone(null);
|
||||
o.setTotalNum(null);
|
||||
o.setTotalPrice(null);
|
||||
o.setPayPrice(null);
|
||||
o.setPaid(null);
|
||||
o.setPayTime(null);
|
||||
o.setPayEndTime(null);
|
||||
o.setPayType(null);
|
||||
o.setCreateTime(null);
|
||||
o.setStatus(null);
|
||||
o.setRefundStatus(null);
|
||||
o.setRefundReasonWapImg(null);
|
||||
o.setRefundReasonWapExplain(null);
|
||||
o.setRefundReasonWap(null);
|
||||
o.setRefundReason(null);
|
||||
o.setRefundReasonTime(null);
|
||||
o.setRefundPrice(null);
|
||||
o.setMark(null);
|
||||
o.setRemark(null);
|
||||
o.setCost(null);
|
||||
o.setIsChannel(null);
|
||||
o.setIsRemind(null);
|
||||
o.setIsSystemDel(null);
|
||||
o.setType(null);
|
||||
o.setProTotalPrice(null);
|
||||
o.setBeforePayPrice(null);
|
||||
o.setIsAlterPrice(null);
|
||||
o.setOutTradeNo(null);
|
||||
o.setPaySerialNumber(null);
|
||||
});
|
||||
rechargeOrderMapper.insert(dbRechargeOrder);
|
||||
// 测试 orderId 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setOrderId(null)));
|
||||
// 测试 uid 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setUid(null)));
|
||||
// 测试 realName 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRealName(null)));
|
||||
// 测试 userPhone 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setUserPhone(null)));
|
||||
// 测试 confirmPhone 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setConfirmPhone(null)));
|
||||
// 测试 totalNum 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setTotalNum(null)));
|
||||
// 测试 totalPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setTotalPrice(null)));
|
||||
// 测试 payPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayPrice(null)));
|
||||
// 测试 paid 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPaid(null)));
|
||||
// 测试 payTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayTime(null)));
|
||||
// 测试 payEndTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayEndTime(null)));
|
||||
// 测试 payType 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPayType(null)));
|
||||
// 测试 createTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setCreateTime(null)));
|
||||
// 测试 status 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setStatus(null)));
|
||||
// 测试 refundStatus 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundStatus(null)));
|
||||
// 测试 refundReasonWapImg 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWapImg(null)));
|
||||
// 测试 refundReasonWapExplain 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWapExplain(null)));
|
||||
// 测试 refundReasonWap 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonWap(null)));
|
||||
// 测试 refundReason 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReason(null)));
|
||||
// 测试 refundReasonTime 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundReasonTime(null)));
|
||||
// 测试 refundPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRefundPrice(null)));
|
||||
// 测试 mark 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setMark(null)));
|
||||
// 测试 remark 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setRemark(null)));
|
||||
// 测试 cost 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setCost(null)));
|
||||
// 测试 isChannel 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsChannel(null)));
|
||||
// 测试 isRemind 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsRemind(null)));
|
||||
// 测试 isSystemDel 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsSystemDel(null)));
|
||||
// 测试 type 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setType(null)));
|
||||
// 测试 proTotalPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setProTotalPrice(null)));
|
||||
// 测试 beforePayPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setBeforePayPrice(null)));
|
||||
// 测试 isAlterPrice 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setIsAlterPrice(null)));
|
||||
// 测试 outTradeNo 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setOutTradeNo(null)));
|
||||
// 测试 paySerialNumber 不匹配
|
||||
rechargeOrderMapper.insert(cloneIgnoreId(dbRechargeOrder, o -> o.setPaySerialNumber(null)));
|
||||
// 准备参数
|
||||
RechargeOrderExportReqVO reqVO = new RechargeOrderExportReqVO();
|
||||
reqVO.setOrderId(null);
|
||||
reqVO.setUid(null);
|
||||
reqVO.setRealName(null);
|
||||
reqVO.setUserPhone(null);
|
||||
reqVO.setConfirmPhone(null);
|
||||
reqVO.setTotalNum(null);
|
||||
reqVO.setTotalPrice(null);
|
||||
reqVO.setPayPrice(null);
|
||||
reqVO.setPaid(null);
|
||||
reqVO.setPayTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPayEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setPayType(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setRefundStatus(null);
|
||||
reqVO.setRefundReasonWapImg(null);
|
||||
reqVO.setRefundReasonWapExplain(null);
|
||||
reqVO.setRefundReasonWap(null);
|
||||
reqVO.setRefundReason(null);
|
||||
reqVO.setRefundReasonTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setRefundPrice(null);
|
||||
reqVO.setMark(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setCost(null);
|
||||
reqVO.setIsChannel(null);
|
||||
reqVO.setIsRemind(null);
|
||||
reqVO.setIsSystemDel(null);
|
||||
reqVO.setType(null);
|
||||
reqVO.setProTotalPrice(null);
|
||||
reqVO.setBeforePayPrice(null);
|
||||
reqVO.setIsAlterPrice(null);
|
||||
reqVO.setOutTradeNo(null);
|
||||
reqVO.setPaySerialNumber(null);
|
||||
|
||||
// 调用
|
||||
List<RechargeOrderDO> list = rechargeOrderService.getRechargeOrderList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRechargeOrder, list.get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
package cn.iocoder.yudao.module.shop.service.recharge;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*;
|
||||
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RefundFeeRecordDO;
|
||||
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RefundFeeRecordMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.shop.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link RefundFeeRecordServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 创盈云
|
||||
*/
|
||||
@Import(RefundFeeRecordServiceImpl.class)
|
||||
public class RefundFeeRecordServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private RefundFeeRecordServiceImpl refundFeeRecordService;
|
||||
|
||||
@Resource
|
||||
private RefundFeeRecordMapper refundFeeRecordMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateRefundFeeRecord_success() {
|
||||
// 准备参数
|
||||
RefundFeeRecordCreateReqVO reqVO = randomPojo(RefundFeeRecordCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long refundFeeRecordId = refundFeeRecordService.createRefundFeeRecord(reqVO);
|
||||
// 断言
|
||||
assertNotNull(refundFeeRecordId);
|
||||
// 校验记录的属性是否正确
|
||||
RefundFeeRecordDO refundFeeRecord = refundFeeRecordMapper.selectById(refundFeeRecordId);
|
||||
assertPojoEquals(reqVO, refundFeeRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRefundFeeRecord_success() {
|
||||
// mock 数据
|
||||
RefundFeeRecordDO dbRefundFeeRecord = randomPojo(RefundFeeRecordDO.class);
|
||||
refundFeeRecordMapper.insert(dbRefundFeeRecord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
RefundFeeRecordUpdateReqVO reqVO = randomPojo(RefundFeeRecordUpdateReqVO.class, o -> {
|
||||
o.setId(dbRefundFeeRecord.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
refundFeeRecordService.updateRefundFeeRecord(reqVO);
|
||||
// 校验是否更新正确
|
||||
RefundFeeRecordDO refundFeeRecord = refundFeeRecordMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, refundFeeRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRefundFeeRecord_notExists() {
|
||||
// 准备参数
|
||||
RefundFeeRecordUpdateReqVO reqVO = randomPojo(RefundFeeRecordUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> refundFeeRecordService.updateRefundFeeRecord(reqVO), REFUND_FEE_RECORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRefundFeeRecord_success() {
|
||||
// mock 数据
|
||||
RefundFeeRecordDO dbRefundFeeRecord = randomPojo(RefundFeeRecordDO.class);
|
||||
refundFeeRecordMapper.insert(dbRefundFeeRecord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbRefundFeeRecord.getId();
|
||||
|
||||
// 调用
|
||||
refundFeeRecordService.deleteRefundFeeRecord(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(refundFeeRecordMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRefundFeeRecord_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> refundFeeRecordService.deleteRefundFeeRecord(id), REFUND_FEE_RECORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRefundFeeRecordPage() {
|
||||
// mock 数据
|
||||
RefundFeeRecordDO dbRefundFeeRecord = randomPojo(RefundFeeRecordDO.class, o -> { // 等会查询到
|
||||
o.setPhoneRecordId(null);
|
||||
o.setRechargeOrderId(null);
|
||||
o.setPhone(null);
|
||||
o.setBusinessName(null);
|
||||
o.setBelongingPlace(null);
|
||||
o.setDenomination(null);
|
||||
o.setStatus(null);
|
||||
o.setTransactionTime(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
refundFeeRecordMapper.insert(dbRefundFeeRecord);
|
||||
// 测试 phoneRecordId 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setPhoneRecordId(null)));
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 phone 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setPhone(null)));
|
||||
// 测试 businessName 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setBusinessName(null)));
|
||||
// 测试 belongingPlace 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setBelongingPlace(null)));
|
||||
// 测试 denomination 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setDenomination(null)));
|
||||
// 测试 status 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setStatus(null)));
|
||||
// 测试 transactionTime 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setTransactionTime(null)));
|
||||
// 测试 createTime 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
RefundFeeRecordPageReqVO reqVO = new RefundFeeRecordPageReqVO();
|
||||
reqVO.setPhoneRecordId(null);
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setPhone(null);
|
||||
reqVO.setBusinessName(null);
|
||||
reqVO.setBelongingPlace(null);
|
||||
reqVO.setDenomination(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setTransactionTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<RefundFeeRecordDO> pageResult = refundFeeRecordService.getRefundFeeRecordPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRefundFeeRecord, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetRefundFeeRecordList() {
|
||||
// mock 数据
|
||||
RefundFeeRecordDO dbRefundFeeRecord = randomPojo(RefundFeeRecordDO.class, o -> { // 等会查询到
|
||||
o.setPhoneRecordId(null);
|
||||
o.setRechargeOrderId(null);
|
||||
o.setPhone(null);
|
||||
o.setBusinessName(null);
|
||||
o.setBelongingPlace(null);
|
||||
o.setDenomination(null);
|
||||
o.setStatus(null);
|
||||
o.setTransactionTime(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
refundFeeRecordMapper.insert(dbRefundFeeRecord);
|
||||
// 测试 phoneRecordId 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setPhoneRecordId(null)));
|
||||
// 测试 rechargeOrderId 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setRechargeOrderId(null)));
|
||||
// 测试 phone 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setPhone(null)));
|
||||
// 测试 businessName 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setBusinessName(null)));
|
||||
// 测试 belongingPlace 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setBelongingPlace(null)));
|
||||
// 测试 denomination 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setDenomination(null)));
|
||||
// 测试 status 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setStatus(null)));
|
||||
// 测试 transactionTime 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setTransactionTime(null)));
|
||||
// 测试 createTime 不匹配
|
||||
refundFeeRecordMapper.insert(cloneIgnoreId(dbRefundFeeRecord, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
RefundFeeRecordExportReqVO reqVO = new RefundFeeRecordExportReqVO();
|
||||
reqVO.setPhoneRecordId(null);
|
||||
reqVO.setRechargeOrderId(null);
|
||||
reqVO.setPhone(null);
|
||||
reqVO.setBusinessName(null);
|
||||
reqVO.setBelongingPlace(null);
|
||||
reqVO.setDenomination(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setTransactionTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
List<RefundFeeRecordDO> list = refundFeeRecordService.getRefundFeeRecordList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRefundFeeRecord, list.get(0));
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue