package cn.iocoder.yudao.module.configure.service.inspectionitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.configure.controller.admin.inspectionitem.vo.InspectionItemPageReqVO;
import cn.iocoder.yudao.module.configure.dal.dataobject.inspectionitem.InspectionItemDO;
import cn.iocoder.yudao.module.configure.dal.mysql.inspectionitem.InspectionItemMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* {@link InspectionItemServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(InspectionItemServiceImpl.class)
public class InspectionItemServiceImplTest extends BaseDbUnitTest {

    @Resource
    private InspectionItemServiceImpl inspectionItemService;

    @Resource
    private InspectionItemMapper inspectionItemMapper;

    @Test
    @Disabled  // TODO 请修改 null 为需要的值，然后删除 @Disabled 注解
    public void testGetInspectionItemPage() {
       // mock 数据
       InspectionItemDO dbInspectionItem = randomPojo(InspectionItemDO.class, o -> { // 等会查询到
           o.setTemplateId(null);
           o.setTemplateName(null);
           o.setInspectionItem(null);
           o.setInspectionItemId(null);
           o.setInspectionUnit(null);
           o.setInspectionRequire(null);
           o.setBelongBusinessId(null);
           o.setBelongBusinessName(null);
           o.setCreateTime(null);
       });
       inspectionItemMapper.insert(dbInspectionItem);
       // 测试 templateId 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setTemplateId(null)));
       // 测试 templateName 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setTemplateName(null)));
       // 测试 inspectionItem 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setInspectionItem(null)));
       // 测试 inspectionItemId 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setInspectionItemId(null)));
       // 测试 inspectionUnit 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setInspectionUnit(null)));
       // 测试 inspectionRequire 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setInspectionRequire(null)));
       // 测试 belongBusinessId 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setBelongBusinessId(null)));
       // 测试 belongBusinessName 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setBelongBusinessName(null)));
       // 测试 createTime 不匹配
       inspectionItemMapper.insert(cloneIgnoreId(dbInspectionItem, o -> o.setCreateTime(null)));
       // 准备参数
       InspectionItemPageReqVO reqVO = new InspectionItemPageReqVO();
        LocalDateTime[] localDateTimes = LocalDateTimeUtils.buildBetweenTime(2023, 2, 1, 2023, 2, 28);
        Date[] dates = new Date[localDateTimes.length];
        for(int i=0; i<localDateTimes.length; i++) {
            dates[i] = Date.from(localDateTimes[i].atZone(ZoneId.systemDefault()).toInstant());
        }
       reqVO.setTemplateId(null);
       reqVO.setTemplateName(null);
       reqVO.setInspectionItem(null);
       reqVO.setInspectionItemId(null);
       reqVO.setInspectionUnit(null);
       reqVO.setInspectionRequire(null);
       reqVO.setBelongBusinessId(null);
       reqVO.setBelongBusinessName(null);
       reqVO.setCreateTime(dates);

       // 调用
       PageResult<InspectionItemDO> pageResult = inspectionItemService.getInspectionItemPage(reqVO);
       // 断言
       assertEquals(1, pageResult.getTotal());
       assertEquals(1, pageResult.getList().size());
       assertPojoEquals(dbInspectionItem, pageResult.getList().get(0));
    }

}
