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:
Muhsin Keloth
2021-06-15 20:09:42 +05:30
committed by GitHub
co-authored by Pranav Raj S
parent 853db60f8e
commit fb2f3ff89f
14 changed files with 211 additions and 18 deletions
@@ -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]]);
});
});
});