Chore: Fix issues with conversation data models (#1000)

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-07-04 19:46:17 +05:30
committed by GitHub
parent 36661ea45d
commit 4612494923
15 changed files with 147 additions and 51 deletions

View File

@@ -3,6 +3,7 @@ import actions from '../../conversations/actions';
import * as types from '../../../mutation-types';
const commit = jest.fn();
const dispatch = jest.fn();
global.axios = axios;
jest.mock('axios');
@@ -39,4 +40,91 @@ describe('#actions', () => {
expect(commit.mock.calls).toEqual([]);
});
});
describe('#updateConversation', () => {
it('sends setContact action and update_conversation mutation', () => {
const conversation = {
id: 1,
messages: [],
meta: { sender: { id: 1, name: 'john-doe' } },
};
actions.updateConversation({ commit, dispatch }, conversation);
expect(commit.mock.calls).toEqual([
[types.default.UPDATE_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
'contacts/setContact',
{
id: 1,
name: 'john-doe',
},
],
]);
});
});
describe('#addConversation', () => {
it('doesnot send mutation if conversation is from a different inbox', () => {
const conversation = {
id: 1,
messages: [],
meta: { sender: { id: 1, name: 'john-doe' } },
inbox_id: 2,
};
actions.addConversation(
{ commit, dispatch, state: { currentInbox: 1 } },
conversation
);
expect(commit.mock.calls).toEqual([]);
expect(dispatch.mock.calls).toEqual([]);
});
it('sends correct mutations', () => {
const conversation = {
id: 1,
messages: [],
meta: { sender: { id: 1, name: 'john-doe' } },
inbox_id: 1,
};
actions.addConversation(
{ commit, dispatch, state: { currentInbox: 1 } },
conversation
);
expect(commit.mock.calls).toEqual([
[types.default.ADD_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
'contacts/setContact',
{
id: 1,
name: 'john-doe',
},
],
]);
});
it('sends correct mutations if inbox filter is not available', () => {
const conversation = {
id: 1,
messages: [],
meta: { sender: { id: 1, name: 'john-doe' } },
inbox_id: 1,
};
actions.addConversation({ commit, dispatch, state: {} }, conversation);
expect(commit.mock.calls).toEqual([
[types.default.ADD_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
'contacts/setContact',
{
id: 1,
name: 'john-doe',
},
],
]);
});
});
});