|
|
@@ -8,7 +8,9 @@ import org.junit.jupiter.api.Test;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.ruoyi.app.omgpay.OmgPaymentErrorCode.ORDER_ALREADY_PAID;
|
|
|
+import static com.ruoyi.app.omgpay.OmgPaymentErrorCode.ORDER_NOT_AVAILABLE;
|
|
|
import static com.ruoyi.app.omgpay.OmgPaymentErrorCode.PAYMENT_METHOD_INVALID;
|
|
|
+import static com.ruoyi.app.omgpay.OmgPaymentErrorCode.PAYMENT_QUERY_NOT_AVAILABLE;
|
|
|
import static com.ruoyi.app.omgpay.OmgPaymentErrorCode.PAYMENT_RETRY_NOT_AVAILABLE;
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
|
|
@@ -90,6 +92,33 @@ class OmgPaymentRetryServiceTest {
|
|
|
verifyNoInteractions(createService);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void createsFreshAttemptWhenNoActiveAttemptRemains() {
|
|
|
+ // 旧尝试被自动补偿任务关闭为 FAILED/SUPERSEDED 后 active 指针已释放,
|
|
|
+ // query 找不到可查记录时,重新付款必须回落到新建而不是死路。
|
|
|
+ OmgPaymentCreateOutcome expected = outcome();
|
|
|
+ when(queryService.query(5L, "DD-1"))
|
|
|
+ .thenThrow(new OmgPaymentBusinessException(PAYMENT_QUERY_NOT_AVAILABLE, 77L));
|
|
|
+ when(createService.create(5L, "DD-1", OmgPaymentMethod.CREDIT)).thenReturn(expected);
|
|
|
+
|
|
|
+ assertSame(expected, service.retry(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
+
|
|
|
+ verify(createService).create(5L, "DD-1", OmgPaymentMethod.CREDIT);
|
|
|
+ verify(createService, never()).replaceActiveForRetry(5L, "DD-1", "OMGOLD", OmgPaymentMethod.CREDIT);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void propagatesUnrelatedQueryErrorsWithoutCreating() {
|
|
|
+ when(queryService.query(5L, "DD-1"))
|
|
|
+ .thenThrow(new OmgPaymentBusinessException(ORDER_NOT_AVAILABLE));
|
|
|
+
|
|
|
+ OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
+ () -> service.retry(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
+
|
|
|
+ assertEquals(ORDER_NOT_AVAILABLE, error.getCode());
|
|
|
+ verifyNoInteractions(createService);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void rejectsNullPaymentMethodBeforeQuery() {
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|