fix(15): correct API response field name (chats not messages)
The chat history API returns { chats: [...], next: ... } but the
fetchChatHistory.fulfilled handler was expecting { messages: [...] }.
This caused a TypeError when opening the chat window because
`messages` was undefined.
Fixed:
- sessionChatSlice.js: Extract `chats` from payload, default to []
- Updated all test payloads to use `chats` field name
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
bfee9acdfb
commit
da4e864ab7
|
|
@ -537,7 +537,7 @@ describe('fetchChatHistory async thunk', () => {
|
|||
meta: { arg: { channel: 'session-abc' } },
|
||||
payload: {
|
||||
channel: 'session-abc',
|
||||
messages: [
|
||||
chats: [
|
||||
{ id: 'msg-1', message: 'Hello', sender_id: 'user-1', created_at: '2026-01-26T12:00:00Z' }
|
||||
],
|
||||
next: 20
|
||||
|
|
@ -576,7 +576,7 @@ describe('fetchChatHistory async thunk', () => {
|
|||
meta: { arg: { channel: 'session-abc' } },
|
||||
payload: {
|
||||
channel: 'session-abc',
|
||||
messages: [
|
||||
chats: [
|
||||
{ id: 'msg-1', user_id: 'user-1', user: { name: 'User' }, message: 'Hello', created_at: '2026-01-26T12:00:00Z', channel: 'session' }, // Duplicate
|
||||
{ id: 'msg-2', user_id: 'user-2', user: { name: 'User2' }, message: 'World', created_at: '2026-01-26T12:01:00Z', channel: 'session' } // New
|
||||
],
|
||||
|
|
@ -609,7 +609,7 @@ describe('fetchChatHistory async thunk', () => {
|
|||
meta: { arg: { channel: 'session-abc', before: 3 } },
|
||||
payload: {
|
||||
channel: 'session-abc',
|
||||
messages: [
|
||||
chats: [
|
||||
{ id: 'msg-1', message: 'Oldest', createdAt: '2026-01-26T12:00:00Z' },
|
||||
{ id: 'msg-2', message: 'Middle', createdAt: '2026-01-26T12:01:00Z' }
|
||||
],
|
||||
|
|
@ -648,7 +648,7 @@ describe('fetchChatHistory async thunk', () => {
|
|||
meta: { arg: { channel: 'session-abc' } },
|
||||
payload: {
|
||||
channel: 'session-abc',
|
||||
messages: [
|
||||
chats: [
|
||||
{ id: 'msg-1', message: 'Hello', createdAt: '2026-01-26T12:00:00Z' }
|
||||
],
|
||||
next: null
|
||||
|
|
@ -674,7 +674,7 @@ describe('fetchChatHistory async thunk', () => {
|
|||
meta: { arg: { channel: 'session-abc' } },
|
||||
payload: {
|
||||
channel: 'session-abc',
|
||||
messages: [
|
||||
chats: [
|
||||
{
|
||||
id: 'msg-1',
|
||||
user_id: 'user-1',
|
||||
|
|
|
|||
|
|
@ -306,7 +306,9 @@ const sessionChatSlice = createSlice({
|
|||
// fetchChatHistory fulfilled
|
||||
.addCase(fetchChatHistory.fulfilled, (state, action) => {
|
||||
const channel = action.meta.arg.channel;
|
||||
const { messages, next } = action.payload;
|
||||
// API returns { chats: [...], next: ... }
|
||||
const { chats, next } = action.payload;
|
||||
const messages = chats || [];
|
||||
|
||||
// Initialize channel if not exists
|
||||
if (!state.messagesByChannel[channel]) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue