package org.dromara.web.service;

import org.dromara.common.core.domain.model.ForgotLoginBody;
import org.dromara.system.service.ISysUserService;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
@Tag("dev")
class ForgotPasswordServiceTest {

    @Mock
    private ISysUserService userService;
    @InjectMocks
    private ForgotPasswordService forgotPasswordService;

    @Test
    void forgotPasswordService_delegatesVerificationAndResetToUserService() {
        ForgotLoginBody body = new ForgotLoginBody();
        body.setUsername("alice");
        body.setSmsCode("123456");
        body.setPassword("newPassword");
        when(userService.resetPasswordByVerificationCode("alice", "123456", "newPassword"))
            .thenReturn(true);

        boolean result = forgotPasswordService.forgotPasswordService(body);

        assertThat(result).isTrue();
        verify(userService).resetPasswordByVerificationCode("alice", "123456", "newPassword");
    }
}
