Skip to content
Snippets Groups Projects
Unverified Commit 6f9624b5 authored by Aleksander Nicacio da Silva's avatar Aleksander Nicacio da Silva Committed by GitHub
Browse files

regression: triggers being scheduled when user is already registered (#31999)

parent 5484c411
No related branches found
No related tags found
No related merge requests found
import { faker } from '@faker-js/faker';
import type { Page } from '@playwright/test';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { OmnichannelLiveChat, HomeOmnichannel } from '../page-objects';
import { test, expect } from '../utils/test';
test.use({ storageState: Users.admin.state });
test.describe('OC - Livechat Triggers - Open by Visitor', () => {
let poLiveChat: OmnichannelLiveChat;
let newUser: { email: string; name: string };
let agent: { page: Page; poHomeOmnichannel: HomeOmnichannel };
test.beforeAll(async ({ api, browser }) => {
newUser = {
name: faker.person.firstName(),
email: faker.internet.email(),
};
const requests = await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }),
api.post('/livechat/users/manager', { username: 'user1' }),
api.post(
'/livechat/triggers',
{
name: 'open',
description: '',
enabled: true,
runOnce: false,
conditions: [
{
name: 'chat-opened-by-visitor',
value: '',
},
],
actions: [
{
name: 'send-message',
params: {
name: '',
msg: 'This is a trigger message open by visitor',
sender: 'queue',
},
},
],
},
),
]);
requests.every((e) => expect(e.status()).toBe(200));
const { page } = await createAuxContext(browser, Users.user1, '/');
agent = { page, poHomeOmnichannel: new HomeOmnichannel(page) };
});
test.beforeEach(async ({ page, api }) => {
poLiveChat = new OmnichannelLiveChat(page, api);
await page.goto('/livechat');
});
test.afterAll(async ({ api }) => {
const ids = (await (await api.get('/livechat/triggers')).json()).triggers.map(
(trigger: { _id: string }) => trigger._id,
) as unknown as string[];
await Promise.all(ids.map((id) => api.delete(`/livechat/triggers/${id}`)));
await Promise.all([
api.delete('/livechat/users/agent/user1'),
api.delete('/livechat/users/manager/user1'),
api.post('/settings/Livechat_clear_local_storage_when_chat_ended', { value: false }),
]);
await agent.page.close();
});
test('OC - Livechat Triggers - after the visitor opens the chat the trigger message should not be visible neither after a page reload', async () => {
await poLiveChat.openLiveChat();
await expect(poLiveChat.txtChatMessage('This is a trigger message open by visitor')).toBeVisible();
await poLiveChat.btnChatNow.click();
await poLiveChat.sendMessage(newUser, false);
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor')).toBeVisible();
await poLiveChat.page.reload();
// if the request took too long, the loadMessage cleans triggers, but if the fetch is fast enough, the trigger message will be visible
await poLiveChat.page.waitForRequest(/livechat\/messages.history/);
await poLiveChat.openLiveChat();
await expect(poLiveChat.txtChatMessage('This is a trigger message open by visitor')).not.toBeVisible();
await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor')).toBeVisible();
});
});
import { faker } from '@faker-js/faker';
import type { Page } from '@playwright/test';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { OmnichannelLiveChat, HomeOmnichannel } from '../page-objects';
import { test, expect } from '../utils/test';
test.use({ storageState: Users.admin.state });
test.describe('OC - Livechat Triggers - Time on site', () => {
let poLiveChat: OmnichannelLiveChat;
let newUser: { email: string; name: string };
let agent: { page: Page; poHomeOmnichannel: HomeOmnichannel };
test.beforeAll(async ({ api, browser }) => {
newUser = {
name: faker.person.firstName(),
email: faker.internet.email(),
};
const requests = await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }),
api.post('/livechat/users/manager', { username: 'user1' }),
api.post(
'/livechat/triggers',
{
enabled: true,
runOnce: false,
conditions: [{ name: 'time-on-site', value: '1' }],
actions: [{ name: 'send-message', params: { name: '', msg: 'This is a trigger message time on site', sender: 'queue' } }],
name: 'test',
description: 'test',
},
),
]);
requests.every((e) => expect(e.status()).toBe(200));
const { page } = await createAuxContext(browser, Users.user1, '/');
agent = { page, poHomeOmnichannel: new HomeOmnichannel(page) };
});
test.beforeEach(async ({ page, api }) => {
poLiveChat = new OmnichannelLiveChat(page, api);
await page.goto('/livechat');
});
test.afterAll(async ({ api }) => {
const ids = (await (await api.get('/livechat/triggers')).json()).triggers.map(
(trigger: { _id: string }) => trigger._id,
) as unknown as string[];
await Promise.all(ids.map((id) => api.delete(`/livechat/triggers/${id}`)));
await Promise.all([
api.delete('/livechat/users/agent/user1'),
api.delete('/livechat/users/manager/user1'),
api.post('/settings/Livechat_clear_local_storage_when_chat_ended', { value: false }),
]);
await agent.page.close();
});
test('expect to receive trigger message after 1 second', async () => {
await expect(poLiveChat.page.locator('role=button[name="Close"]')).toBeVisible();
await expect(poLiveChat.page.locator('role=main')).toContainText('This is a trigger message time on site');
await expect(poLiveChat.page.locator('role=button[name="Start chat"]')).toBeVisible();
await expect(poLiveChat.page.locator('role=button[name="Messages"]')).toBeVisible();
});
test('OC - Livechat Triggers - after the visitor opens the chat the trigger time-on-site should not be triggered after reload', async () => {
await expect(poLiveChat.page.locator('role=button[name="Close"]')).toBeVisible();
await expect(poLiveChat.page.locator('role=main')).toContainText('This is a trigger message time on site');
await expect(poLiveChat.page.locator('role=button[name="Start chat"]')).toBeVisible();
await expect(poLiveChat.page.locator('role=button[name="Messages"]')).toBeVisible();
await poLiveChat.btnOpenOnlineLiveChat('Start chat').click();
await poLiveChat.btnOpenOnlineLiveChat('Chat now').click();
await poLiveChat.sendMessage(newUser, false);
await test.step('expect to not have any trigger message after registration', async () => {
await expect(poLiveChat.txtChatMessage('This is a trigger message time on site')).not.toBeVisible();
});
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.page.locator('role=main')).toContainText('Chat started');
await poLiveChat.page.reload();
await poLiveChat.btnOpenOnlineLiveChat('Rocket.Chat').click();
await expect(poLiveChat.page.locator('role=main')).toContainText('Chat started');
await poLiveChat.page.waitForTimeout(1000);
await expect(poLiveChat.txtChatMessage('This is a trigger message time on site')).not.toBeVisible();
});
});
......@@ -50,7 +50,7 @@ export class OmnichannelLiveChat {
}
async openLiveChat(): Promise<void> {
const { value: siteName } = await (await this.api.get('/settings/Site_Name')).json();
const { value: siteName } = await (await this.api.get('/settings/Livechat_title')).json();
await this.btnOpenOnlineLiveChat(siteName).click();
}
......
......@@ -68,8 +68,14 @@ class Triggers {
}
async when(id, condition) {
const { user } = store.state;
if (!this._enabled) {
return Promise.reject('Triggers disabled');
return Promise.reject('Failed to schedule. Triggers disabled.');
}
if (user) {
return Promise.reject('Failed to schedule. User already registered.');
}
this._updateRecord(id, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment