I have the following in my controller which works. But when I die and dump the $response in the test in this case. It doesn't have the messages. Seems like the session id does not match.
public function index()
{
$conversationHistory = ChatbotMessage::select(['content', 'role'])
->where('session_id', session()
->getId())
->get();
return view('chatbot-messages.index', compact('conversationHistory'));
}
/** @test */
public function chatbot_messages_page_has_non_empty_chat()
{
// Start the session.
$this->startSession();
// Get the session ID.
$sessionId = session()->getId();
// Ensure that the session ID is not empty.
$this->assertNotEmpty($sessionId);
// Create chatbot messages.
ChatbotMessage::create([
'session_id' => $sessionId,
'content' => 'Hello',
'role' => 'You'
]);
ChatbotMessage::create([
'session_id' => $sessionId,
'content' => 'Hi there',
'role' => 'Bot'
]);
$response = $this->get(route('chatbot-messages.index'));
// You can add assertions here to ensure that the response contains the expected data.
$response->assertSee('Hello');
$response->assertSee('Hi there');
}