fix: hydrate realtime conversations before rendering
Build and publish Docker images / Build and publish images (push) Successful in 3m16s

This commit is contained in:
2026-09-14 21:39:56 +08:00
parent 9b8d575657
commit 5a0e9ecada
4 changed files with 149 additions and 10 deletions
@@ -102,6 +102,62 @@ describe('ActionCableConnector - Copilot Tests', () => {
});
});
it('handles native assignment events and refreshes authoritative conversation data', async () => {
expect(actionCable.events['conversation.assigned']).toBe(
actionCable.onConversationAssigned
);
expect(actionCable.events['conversation.unassigned']).toBe(
actionCable.onConversationAssigned
);
actionCable.onReceived({
event: 'conversation.assigned',
data: { account_id: 1, id: 42 },
});
expect(mockDispatch).toHaveBeenCalledWith('getConversation', 42);
});
it('hydrates a message whose realtime event arrives before conversation creation', async () => {
const message = {
id: 42,
account_id: 1,
conversation_id: 7,
conversation: { last_activity_at: 123 },
};
mockDispatch.mockImplementation(action => {
if (action === 'addMessage') return Promise.resolve(false);
if (action === 'getConversation') {
return Promise.resolve({ id: 7, messages: [message] });
}
return undefined;
});
await actionCable.onMessageCreated(message);
expect(mockDispatch).toHaveBeenCalledWith('getConversation', 7);
expect(DashboardAudioNotificationHelper.onNewMessage).toHaveBeenCalledWith(
message
);
});
it('hydrates a conversation-created event that has no embedded messages', async () => {
mockDispatch.mockImplementation(action => {
if (action === 'addConversation') return Promise.resolve(true);
if (action === 'getConversation') return Promise.resolve({ id: 7 });
return undefined;
});
await actionCable.onConversationCreated({
id: 7,
inbox_id: 1,
messages: [],
meta: { sender: {} },
});
expect(mockDispatch).toHaveBeenCalledWith('getConversation', 7);
});
it('plays new message audio only once when realtime replays a message', async () => {
const message = {
id: 42,