package com.ruoyi.app.omgpay;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class OmgPaymentRefundServiceTest {
    private final OmgPaymentRefundService service = new OmgPaymentRefundService();

    @Test
    void testEnvironmentRejectsRefundBeforeAnyGatewayOrStateChangeCanExist() {
        OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
                () -> service.refund(5L, "DD-1"));

        assertEquals(OmgPaymentErrorCode.PAYMENT_REFUND_UNAVAILABLE_IN_TEST_ENVIRONMENT,
                error.getCode());
    }

    @Test
    void validatesAuthenticationAndOrderIdBeforeEnvironmentResponse() {
        assertEquals(OmgPaymentErrorCode.AUTH_REQUIRED,
                assertThrows(OmgPaymentBusinessException.class,
                        () -> service.refund(null, "DD-1")).getCode());
        assertEquals(OmgPaymentErrorCode.ORDER_REQUIRED,
                assertThrows(OmgPaymentBusinessException.class,
                        () -> service.refund(5L, " ")).getCode());
        assertEquals(OmgPaymentErrorCode.ORDER_REQUIRED,
                assertThrows(OmgPaymentBusinessException.class,
                        () -> service.refund(5L, "X".repeat(65))).getCode());
    }
}
