package za.co.rootbranch.coffeechat;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
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 za.co.rootbranch.coffeechat.models.User;
import za.co.rootbranch.coffeechat.repositories.UserRepository;
import za.co.rootbranch.coffeechat.services.UserService;

@ExtendWith(MockitoExtension.class)
public class CreateUserTest {

    @Mock
    private UserRepository userRepository;

    @InjectMocks
    private UserService userService;

    @BeforeEach()
    void init() {
        // do setup
    }

    @Test
    void TestCreateANewUser() {
        // Mock the behavior of the repository
        String email = "test@example.com";
        User mockUser = new User(null,"", "", email);
        when(userRepository.findByEmail(email)).thenReturn(mockUser); // Stub the method call

        // Call the service method
        User foundUser = userService.findUserByEmail(email);

        // Verify the result using JUnit assertions
        assertEquals(email, foundUser.getEmail());
    }
}
