| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.qc.imports; |
| | | |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcSaveReqVO; |
| | | import jakarta.validation.Validation; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | | class MesQcOptionalClientTest { |
| | | @Test |
| | | void emptyCustomerDoesNotCallCrmOrRequireCustomerPermission() { |
| | | CrmCustomerApi crm = mock(CrmCustomerApi.class); |
| | | MesQcImportHelper helper = new MesQcImportHelper(); |
| | | ReflectionTestUtils.setField(helper, "crmCustomerApi", crm); |
| | | assertNull(helper.resolveClientId(null)); |
| | | assertNull(helper.resolveClientId(" ")); |
| | | helper.validateClientPermission(null, ""); |
| | | verifyNoInteractions(crm); |
| | | } |
| | | |
| | | @Test |
| | | void aSuppliedUnknownCustomerIsStillRejected() { |
| | | CrmCustomerApi crm = mock(CrmCustomerApi.class); |
| | | when(crm.getCustomerSimpleList()).thenReturn(List.of()); |
| | | MesQcImportHelper helper = new MesQcImportHelper(); |
| | | ReflectionTestUtils.setField(helper, "crmCustomerApi", crm); |
| | | assertThrows(IllegalArgumentException.class, () -> helper.resolveClientId("ä¸åå¨ç客æ·")); |
| | | } |
| | | |
| | | @Test |
| | | void customerPermissionsDoNotRestrictMesImports() { |
| | | CrmCustomerApi crm = mock(CrmCustomerApi.class); |
| | | when(crm.getPermittedCustomerIds()).thenReturn(List.of(10L)); |
| | | MesQcImportHelper helper = new MesQcImportHelper(); |
| | | ReflectionTestUtils.setField(helper, "crmCustomerApi", crm); |
| | | helper.validateClientPermission(10L, "å¯è§å®¢æ·"); |
| | | assertDoesNotThrow(() -> helper.validateClientPermission(20L, "å
¶ä»å®¢æ·")); |
| | | verifyNoInteractions(crm); |
| | | } |
| | | |
| | | @Test |
| | | void saveRequestAllowsEmptyCustomerButStillRequiresMaterial() { |
| | | MesQcOqcSaveReqVO req = new MesQcOqcSaveReqVO(); |
| | | req.setCode("OQC-OPTIONAL-CUSTOMER");req.setName("åºè´§æ£éª");req.setItemId(10L); |
| | | req.setOutQuantity(BigDecimal.TEN);req.setCheckQuantity(BigDecimal.ONE); |
| | | req.setQualifiedQuantity(BigDecimal.ONE);req.setUnqualifiedQuantity(BigDecimal.ZERO); |
| | | req.setOutDate(LocalDateTime.now());req.setInspectDate(LocalDateTime.now());req.setInspectorUserId(1L); |
| | | try (var factory = Validation.buildDefaultValidatorFactory()) { |
| | | assertTrue(factory.getValidator().validate(req).isEmpty()); |
| | | req.setItemId(null); |
| | | assertFalse(factory.getValidator().validate(req).isEmpty()); |
| | | } |
| | | } |
| | | } |