package com.ruoyi.framework.web.service.sms;

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

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.framework.config.properties.SmsProperties;
import com.ruoyi.framework.config.properties.SmsProperties.Aliyun;

@ExtendWith(MockitoExtension.class)
@DisplayName("AliyunSmsGatewayClient")
class AliyunSmsGatewayClientTest
{
    @InjectMocks
    private AliyunSmsGatewayClient gatewayClient;

    @Spy
    private SmsProperties smsProperties = new SmsProperties();

    @Test
    @DisplayName("dry-run 模式走日志 Stub 并返回成功")
    void dryRunReturnsTrueWithoutRemoteCall()
    {
        Aliyun aliyun = smsProperties.getAliyun();
        aliyun.setDryRun(true);
        aliyun.setAccessKeyId("");
        assertTrue(gatewayClient.sendLoginCode("13800001111", "123456"));
    }

    @Test
    @DisplayName("未配置密钥时自动降级为日志 Stub")
    void missingCredentialsUsesLogStub()
    {
        Aliyun aliyun = smsProperties.getAliyun();
        aliyun.setDryRun(false);
        aliyun.setAccessKeyId("");
        aliyun.setAccessKeySecret("");
        assertTrue(gatewayClient.sendLoginCode("13800001111", "654321"));
    }
}
