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

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

import java.math.BigDecimal;
import java.util.Date;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord;

/**
 * ZCZX-BTJL-UT-014～016
 */
@DisplayName("SubsidyGrantRecordMasking")
class SubsidyGrantRecordMaskingTest
{
    @Test
    @DisplayName("ZCZX-BTJL-UT-014 身份证脱敏")
    void ut014_maskIdCard()
    {
        String masked = SubsidyGrantRecordMasking.maskIdCard("11010519491231002X");
        assertEquals("1101**********002X", masked);
        assertTrue(masked.startsWith("1101"));
        assertTrue(masked.endsWith("002X"));
    }

    @Test
    @DisplayName("ZCZX-BTJL-UT-015 手机号脱敏")
    void ut015_maskPhone()
    {
        assertEquals("138****8000", SubsidyGrantRecordMasking.maskPhone("13800138000"));
    }

    @Test
    @DisplayName("ZCZX-BTJL-UT-016 无特权详情脱敏")
    void ut016_applyMask()
    {
        BizSubsidyGrantRecord row = sample();
        SubsidyGrantRecordMasking.applySensitiveMask(row, false);
        assertTrue(row.getIdCard().contains("*"));
        assertTrue(row.getContactPhone().contains("****"));
        assertTrue(row.getBankAccount().contains("*"));

        BizSubsidyGrantRecord full = sample();
        SubsidyGrantRecordMasking.applySensitiveMask(full, true);
        assertEquals("11010519491231002X", full.getIdCard());
        assertEquals("13800138000", full.getContactPhone());
    }

    private static BizSubsidyGrantRecord sample()
    {
        BizSubsidyGrantRecord r = new BizSubsidyGrantRecord();
        r.setSubsidyProjectName("农业补贴");
        r.setSubsidyType(1);
        r.setRecipientName("张三");
        r.setIdCard("11010519491231002X");
        r.setContactPhone("13800138000");
        r.setBankAccount("6222021234567890");
        r.setSubsidyAmount(new BigDecimal("1000.00"));
        r.setGrantDate(new Date());
        return r;
    }
}
