fix: hydrate realtime conversations before rendering
Build and publish Docker images / Build and publish images (push) Successful in 3m16s
Build and publish Docker images / Build and publish images (push) Successful in 3m16s
This commit is contained in:
@@ -70,6 +70,31 @@ describe('#actions', () => {
|
||||
['contacts/SET_CONTACT_ITEM', { id: 1, name: 'Contact 1' }],
|
||||
]);
|
||||
});
|
||||
it('hydrates messages returned with the conversation', async () => {
|
||||
const messages = [{ id: 2, conversation_id: 1, content: 'hello' }];
|
||||
axios.get.mockResolvedValue({
|
||||
data: {
|
||||
id: 1,
|
||||
messages,
|
||||
meta: { sender: { id: 1, name: 'Contact 1' } },
|
||||
},
|
||||
});
|
||||
|
||||
await actions.getConversation({ commit }, 1);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.UPDATE_CONVERSATION,
|
||||
{
|
||||
id: 1,
|
||||
messages,
|
||||
meta: { sender: { id: 1, name: 'Contact 1' } },
|
||||
},
|
||||
],
|
||||
[types.SET_MISSING_MESSAGES, { id: 1, data: messages }],
|
||||
['contacts/SET_CONTACT_ITEM', { id: 1, name: 'Contact 1' }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.getConversation({ commit });
|
||||
@@ -957,6 +982,20 @@ describe('#addMentions', () => {
|
||||
expect(localDispatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('hydrates a realtime conversation when its event has no messages', async () => {
|
||||
const localCommit = vi.fn();
|
||||
const localDispatch = vi.fn().mockResolvedValue({ id: 42 });
|
||||
const data = { id: 42, messages: [] };
|
||||
|
||||
await actions.setActiveChat(
|
||||
{ commit: localCommit, dispatch: localDispatch },
|
||||
{ data }
|
||||
);
|
||||
|
||||
expect(localDispatch).toHaveBeenCalledWith('getConversation', 42);
|
||||
expect(localCommit).toHaveBeenCalledWith(types.SET_CHAT_DATA_FETCHED, 42);
|
||||
});
|
||||
|
||||
it('should commit SET_CHAT_DATA_FETCHED by ID, not mutate the data object directly (race condition fix)', async () => {
|
||||
const localCommit = vi.fn();
|
||||
const localDispatch = vi.fn().mockResolvedValue();
|
||||
|
||||
Reference in New Issue
Block a user