chore: Enhance contact merge action for identified users (#4886)
- Discard conflicting keys - Do not merge if there is already an identified contact Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
import { API } from 'widget/helpers/axios';
|
||||
import { sendMessage } from 'widget/helpers/utils';
|
||||
import { actions } from '../../contacts';
|
||||
|
||||
const commit = jest.fn();
|
||||
const dispatch = jest.fn();
|
||||
jest.mock('widget/helpers/axios');
|
||||
jest.mock('widget/helpers/utils', () => ({
|
||||
sendMessage: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#update', () => {
|
||||
it('sends correct actions', async () => {
|
||||
describe('#setUser', () => {
|
||||
it('sends correct actions if contact object is refreshed ', async () => {
|
||||
const user = {
|
||||
email: 'thoma@sphadikam.com',
|
||||
name: 'Adu Thoma',
|
||||
avatar_url: '',
|
||||
identifier_hash: 'random_hex_identifier_hash',
|
||||
};
|
||||
API.patch.mockResolvedValue({ data: { pubsub_token: 'token' } });
|
||||
await actions.update({ commit, dispatch }, { identifier: 1, user });
|
||||
API.patch.mockResolvedValue({ data: { widget_auth_token: 'token' } });
|
||||
await actions.setUser({ commit, dispatch }, { identifier: 1, user });
|
||||
expect(sendMessage.mock.calls).toEqual([
|
||||
[{ data: { widgetAuthToken: 'token' }, event: 'setAuthCookie' }],
|
||||
]);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
['get'],
|
||||
@@ -24,5 +29,52 @@ describe('#actions', () => {
|
||||
['conversationAttributes/getAttributes', {}, { root: true }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if identifierHash is passed ', async () => {
|
||||
const user = {
|
||||
email: 'thoma@sphadikam.com',
|
||||
name: 'Adu Thoma',
|
||||
avatar_url: '',
|
||||
identifier_hash: '12345',
|
||||
};
|
||||
API.patch.mockResolvedValue({ data: { id: 1 } });
|
||||
await actions.setUser({ commit, dispatch }, { identifier: 1, user });
|
||||
expect(sendMessage.mock.calls).toEqual([]);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
['get'],
|
||||
['conversation/clearConversations', {}, { root: true }],
|
||||
['conversation/fetchOldConversations', {}, { root: true }],
|
||||
['conversationAttributes/getAttributes', {}, { root: true }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not call sendMessage if contact object is not refreshed ', async () => {
|
||||
const user = {
|
||||
email: 'thoma@sphadikam.com',
|
||||
name: 'Adu Thoma',
|
||||
avatar_url: '',
|
||||
};
|
||||
API.patch.mockResolvedValue({ data: { id: 1 } });
|
||||
await actions.setUser({ commit, dispatch }, { identifier: 1, user });
|
||||
expect(sendMessage.mock.calls).toEqual([]);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([['get']]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions', async () => {
|
||||
const user = {
|
||||
email: 'thoma@sphadikam.com',
|
||||
name: 'Adu Thoma',
|
||||
avatar_url: '',
|
||||
identifier_hash: 'random_hex_identifier_hash',
|
||||
};
|
||||
API.patch.mockResolvedValue({ data: { id: 1 } });
|
||||
await actions.update({ commit, dispatch }, { identifier: 1, user });
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([['get']]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user