|
@@ -0,0 +1,130 @@
|
|
|
|
|
+package com.ruoyi.app.pay;
|
|
|
|
|
+
|
|
|
|
|
+import com.ruoyi.system.domain.PaymentMethodConfig;
|
|
|
|
|
+import com.ruoyi.system.mapper.InfoBankCardMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.InfoUserMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.PaymentMethodConfigMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.PosStoreLinePayMapper;
|
|
|
|
|
+import com.ruoyi.system.mapper.PosStoreOmgMapper;
|
|
|
|
|
+import com.ruoyi.system.service.PaymentMethodGateService;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 商家支付设置页就绪度聚合单测(031):available=平台开放全集,
|
|
|
|
|
+ * 线上渠道任一门店有启用凭证即就绪,线下转账看主账号启用卡,COD/现金恒就绪。
|
|
|
|
|
+ */
|
|
|
|
|
+class PaymentMethodGateSettingsReadyTest {
|
|
|
|
|
+
|
|
|
|
|
+ private PaymentMethodGateService gateService;
|
|
|
|
|
+ private PaymentMethodConfigMapper configMapper;
|
|
|
|
|
+ private InfoUserMapper userMapper;
|
|
|
|
|
+ private InfoBankCardMapper bankCardMapper;
|
|
|
|
|
+ private PosStoreOmgMapper omgMapper;
|
|
|
|
|
+ private PosStoreLinePayMapper linePayMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @BeforeEach
|
|
|
|
|
+ void setUp() {
|
|
|
|
|
+ configMapper = mock(PaymentMethodConfigMapper.class);
|
|
|
|
|
+ userMapper = mock(InfoUserMapper.class);
|
|
|
|
|
+ bankCardMapper = mock(InfoBankCardMapper.class);
|
|
|
|
|
+ omgMapper = mock(PosStoreOmgMapper.class);
|
|
|
|
|
+ linePayMapper = mock(PosStoreLinePayMapper.class);
|
|
|
|
|
+ gateService = new PaymentMethodGateService(
|
|
|
|
|
+ configMapper, userMapper, bankCardMapper, omgMapper, linePayMapper);
|
|
|
|
|
+ // 平台缺行=开;selectCount 缺省返回 null 会拆箱 NPE,统一补 0
|
|
|
|
|
+ when(configMapper.selectList(any())).thenReturn(List.of());
|
|
|
|
|
+ when(bankCardMapper.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+ when(omgMapper.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+ when(linePayMapper.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private PaymentMethodGateService.PayMethodOption option(
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options, String payType) {
|
|
|
|
|
+ return options.stream().filter(item -> payType.equals(item.getPayType()))
|
|
|
|
|
+ .findFirst().orElseThrow(() -> new AssertionError("缺少 payType " + payType));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void credentialMissingMarksCardAndLineNotReadyWhileCodCashReady() {
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+
|
|
|
|
|
+ assertFalse(option(options, "2").isReady());
|
|
|
|
|
+ assertFalse(option(options, "5").isReady());
|
|
|
|
|
+ assertFalse(option(options, "3").isReady());
|
|
|
|
|
+ assertFalse(option(options, "6").isReady());
|
|
|
|
|
+ assertTrue(option(options, "1").isReady());
|
|
|
|
|
+ assertTrue(option(options, "4").isReady());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void anyStoreCredentialMakesWholeGroupReady() {
|
|
|
|
|
+ // 两家门店:第一查无凭证、第二有 → CARD_OMG(2/5)整体就绪;组内就绪度一致
|
|
|
|
|
+ when(omgMapper.selectCount(any())).thenReturn(0L, 1L);
|
|
|
|
|
+
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L, 12L));
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(option(options, "2").isReady());
|
|
|
|
|
+ assertTrue(option(options, "5").isReady());
|
|
|
|
|
+ assertFalse(option(options, "3").isReady());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void linePayReadyFollowsLinePayCredentialOnly() {
|
|
|
|
|
+ when(linePayMapper.selectCount(any())).thenReturn(1L);
|
|
|
|
|
+
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(option(options, "3").isReady());
|
|
|
|
|
+ assertFalse(option(options, "2").isReady());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void offlineReadyRequiresOwnerActiveCard() {
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> withoutCard =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+ assertFalse(option(withoutCard, "6").isReady());
|
|
|
|
|
+
|
|
|
|
|
+ when(bankCardMapper.selectCount(any())).thenReturn(1L);
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> withCard =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+ assertTrue(option(withCard, "6").isReady());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void platformDisabledGroupExcludedFromSettingsAvailable() {
|
|
|
|
|
+ PaymentMethodConfig disabled = new PaymentMethodConfig();
|
|
|
|
|
+ disabled.setMethodCode("CARD_OMG");
|
|
|
|
|
+ disabled.setScope("MERCHANT");
|
|
|
|
|
+ disabled.setEnabled(0);
|
|
|
|
|
+ when(configMapper.selectList(any())).thenReturn(List.of(disabled));
|
|
|
|
|
+
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+
|
|
|
|
|
+ assertFalse(options.stream().anyMatch(item -> "CARD_OMG".equals(item.getMethodCode())));
|
|
|
|
|
+ assertEquals("1", option(options, "1").getPayType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void cardOmgExpandsToTwoPayTypesWithSameReady() {
|
|
|
|
|
+ List<PaymentMethodGateService.PayMethodOption> options =
|
|
|
|
|
+ gateService.listAvailableForMerchantSettings(7L, List.of(11L));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(2, options.stream().filter(item -> "CARD_OMG".equals(item.getMethodCode())).count());
|
|
|
|
|
+ assertEquals("2", option(options, "2").getPayType());
|
|
|
|
|
+ assertEquals("5", option(options, "5").getPayType());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|