Skip to content

Commit

Permalink
regression: after-guest-registration being deleted after chat starts (#…
Browse files Browse the repository at this point in the history
…31981)

Co-authored-by: Aleksander Nicacio da Silva <[email protected]>
  • Loading branch information
2 people authored and MartinSchoeler committed Mar 20, 2024
1 parent 6c92d10 commit 95e33d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions apps/meteor/tests/e2e/omnichannel/omnichannel-triggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ test.describe.serial('OC - Livechat Triggers', () => {
});

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.delete(`/livechat/triggers/${triggersName}`),
api.post('/settings/Livechat_clear_local_storage_when_chat_ended', { value: false }),
]);
await agent.page.close();
Expand Down Expand Up @@ -68,14 +73,16 @@ test.describe.serial('OC - Livechat Triggers', () => {
});

test('OC - Livechat Triggers - Create and edit trigger', async () => {
triggerMessage = 'This is a trigger message time on site';
await test.step('expect create new trigger', async () => {
await agent.poHomeOmnichannel.triggers.createTrigger(triggersName, triggerMessage);
await agent.poHomeOmnichannel.triggers.btnCloseToastMessage.click();
});

triggerMessage = 'This is a trigger message chat opened by visitor';
await test.step('expect update trigger', async () => {
await agent.poHomeOmnichannel.triggers.firstRowInTriggerTable(triggersName).click();
await agent.poHomeOmnichannel.triggers.updateTrigger(triggersName);
await agent.poHomeOmnichannel.triggers.updateTrigger(triggersName, triggerMessage);
await agent.poHomeOmnichannel.triggers.btnCloseToastMessage.click();
});
});
Expand Down Expand Up @@ -112,6 +119,8 @@ test.describe.serial('OC - Livechat Triggers', () => {
});

test('OC - Livechat Triggers - Condition: after guest registration', async ({ page }) => {

triggerMessage = 'This is a trigger message after guest registration';
await test.step('expect update trigger to after guest registration', async () => {
await agent.poHomeOmnichannel.triggers.firstRowInTriggerTable(`edited-${triggersName}`).click();
await agent.poHomeOmnichannel.triggers.fillTriggerForm({ condition: 'after-guest-registration', triggerMessage });
Expand Down Expand Up @@ -142,6 +151,7 @@ test.describe.serial('OC - Livechat Triggers', () => {
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.txtChatMessage('this_a_test_message_from_user')).toBeVisible();
await expect(poLiveChat.txtChatMessage(triggerMessage)).toBeVisible();
});

await test.step('expect to finish this chat', async () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/tests/e2e/page-objects/omnichannel-triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ export class OmnichannelTriggers {
await this.btnSave.click();
}

public async updateTrigger(newName: string) {
public async updateTrigger(newName: string, triggerMessage: string) {
await this.fillTriggerForm({
name: `edited-${newName}`,
description: 'Updating the existing trigger',
condition: 'chat-opened-by-visitor',
sender: 'custom',
agentName: 'Rocket.cat',
triggerMessage,
});
await this.btnSave.click();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/livechat/src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const onMessage = async (originalMessage) => {
await doPlaySound(message);
};

export const getGreetingMessages = (messages) => messages && messages.filter((msg) => msg.trigger && msg.triggerAfterRegistration);
export const getGreetingMessages = (messages) => messages && messages.filter((msg) => msg.trigger);
export const getLatestCallMessage = (messages) => messages && messages.filter((msg) => isVideoCallMessage(msg)).pop();

export const loadMessages = async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/livechat/src/lib/triggerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const sendMessageAction = async (_: string, action: ILivechatSendMessageA
u: agent,
ts: new Date().toISOString(),
_id: createToken(),
trigger: true,
};

await upsertMessage(message);
Expand Down Expand Up @@ -74,6 +75,7 @@ export const sendMessageExternalServiceAction = async (
u: agent,
ts: new Date().toISOString(),
_id: createToken(),
trigger: true,
}));

await Promise.all(messages.map((message) => upsertMessage(message)));
Expand Down

0 comments on commit 95e33d6

Please sign in to comment.