package cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc;
|
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcPageReqVO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcDO;
|
import jakarta.annotation.Resource;
|
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
class MesQcOqcMapperTest extends BaseDbUnitTest {
|
@Resource
|
private MesQcOqcMapper mapper;
|
private final LocalDateTime date = LocalDateTime.of(2026, 10, 12, 0, 0);
|
|
@BeforeEach
|
void clearOqcRows() {
|
mapper.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesQcOqcDO>());
|
}
|
|
private MesQcOqcDO insert(String code, Long clientId) {
|
MesQcOqcDO row = new MesQcOqcDO().setCode(code).setName(code).setItemId(10L)
|
.setTemplateId(20L).setClientId(clientId).setBatchCode("B001")
|
.setOutDate(date).setOutQuantity(BigDecimal.TEN).setStatus(0);
|
mapper.insert(row);
|
return row;
|
}
|
|
@Test
|
void emptyCustomerPersistsAndHasItsOwnDuplicateKey() {
|
insert("OQC-NO-CLIENT", null);
|
insert("OQC-CLIENT", 100L);
|
assertEquals(1, mapper.selectListByImportKey(10L, null, "B001", date).size());
|
assertEquals(1, mapper.selectListByImportKey(10L, 100L, "B001", date).size());
|
assertEquals(0, mapper.selectListByImportKey(10L, 200L, "B001", date).size());
|
}
|
|
@Test
|
void unassignedRecordsVisibleWithoutExposingUnauthorizedCustomers() {
|
insert("UNASSIGNED", null);
|
insert("ALLOWED", 100L);
|
insert("FORBIDDEN", 200L);
|
assertEquals(1L, mapper.selectPage(new MesQcOqcPageReqVO(), List.of()).getTotal());
|
assertEquals(2L, mapper.selectPage(new MesQcOqcPageReqVO(), List.of(100L)).getTotal());
|
assertEquals(3L, mapper.selectPage(new MesQcOqcPageReqVO(), (List<Long>) null).getTotal());
|
MesQcOqcPageReqVO filtered = new MesQcOqcPageReqVO();
|
filtered.setClientId(200L);
|
assertEquals(0L, mapper.selectPage(filtered, List.of(100L)).getTotal());
|
}
|
|
@Test
|
void changingInspectionStatusDoesNotClearAnExistingCustomer() {
|
MesQcOqcDO row = insert("STATUS-UPDATE", 100L);
|
mapper.updateById(new MesQcOqcDO().setId(row.getId()).setStatus(1));
|
assertEquals(100L, mapper.selectById(row.getId()).getClientId());
|
}
|
}
|