package com.ruoyi.web.modules.trading.support;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.trading.SupplierSettlementTestSamples;
import com.ruoyi.web.modules.trading.domain.BizSupplierSettlement;

@DisplayName("SettlementValidation")
class SettlementValidationTest
{
    private final SettlementValidation validation = new SettlementValidation();

    @Test
    @DisplayName("ZCZX-GYSJSGL-UT-011 缺凭证")
    void ut011_missingVoucher()
    {
        BizSupplierSettlement row = new BizSupplierSettlement();
        row.setId(SupplierSettlementTestSamples.SETTLEMENT_ID);
        ServiceException ex = assertThrows(ServiceException.class, () -> validation.validateSettleVoucher(row));
        assertEquals(SettlementRules.MSG_SETTLE_VOUCHER_REQUIRED, ex.getMessage());
    }

    @Test
    @DisplayName("ZCZX-GYSJSGL-UT-012 非法后缀")
    void ut012_invalidSuffix()
    {
        BizSupplierSettlement row = SupplierSettlementTestSamples.settleRequest();
        row.setSettleVoucherPath("/upload/bad.pdf");
        ServiceException ex = assertThrows(ServiceException.class, () -> validation.validateSettleVoucher(row));
        assertEquals(SettlementRules.MSG_SETTLE_VOUCHER_INVALID, ex.getMessage());
    }

    @Test
    @DisplayName("ZCZX-GYSJSGL-UT-013 合法 png")
    void ut013_validPng()
    {
        BizSupplierSettlement row = SupplierSettlementTestSamples.settleRequest();
        row.setSettleVoucherPath("/upload/ok.png");
        assertDoesNotThrow(() -> validation.validateSettleVoucher(row));
    }
}
