feat: Create campaign conversation only if user interacts with the bubble (#2335)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -39,14 +39,14 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#startCampaigns', () => {
|
||||
describe('#initCampaigns', () => {
|
||||
const actionParams = {
|
||||
websiteToken: 'XDsafmADasd',
|
||||
currentURL: 'https://chatwoot.com',
|
||||
};
|
||||
|
||||
it('sends correct actions if campaigns are empty', async () => {
|
||||
await actions.startCampaigns(
|
||||
await actions.initCampaigns(
|
||||
{ dispatch, getters: { getCampaigns: [] } },
|
||||
actionParams
|
||||
);
|
||||
@@ -54,7 +54,7 @@ describe('#actions', () => {
|
||||
expect(campaignTimer.initTimers).not.toHaveBeenCalled();
|
||||
});
|
||||
it('resets time if campaigns are available', async () => {
|
||||
await actions.startCampaigns(
|
||||
await actions.initCampaigns(
|
||||
{ dispatch, getters: { getCampaigns: campaigns } },
|
||||
actionParams
|
||||
);
|
||||
@@ -64,4 +64,34 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('#startCampaign', () => {
|
||||
it('reset campaign if campaign id is not present in the campaign list', async () => {
|
||||
await actions.startCampaign(
|
||||
{ dispatch, getters: { getCampaigns: campaigns }, commit },
|
||||
{ campaignId: 32 }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([['setActiveCampaign', undefined]]);
|
||||
});
|
||||
it('start campaign if campaign id passed', async () => {
|
||||
await actions.startCampaign(
|
||||
{ dispatch, getters: { getCampaigns: campaigns }, commit },
|
||||
{ campaignId: 1 }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([['setActiveCampaign', campaigns[0]]]);
|
||||
});
|
||||
});
|
||||
describe('#executeCampaign', () => {
|
||||
it('sends correct actions if execute campaign API is success', async () => {
|
||||
const params = { campaignId: 12, websiteToken: 'XDsafmADasd' };
|
||||
API.post.mockResolvedValue({});
|
||||
await actions.executeCampaign({ commit }, params);
|
||||
expect(commit.mock.calls).toEqual([['setActiveCampaign', {}]]);
|
||||
});
|
||||
it('sends correct actions if execute campaign API is failed', async () => {
|
||||
const params = { campaignId: 12, websiteToken: 'XDsafmADasd' };
|
||||
API.post.mockRejectedValue({ message: 'Authentication required' });
|
||||
await actions.executeCampaign({ commit }, params);
|
||||
expect(commit.mock.calls).toEqual([['setError', true]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getters } from '../../campaign';
|
||||
import { campaigns } from './data';
|
||||
jest.mock('widget/store/index.js');
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getCampaigns', () => {
|
||||
@@ -93,4 +94,39 @@ describe('#getters', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('getActiveCampaign', () => {
|
||||
const state = {
|
||||
records: campaigns[0],
|
||||
};
|
||||
expect(getters.getCampaigns(state)).toEqual({
|
||||
id: 1,
|
||||
title: 'Welcome',
|
||||
description: null,
|
||||
account_id: 1,
|
||||
inbox: {
|
||||
id: 37,
|
||||
channel_id: 1,
|
||||
name: 'Chatwoot',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
},
|
||||
sender: {
|
||||
account_id: 1,
|
||||
availability_status: 'offline',
|
||||
confirmed: true,
|
||||
email: 'sojan@chatwoot.com',
|
||||
available_name: 'Sojan',
|
||||
id: 10,
|
||||
name: 'Sojan',
|
||||
},
|
||||
message: 'Hey, What brings you today',
|
||||
enabled: true,
|
||||
trigger_rules: {
|
||||
url: 'https://github.com',
|
||||
time_on_page: 10,
|
||||
},
|
||||
created_at: '2021-05-03T04:53:36.354Z',
|
||||
updated_at: '2021-05-03T04:53:36.354Z',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { mutations } from '../../campaign';
|
||||
import { campaigns } from './data';
|
||||
|
||||
jest.mock('widget/store/index.js');
|
||||
describe('#mutations', () => {
|
||||
describe('#setCampaigns', () => {
|
||||
it('set campaign records', () => {
|
||||
@@ -25,4 +25,12 @@ describe('#mutations', () => {
|
||||
expect(state.uiFlags.hasFetched).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setActiveCampaign', () => {
|
||||
it('set active campaign', () => {
|
||||
const state = { records: [] };
|
||||
mutations.setActiveCampaign(state, campaigns[0]);
|
||||
expect(state.activeCampaign).toEqual(campaigns[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -434,4 +434,15 @@ describe('#getters', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('getMessageCount', () => {
|
||||
const state = {
|
||||
conversations: {
|
||||
1: {
|
||||
content: 'hey, how are you?',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(getters.getMessageCount(state)).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user