package org.dromara.chat.service;

import org.dromara.chat.domain.ChatSession;
import org.dromara.chat.domain.bo.ChatSessionBo;
import org.dromara.chat.mapper.ChatSessionMapper;
import org.dromara.chat.service.impl.ChatSessionServiceImpl;
import org.junit.jupiter.api.Assertions;
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.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

/**
 * ChatSessionService单元测试
 */
@ExtendWith(MockitoExtension.class)
public class ChatSessionServiceTest {

    @Mock
    private ChatSessionMapper chatSessionMapper;

    @InjectMocks
    private ChatSessionServiceImpl chatSessionService;

    @BeforeEach
    public void setUp() {
    }

    @Test
    public void testInsertByBo() {
        ChatSessionBo bo = new ChatSessionBo();
        bo.setUserId(1L);
        bo.setSessionTitle("Test Session");

        Mockito.when(chatSessionMapper.insert(Mockito.any(ChatSession.class))).thenReturn(1);

        Boolean result = chatSessionService.insertByBo(bo);
        Assertions.assertTrue(result);
        Mockito.verify(chatSessionMapper).insert(Mockito.any(ChatSession.class));
    }

    @Test
    public void testUpdateSessionTitle() {
        Long sessionId = 1L;
        String newTitle = "Updated Title";

        Mockito.when(chatSessionMapper.updateById(Mockito.any(ChatSession.class))).thenReturn(1);

        Boolean result = chatSessionService.updateSessionTitle(sessionId, newTitle);
        Assertions.assertTrue(result);
        Mockito.verify(chatSessionMapper).updateById(Mockito.any(ChatSession.class));
    }
}
