diff --git a/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js index 5da91d6dc..001c3c84d 100644 --- a/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js +++ b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js @@ -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', diff --git a/jam-ui/src/store/features/sessionChatSlice.js b/jam-ui/src/store/features/sessionChatSlice.js index 6e9e2a40c..cfc6d911a 100644 --- a/jam-ui/src/store/features/sessionChatSlice.js +++ b/jam-ui/src/store/features/sessionChatSlice.js @@ -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]) {