package com.ruoyi.loanpricing.service;

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

import org.junit.jupiter.api.Test;

class SensitiveFieldCryptoServiceTest
{
    @Test
    void shouldEncryptAndDecryptCustNameAndIdNum()
    {
        SensitiveFieldCryptoService service = new SensitiveFieldCryptoService("1234567890abcdef");

        String nameCipher = service.encrypt("张三");
        String idNumCipher = service.encrypt("110101199001011234");

        assertNotEquals("张三", nameCipher);
        assertNotEquals("110101199001011234", idNumCipher);
        assertEquals("张三", service.decrypt(nameCipher));
        assertEquals("110101199001011234", service.decrypt(idNumCipher));
    }

    @Test
    void shouldRejectBlankKeyConfiguration()
    {
        SensitiveFieldCryptoService service = new SensitiveFieldCryptoService("");

        assertThrows(IllegalStateException.class, () -> service.encrypt("张三"));
    }
}
