Browse Source

完善 OMG 表单渠道验收测试

qmj 1 month ago
parent
commit
267fdc0874

+ 22 - 3
ruoyi-admin/src/test/java/com/ruoyi/app/omgpay/OmgPaymentFormFactoryTest.java

@@ -11,11 +11,13 @@ import java.time.Instant;
 import java.time.ZoneOffset;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Set;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.anyMap;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
@@ -27,23 +29,33 @@ class OmgPaymentFormFactoryTest {
     void buildsSignedCreditCardForm() {
         OmgPaymentProperties properties = properties();
         OmgCheckMacSigner signer = mock(OmgCheckMacSigner.class);
-        when(signer.sign(anyMap(), eq("KEY"), eq("IV"))).thenReturn("A".repeat(64));
+        String checkMacValue = "A".repeat(64);
+        when(signer.sign(anyMap(), eq("KEY"), eq("IV"))).thenReturn(checkMacValue);
         OmgPaymentFormFactory factory = new OmgPaymentFormFactory(properties, signer,
                 Clock.fixed(Instant.parse("2026-08-13T07:30:23Z"), ZoneOffset.UTC));
 
-        OmgPaymentForm credit = factory.create("DD-1", 100, "1000031", "KEY", "IV",
+        OmgPaymentForm credit = factory.create("DD-<script>#|訂單", 100, "1000031", "KEY", "IV",
                 "OMG12345678901234567", OmgPaymentMethod.CREDIT);
 
         assertEquals(OmgPaymentFormFactory.STAGE_GATEWAY_URL, credit.gatewayUrl());
+        assertEquals(Set.of("MerchantID", "MerchantTradeNo", "MerchantTradeDate", "PaymentType",
+                "TotalAmount", "TradeDesc", "ItemName", "ReturnURL", "OrderResultURL", "ChoosePayment",
+                "UnionPay", "EncryptType", "InvoiceMark", "NeedExtraPaidInfo", "CheckMacValue"),
+                credit.fields().keySet());
         assertEquals("2026/08/13 15:30:23", credit.fields().get("MerchantTradeDate"));
         assertEquals("Credit", credit.fields().get("ChoosePayment"));
         assertEquals("2", credit.fields().get("UnionPay"));
         assertFalse(credit.fields().containsKey("IgnorePayment"));
+        assertEquals("Foodie order DDscript", credit.fields().get("TradeDesc"));
+        assertFalse(credit.fields().get("ItemName").contains("|"));
+        assertTrue(credit.fields().get("ItemName").length() <= 120);
         assertEquals("Y", credit.fields().get("NeedExtraPaidInfo"));
         assertEquals("https://foodieapi.waimai-paotui.com/pay/omg/result",
                 credit.fields().get("OrderResultURL"));
+        assertEquals(checkMacValue, credit.fields().get("CheckMacValue"));
         ArgumentCaptor<Map<String, String>> signedFields = ArgumentCaptor.forClass(Map.class);
         verify(signer).sign(signedFields.capture(), eq("KEY"), eq("IV"));
+        assertEquals(14, signedFields.getValue().size());
         Map<String, String> expectedSignedFields = new LinkedHashMap<>(credit.fields());
         expectedSignedFields.remove("CheckMacValue");
         assertEquals(expectedSignedFields, signedFields.getValue());
@@ -54,18 +66,25 @@ class OmgPaymentFormFactoryTest {
     void buildsSignedApplePayForm() {
         OmgPaymentProperties properties = properties();
         OmgCheckMacSigner signer = mock(OmgCheckMacSigner.class);
-        when(signer.sign(anyMap(), eq("KEY"), eq("IV"))).thenReturn("A".repeat(64));
+        String checkMacValue = "A".repeat(64);
+        when(signer.sign(anyMap(), eq("KEY"), eq("IV"))).thenReturn(checkMacValue);
         OmgPaymentFormFactory factory = new OmgPaymentFormFactory(properties, signer,
                 Clock.fixed(Instant.parse("2026-08-13T07:30:23Z"), ZoneOffset.UTC));
 
         OmgPaymentForm applePay = factory.create("DD-1", 100, "1000031", "KEY", "IV",
                 "OMG12345678901234567", OmgPaymentMethod.APPLE_PAY);
 
+        assertEquals(Set.of("MerchantID", "MerchantTradeNo", "MerchantTradeDate", "PaymentType",
+                "TotalAmount", "TradeDesc", "ItemName", "ReturnURL", "OrderResultURL", "ChoosePayment",
+                "EncryptType", "InvoiceMark", "NeedExtraPaidInfo", "CheckMacValue"),
+                applePay.fields().keySet());
         assertEquals("ApplePay", applePay.fields().get("ChoosePayment"));
         assertFalse(applePay.fields().containsKey("UnionPay"));
         assertFalse(applePay.fields().containsKey("IgnorePayment"));
+        assertEquals(checkMacValue, applePay.fields().get("CheckMacValue"));
         ArgumentCaptor<Map<String, String>> signedFields = ArgumentCaptor.forClass(Map.class);
         verify(signer).sign(signedFields.capture(), eq("KEY"), eq("IV"));
+        assertEquals(13, signedFields.getValue().size());
         Map<String, String> expectedSignedFields = new LinkedHashMap<>(applePay.fields());
         expectedSignedFields.remove("CheckMacValue");
         assertEquals(expectedSignedFields, signedFields.getValue());

+ 1 - 1
specs/020-omg-payment-rebuild/plan.md

@@ -1461,7 +1461,7 @@ git commit -m "实现 OMG 信用卡与 Apple Pay 双入口"
 
 **Interfaces:**
 
-- Consumes: Task 1 的独立实现提交与项目现有 OMG 全部功能。
+- Consumes: Task 18 的独立实现提交与项目现有 OMG 全部功能。
 - Produces: 定向测试、完整 OMG 回归、模块构建和 stage 双渠道人工证据。
 
 - [ ] **Step 1: 使用 JDK 21 运行渠道定向测试**