Fixes specs for conversation mutation
This commit is contained in:
parent
f4f75ca394
commit
ae3679b052
|
@ -113,11 +113,4 @@ export const mutations = {
|
|||
id => id !== messageId
|
||||
);
|
||||
},
|
||||
|
||||
setMetaUserLastSeenIn($state, { conversationId, lastSeen }) {
|
||||
const conversationById = $state.conversations.byId[conversationId];
|
||||
if (!conversationById) return;
|
||||
|
||||
Vue.set(conversationById.meta, 'userLastSeenAt', lastSeen);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
import { actions } from '../../conversation/actions';
|
||||
import getUuid from '../../../../helpers/uuid';
|
||||
import { API } from 'widget/helpers/axios';
|
||||
|
||||
jest.mock('../../../../helpers/uuid');
|
||||
jest.mock('widget/helpers/axios');
|
||||
|
||||
const commit = jest.fn();
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#fetchAllConversations', () => {
|
||||
it('sends correct mutations', async () => {
|
||||
API.get.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
messages: [{ id: 12 }],
|
||||
status: 'open',
|
||||
contact_last_seen_at: 12345,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await actions.fetchAllConversations({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['setUIFlag', { isFetching: true }],
|
||||
[
|
||||
'addConversationEntry',
|
||||
{
|
||||
id: 1,
|
||||
messages: [{ id: 12 }],
|
||||
status: 'open',
|
||||
contact_last_seen_at: 12345,
|
||||
},
|
||||
],
|
||||
['addConversationId', 1],
|
||||
['setConversationUIFlag', { uiFlags: {}, conversationId: 1 }],
|
||||
[
|
||||
'setConversationMeta',
|
||||
{
|
||||
meta: { userLastSeenAt: 12345, status: 'open' },
|
||||
conversationId: 1,
|
||||
},
|
||||
],
|
||||
[
|
||||
'message/addMessagesEntry',
|
||||
{ conversationId: 1, messages: [{ id: 12 }] },
|
||||
{ root: true },
|
||||
],
|
||||
[
|
||||
'addMessageIdsToConversation',
|
||||
{ conversationId: 1, messages: [{ id: 12 }] },
|
||||
],
|
||||
['setUIFlag', { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -179,7 +179,7 @@ describe('#mutations', () => {
|
|||
uiFlags: {
|
||||
byId: {
|
||||
1: {
|
||||
allMessagesLoaded: false,
|
||||
allFetched: false,
|
||||
isAgentTyping: false,
|
||||
isFetching: false,
|
||||
},
|
||||
|
@ -192,13 +192,107 @@ describe('#mutations', () => {
|
|||
uiFlags: { isFetching: true },
|
||||
});
|
||||
expect(state.conversations.uiFlags.byId[1]).toEqual({
|
||||
allMessagesLoaded: false,
|
||||
allFetched: false,
|
||||
isAgentTyping: false,
|
||||
isFetching: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setConversationMeta', () => {
|
||||
it('it sets meta data for conversation correctly', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: {},
|
||||
allIds: [],
|
||||
meta: {
|
||||
byId: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
mutations.setConversationMeta(state, {
|
||||
conversationId: 1,
|
||||
meta: { status: 'closed' },
|
||||
});
|
||||
expect(state.conversations.meta.byId[1]).toEqual({
|
||||
userLastSeenAt: undefined,
|
||||
status: 'closed',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#prependMessageIdsToConversation', () => {
|
||||
it('it prepends a list of message ids to existing conversation entry', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: { 120: { id: 120, messages: [1] } },
|
||||
allIds: [120],
|
||||
},
|
||||
messages: { byId: { 1: {} }, allIds: [1] },
|
||||
};
|
||||
const messages = [
|
||||
{ id: 2, content: 'hi' },
|
||||
{ id: 3, content: 'hello' },
|
||||
];
|
||||
mutations.prependMessageIdsToConversation(state, {
|
||||
conversationId: 120,
|
||||
messages,
|
||||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([2, 3, 1]);
|
||||
});
|
||||
it('it does not clear existing messages in a conversation', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: { 120: { id: 120, messages: [2] } },
|
||||
allIds: [120],
|
||||
},
|
||||
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
|
||||
};
|
||||
const messages = [{ id: 3, content: 'hello' }];
|
||||
mutations.prependMessageIdsToConversation(state, {
|
||||
conversationId: 120,
|
||||
messages,
|
||||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([3, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#appendMessageIdsToConversation', () => {
|
||||
it('it prepends a list of message ids to existing conversation entry', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: { 120: { id: 120, messages: [1] } },
|
||||
allIds: [120],
|
||||
},
|
||||
messages: { byId: { 1: {} }, allIds: [1] },
|
||||
};
|
||||
const messages = [
|
||||
{ id: 2, content: 'hi' },
|
||||
{ id: 3, content: 'hello' },
|
||||
];
|
||||
mutations.appendMessageIdsToConversation(state, {
|
||||
conversationId: 120,
|
||||
messages,
|
||||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([1, 2, 3]);
|
||||
});
|
||||
it('it does not clear existing messages in a conversation', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: { 120: { id: 120, messages: [2] } },
|
||||
allIds: [120],
|
||||
},
|
||||
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
|
||||
};
|
||||
const messages = [{ id: 3, content: 'hello' }];
|
||||
mutations.appendMessageIdsToConversation(state, {
|
||||
conversationId: 120,
|
||||
messages,
|
||||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([2, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addMessageIdsToConversation', () => {
|
||||
it('it adds a list of message ids to existing conversation entry', () => {
|
||||
const state = {
|
||||
|
@ -218,7 +312,7 @@ describe('#mutations', () => {
|
|||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([2, 3]);
|
||||
});
|
||||
it('it does not clear existing messages in a conversation', () => {
|
||||
it('it does clear existing messages in a conversation', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
byId: { 120: { id: 120, messages: [2] } },
|
||||
|
@ -231,7 +325,7 @@ describe('#mutations', () => {
|
|||
conversationId: 120,
|
||||
messages,
|
||||
});
|
||||
expect(state.conversations.byId[120].messages).toEqual([2, 3]);
|
||||
expect(state.conversations.byId[120].messages).toEqual([3]);
|
||||
});
|
||||
it('it does not add messages if conversation is not present in store', () => {
|
||||
const state = {
|
Loading…
Reference in a new issue