791d90c6b7
At present, the websocket pubsub tokens are present at the contact objects in chatwoot. A better approach would be to have these tokens at the contact_inbox object instead. This helps chatwoot to deliver the websocket events targetted to the specific widget connection, stop contact events from leaking into other chat sessions from the same contact. Fixes #1682 Fixes #1664 Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
119 lines
3.4 KiB
JavaScript
119 lines
3.4 KiB
JavaScript
import {
|
|
stripTrailingSlash,
|
|
formatCampaigns,
|
|
filterCampaigns,
|
|
} from '../campaignHelper';
|
|
import campaigns from './campaignFixtures';
|
|
|
|
global.chatwootWebChannel = {
|
|
workingHoursEnabled: false,
|
|
};
|
|
describe('#Campaigns Helper', () => {
|
|
describe('stripTrailingSlash', () => {
|
|
it('should return striped trailing slash if url with trailing slash is passed', () => {
|
|
expect(
|
|
stripTrailingSlash({ URL: 'https://www.chatwoot.com/pricing/' })
|
|
).toBe('https://www.chatwoot.com/pricing');
|
|
});
|
|
});
|
|
|
|
describe('formatCampaigns', () => {
|
|
it('should return formatted campaigns if campaigns are passed', () => {
|
|
expect(formatCampaigns({ campaigns })).toStrictEqual([
|
|
{
|
|
id: 1,
|
|
timeOnPage: 3,
|
|
triggerOnlyDuringBusinessHours: false,
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
},
|
|
{
|
|
id: 2,
|
|
triggerOnlyDuringBusinessHours: false,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
describe('filterCampaigns', () => {
|
|
it('should return filtered campaigns if formatted campaigns are passed', () => {
|
|
expect(
|
|
filterCampaigns({
|
|
campaigns: [
|
|
{
|
|
id: 1,
|
|
timeOnPage: 3,
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
triggerOnlyDuringBusinessHours: false,
|
|
},
|
|
{
|
|
id: 2,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
triggerOnlyDuringBusinessHours: false,
|
|
},
|
|
],
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
})
|
|
).toStrictEqual([
|
|
{
|
|
id: 2,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
triggerOnlyDuringBusinessHours: false,
|
|
},
|
|
]);
|
|
});
|
|
it('should return filtered campaigns if formatted campaigns are passed and business hours enabled', () => {
|
|
expect(
|
|
filterCampaigns({
|
|
campaigns: [
|
|
{
|
|
id: 1,
|
|
timeOnPage: 3,
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
triggerOnlyDuringBusinessHours: false,
|
|
},
|
|
{
|
|
id: 2,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
triggerOnlyDuringBusinessHours: true,
|
|
},
|
|
],
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
isInBusinessHours: true,
|
|
})
|
|
).toStrictEqual([
|
|
{
|
|
id: 2,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
triggerOnlyDuringBusinessHours: true,
|
|
},
|
|
]);
|
|
});
|
|
it('should return empty campaigns if formatted campaigns are passed and business hours disabled', () => {
|
|
expect(
|
|
filterCampaigns({
|
|
campaigns: [
|
|
{
|
|
id: 1,
|
|
timeOnPage: 3,
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
triggerOnlyDuringBusinessHours: true,
|
|
},
|
|
{
|
|
id: 2,
|
|
timeOnPage: 6,
|
|
url: 'https://www.chatwoot.com/about',
|
|
triggerOnlyDuringBusinessHours: true,
|
|
},
|
|
],
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
isInBusinessHours: false,
|
|
})
|
|
).toStrictEqual([]);
|
|
});
|
|
});
|
|
});
|