818c769bb7
* Changes for the message to have multiple attachments * changed the message association to attachments from has_one to has_many * changed all the references of this association in building and fetching to reflect this change * Added number of attachments validation to the message model * Modified the backend responses and endpoints to reflect multiple attachment support (#737) * Changing the frontend components for multiple attachments * changed the request structure to reflect the multiple attachment structures * changed the message bubbles to support multiple attachments * bugfix: agent side attachment was not showing because of a missing await * broken message was shown because of the store filtering * Added documentation for ImageMagick * spec fixes * refactored code to reflect more apt namings * Added updated message listener for the dashboard (#727) * Added the publishing for message updated event * Implemented the listener for dashboard Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
145 lines
3.8 KiB
JavaScript
145 lines
3.8 KiB
JavaScript
import { mutations } from '../../conversation';
|
|
|
|
const temporaryMessagePayload = {
|
|
content: 'hello',
|
|
id: 1,
|
|
message_type: 0,
|
|
status: 'in_progress',
|
|
};
|
|
|
|
const incomingMessagePayload = {
|
|
content: 'hello',
|
|
id: 1,
|
|
message_type: 0,
|
|
status: 'sent',
|
|
};
|
|
|
|
const outgoingMessagePayload = {
|
|
content: 'hello',
|
|
id: 1,
|
|
message_type: 1,
|
|
status: 'sent',
|
|
};
|
|
|
|
describe('#mutations', () => {
|
|
describe('#pushMessageToConversation', () => {
|
|
it('add message to conversation if outgoing', () => {
|
|
const state = { conversations: {} };
|
|
mutations.pushMessageToConversation(state, outgoingMessagePayload);
|
|
expect(state.conversations).toEqual({
|
|
1: outgoingMessagePayload,
|
|
});
|
|
});
|
|
|
|
it('add message to conversation if message in undelivered', () => {
|
|
const state = { conversations: {} };
|
|
mutations.pushMessageToConversation(state, temporaryMessagePayload);
|
|
expect(state.conversations).toEqual({
|
|
1: temporaryMessagePayload,
|
|
});
|
|
});
|
|
|
|
it('replaces temporary message in conversation with actual message', () => {
|
|
const state = {
|
|
conversations: {
|
|
rand_id_123: {
|
|
content: 'hello',
|
|
id: 'rand_id_123',
|
|
message_type: 0,
|
|
status: 'in_progress',
|
|
},
|
|
},
|
|
};
|
|
mutations.pushMessageToConversation(state, incomingMessagePayload);
|
|
expect(state.conversations).toEqual({
|
|
1: incomingMessagePayload,
|
|
});
|
|
});
|
|
|
|
it('adds message in conversation if it is a new message', () => {
|
|
const state = { conversations: {} };
|
|
mutations.pushMessageToConversation(state, incomingMessagePayload);
|
|
expect(state.conversations).toEqual({
|
|
1: incomingMessagePayload,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#setConversationListLoading', () => {
|
|
it('set status correctly', () => {
|
|
const state = { uiFlags: { isFetchingList: false } };
|
|
mutations.setConversationListLoading(state, true);
|
|
expect(state.uiFlags.isFetchingList).toEqual(true);
|
|
});
|
|
});
|
|
|
|
describe('#setMessagesInConversation', () => {
|
|
it('sets allMessagesLoaded flag if payload is empty', () => {
|
|
const state = { uiFlags: { allMessagesLoaded: false } };
|
|
mutations.setMessagesInConversation(state, []);
|
|
expect(state.uiFlags.allMessagesLoaded).toEqual(true);
|
|
});
|
|
|
|
it('sets messages if payload is not empty', () => {
|
|
const state = {
|
|
uiFlags: { allMessagesLoaded: false },
|
|
conversations: {},
|
|
};
|
|
mutations.setMessagesInConversation(state, [{ id: 1, content: 'hello' }]);
|
|
expect(state.conversations).toEqual({
|
|
1: { id: 1, content: 'hello' },
|
|
});
|
|
expect(state.uiFlags.allMessagesLoaded).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe('#updateAttachmentMessageStatus', () => {
|
|
it('Updates status of loading messages if payload is not empty', () => {
|
|
const state = {
|
|
conversations: {
|
|
rand_id_123: {
|
|
content: '',
|
|
id: 'rand_id_123',
|
|
message_type: 0,
|
|
status: 'in_progress',
|
|
attachment: {
|
|
file: '',
|
|
file_type: 'image',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
const message = {
|
|
id: '1',
|
|
content: '',
|
|
status: 'sent',
|
|
message_type: 0,
|
|
attachments: [
|
|
{
|
|
file: '',
|
|
file_type: 'image',
|
|
},
|
|
],
|
|
};
|
|
mutations.updateAttachmentMessageStatus(state, {
|
|
message,
|
|
tempId: 'rand_id_123',
|
|
});
|
|
|
|
expect(state.conversations).toEqual({
|
|
1: {
|
|
id: '1',
|
|
content: '',
|
|
message_type: 0,
|
|
status: 'sent',
|
|
attachments: [
|
|
{
|
|
file: '',
|
|
file_type: 'image',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
});
|
|
});
|