Skip to content

Commit 521487c

Browse files
remove unneeded resolves, use createConversation
1 parent d0fb398 commit 521487c

2 files changed

Lines changed: 36 additions & 93 deletions

File tree

apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-agent-idle-setting.spec.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { HomeOmnichannel } from '../page-objects';
88
import { OmnichannelLiveChat } from '../page-objects/omnichannel';
99
import { setSettingValueById } from '../utils';
1010
import { createAgent } from '../utils/omnichannel/agents';
11-
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
1211
import { test, expect } from '../utils/test';
1312

1413
test.use({ storageState: Users.user1.state });
@@ -22,18 +21,13 @@ test.describe('OC - Routing to Idle Agents', () => {
2221
let livechatPage: Page | undefined;
2322

2423
let agent: Awaited<ReturnType<typeof createAgent>>;
25-
let testDepartment: Awaited<ReturnType<typeof createDepartment>>;
2624
let visitor: { name: string; email: string };
2725

2826
const routingMethods = ['Auto_Selection', 'Load_Balancing', 'Load_Rotation'];
2927

3028
test.beforeAll(async ({ api }) => {
31-
[agent, testDepartment] = await Promise.all([createAgent(api, 'user1'), createDepartment(api, { name: 'Idle Routing Dept' })]);
32-
29+
agent = await createAgent(api, 'user1');
3330
await expect(agent.response).toBeOK();
34-
await expect(testDepartment.response).toBeOK();
35-
36-
await addAgentToDepartment(api, { department: testDepartment.data, agentId: 'user1' });
3731

3832
const settingResponses = await Promise.all([
3933
setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300),
@@ -60,12 +54,11 @@ test.describe('OC - Routing to Idle Agents', () => {
6054
await livechatPage.context().close();
6155
}
6256

63-
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).resolves.toBeOK();
57+
await expect(await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).toBeOK();
6458
});
6559

6660
test.afterAll(async ({ api }) => {
6761
const responses = await Promise.all([
68-
testDepartment.delete(),
6962
agent.delete(),
7063
setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection'),
7164
setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false),
@@ -81,18 +74,17 @@ test.describe('OC - Routing to Idle Agents', () => {
8174
test.describe(`Routing method: ${routingMethod}`, () => {
8275
test(`should not route to idle agents`, async ({ api }) => {
8376
await test.step(`Setup routing method to ${routingMethod} and ignore idle agents`, async () => {
84-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).resolves.toBeOK();
85-
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false)).resolves.toBeOK();
77+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).toBeOK();
78+
await expect(await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false)).toBeOK();
8679
});
8780

8881
await test.step('Visitor tries to initiate a conversation with the away agent', async () => {
89-
await poLivechat.page.reload();
9082
await poLivechat.openAnyLiveChat();
9183
await poLivechat.sendMessage(visitor, false);
9284
await poLivechat.onlineAgentMessage.fill('Hello from visitor');
9385

9486
// Force Agent to become away by idle timeout
95-
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
87+
await expect(await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).toBeOK();
9688
await poHomeOmnichannel.page.reload();
9789
await expect(poHomeOmnichannel.navbar.getUserStatusBadge('away')).toBeVisible();
9890

@@ -108,18 +100,17 @@ test.describe('OC - Routing to Idle Agents', () => {
108100

109101
test(`should route to agents even if they are idle when setting is enabled`, async ({ api }) => {
110102
await test.step(`Setup routing method to ${routingMethod} and allow idle agents`, async () => {
111-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).resolves.toBeOK();
112-
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).resolves.toBeOK();
103+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).toBeOK();
104+
await expect(await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).toBeOK();
113105
});
114106

115107
await test.step('Force agent to become away by idle timeout', async () => {
116-
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
108+
await expect(await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).toBeOK();
117109
await poHomeOmnichannel.page.reload();
118110
await expect(poHomeOmnichannel.navbar.getUserStatusBadge('away')).toBeVisible();
119111
});
120112

121113
await test.step('Visitor initiates chat', async () => {
122-
await poLivechat.page.reload();
123114
await poLivechat.openAnyLiveChatAndSendMessage({
124115
liveChatUser: visitor,
125116
message: 'test message',
Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
import type { Page } from '@playwright/test';
2-
import type { IRoom } from '@rocket.chat/core-typings';
32

43
import { createFakeVisitor } from '../../mocks/data';
54
import { IS_EE } from '../config/constants';
65
import { createAuxContext } from '../fixtures/createAuxContext';
76
import { Users } from '../fixtures/userStates';
87
import { HomeOmnichannel } from '../page-objects';
9-
import { OmnichannelLiveChat } from '../page-objects/omnichannel';
108
import { setSettingValueById } from '../utils';
119
import { createAgent } from '../utils/omnichannel/agents';
1210
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
1311
import { createManager } from '../utils/omnichannel/managers';
12+
import { createConversation } from '../utils/omnichannel/rooms';
1413
import { test, expect } from '../utils/test';
1514

1615
test.use({ storageState: Users.user1.state });
1716

18-
test.describe('OC - Forwarding to away agents (EE)', () => {
17+
test.describe('OC - Forwarding to away departments (EE)', () => {
1918
test.skip(!IS_EE, 'Enterprise Edition Only');
2019

2120
let poHomeOmnichannelOnlineAgent: HomeOmnichannel;
2221
let poHomeOmnichannelAwayAgent: HomeOmnichannel;
23-
let poLivechat: OmnichannelLiveChat;
2422

25-
let livechatPage: Page | undefined;
2623
let omnichannelPage: Page | undefined;
2724

2825
let manager: Awaited<ReturnType<typeof createManager>>;
2926
let onlineAgent: Awaited<ReturnType<typeof createAgent>>;
3027
let awayAgent: Awaited<ReturnType<typeof createAgent>>;
3128
let initialDepartment: Awaited<ReturnType<typeof createDepartment>>;
3229
let forwardToOfflineDepartment: Awaited<ReturnType<typeof createDepartment>>;
30+
let conversation: Awaited<ReturnType<typeof createConversation>>;
3331
let visitor: { name: string; email: string };
3432

3533
test.beforeAll(async ({ api }) => {
@@ -66,10 +64,7 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
6664
await poHomeOmnichannelOnlineAgent.page.goto('/');
6765
await poHomeOmnichannelOnlineAgent.waitForHome();
6866

69-
({ page: livechatPage } = await createAuxContext(browser, Users.user1, '/livechat', false));
70-
poLivechat = new OmnichannelLiveChat(livechatPage, api);
71-
72-
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
67+
await expect(await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).toBeOK();
7368

7469
// Away Agent window opens with idleTimeLimit of 1, therefore after a second it will turn away
7570
({ page: omnichannelPage } = await createAuxContext(browser, Users.user2, '/', false));
@@ -78,14 +73,12 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
7873
});
7974

8075
test.afterEach(async ({ api }) => {
81-
if (livechatPage) {
82-
await livechatPage.context().close();
83-
}
8476
if (omnichannelPage) {
8577
await omnichannelPage.context().close();
8678
}
8779

88-
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).resolves.toBeOK();
80+
await expect(await setSettingValueById(api, 'Livechat_waiting_queue', false)).toBeOK();
81+
await expect(await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).toBeOK();
8982
});
9083

9184
test.afterAll(async ({ api }) => {
@@ -108,16 +101,11 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
108101
api,
109102
}) => {
110103
await test.step('Setup routing settings', async () => {
111-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Manual_Selection')).resolves.toBeOK();
104+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', 'Manual_Selection')).toBeOK();
112105
});
113106

114107
await test.step('Visitor initiates chat', async () => {
115-
await poLivechat.page.reload();
116-
await poLivechat.openAnyLiveChatAndSendMessage({
117-
liveChatUser: visitor,
118-
message: 'test message',
119-
isOffline: false,
120-
});
108+
conversation = await createConversation(api, { visitorName: visitor.name, agentId: onlineAgent.data._id });
121109
});
122110

123111
await test.step('Manager forwards chat', async () => {
@@ -129,12 +117,7 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
129117
});
130118

131119
await test.step('Check inquiry status via API is queued', async () => {
132-
const roomInfoResp = await api.get(`/livechat/rooms`);
133-
await expect(roomInfoResp).toBeOK();
134-
const roomBody = await roomInfoResp.json();
135-
const roomId = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name)._id;
136-
137-
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${roomId}`);
120+
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${conversation.data.room._id}`);
138121
await expect(inquiryResp).toBeOK();
139122
const inquiryBody = await inquiryResp.json();
140123

@@ -147,21 +130,16 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
147130
api,
148131
}) => {
149132
await test.step('Setup routing settings', async () => {
150-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
133+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).toBeOK();
151134
});
152135

153136
await test.step('Visitor initiates chat', async () => {
154-
await poLivechat.page.reload();
155-
await poLivechat.openAnyLiveChatAndSendMessage({
156-
liveChatUser: visitor,
157-
message: 'test message',
158-
isOffline: false,
159-
});
137+
conversation = await createConversation(api, { visitorName: visitor.name, agentId: onlineAgent.data._id });
160138
});
161139

162140
await test.step('Manager enables queue and forwards chat', async () => {
163141
await poHomeOmnichannelOnlineAgent.sidebar.getSidebarItemByName(visitor.name).click();
164-
await expect(setSettingValueById(api, 'Livechat_waiting_queue', true)).resolves.toBeOK();
142+
await expect(await setSettingValueById(api, 'Livechat_waiting_queue', true)).toBeOK();
165143

166144
await poHomeOmnichannelOnlineAgent.quickActionsRoomToolbar.forwardChat();
167145
await poHomeOmnichannelOnlineAgent.content.forwardChatModal.selectDepartment('Forward Dept');
@@ -170,48 +148,34 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
170148
});
171149

172150
await test.step('Check inquiry status via API is queued', async () => {
173-
const roomInfoResp = await api.get(`/livechat/rooms`);
174-
await expect(roomInfoResp).toBeOK();
175-
const roomBody = await roomInfoResp.json();
176-
const roomId = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name)._id;
177-
178-
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${roomId}`);
151+
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${conversation.data.room._id}`);
179152
await expect(inquiryResp).toBeOK();
180153
const inquiryBody = await inquiryResp.json();
181154

182155
expect(inquiryBody.inquiry.status).toBe('queued');
183156
expect(inquiryBody.inquiry.department).toBe(forwardToOfflineDepartment.data._id);
184157
});
185-
186-
await test.step('Disable waiting queue', async () => {
187-
await expect(setSettingValueById(api, 'Livechat_waiting_queue', false)).resolves.toBeOK();
188-
});
189158
});
190159

191160
test('when manager forward to a department while waiting_queue is active and allowReceiveForwardOffline is false, transfer should fail', async ({
192161
api,
193162
}) => {
194163
await test.step('Setup routing and department settings', async () => {
195-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
164+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).toBeOK();
196165
await expect(
197-
api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
166+
await api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
198167
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: false },
199168
}),
200-
).resolves.toBeOK();
169+
).toBeOK();
201170
});
202171

203172
await test.step('Visitor initiates chat', async () => {
204-
await poLivechat.page.reload();
205-
await poLivechat.openAnyLiveChatAndSendMessage({
206-
liveChatUser: visitor,
207-
message: 'test message',
208-
isOffline: false,
209-
});
173+
conversation = await createConversation(api, { visitorName: visitor.name, agentId: onlineAgent.data._id });
210174
});
211175

212176
await test.step('Manager attempts to forward and sees error', async () => {
213177
await poHomeOmnichannelOnlineAgent.sidebar.getSidebarItemByName(visitor.name).click();
214-
await expect(setSettingValueById(api, 'Livechat_waiting_queue', true)).resolves.toBeOK();
178+
await expect(await setSettingValueById(api, 'Livechat_waiting_queue', true)).toBeOK();
215179

216180
await poHomeOmnichannelOnlineAgent.quickActionsRoomToolbar.forwardChat();
217181
await poHomeOmnichannelOnlineAgent.content.forwardChatModal.selectDepartment('Forward Dept');
@@ -223,37 +187,27 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
223187

224188
await test.step('Restore department setting', async () => {
225189
await expect(
226-
api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
190+
await api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
227191
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: true },
228192
}),
229-
).resolves.toBeOK();
230-
});
231-
232-
await test.step('Disable waiting queue', async () => {
233-
await expect(setSettingValueById(api, 'Livechat_waiting_queue', false)).resolves.toBeOK();
193+
).toBeOK();
234194
});
235195
});
236196

237197
test('when manager forward to online (agent away, accept when agent idle on) department the inquiry should not be set to the queue', async ({
238198
api,
239199
}) => {
240200
await test.step('Setup routing settings', async () => {
241-
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
201+
await expect(await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).toBeOK();
242202
});
243203

244204
await test.step('Visitor initiates chat', async () => {
245-
await poLivechat.page.reload();
246-
await poLivechat.openAnyLiveChatAndSendMessage({
247-
liveChatUser: visitor,
248-
message: 'test message',
249-
isOffline: false,
250-
});
251-
await expect(poLivechat.headerTitle).toHaveText(onlineAgent.data.username);
205+
conversation = await createConversation(api, { visitorName: visitor.name, agentId: onlineAgent.data._id });
252206
});
253207

254208
await test.step('Set Livechat_enabled_when_agent_idle to true', async () => {
255209
// We set Livechat_enabled_when_agent_idle to true here in order to not assign the away agent in the previous step
256-
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).resolves.toBeOK();
210+
await expect(await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).toBeOK();
257211
});
258212

259213
await test.step('Manager forwards chat successfully', async () => {
@@ -265,13 +219,11 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
265219
});
266220

267221
await test.step('Check room routing via API serves to away agent', async () => {
268-
const roomInfoResp = await api.get(`/livechat/rooms`);
269-
await expect(roomInfoResp).toBeOK();
270-
const roomBody = await roomInfoResp.json();
271-
const room = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name);
272-
273-
expect(room.servedBy._id).toBe(awayAgent.data._id);
274-
expect(room.departmentId).toBe(forwardToOfflineDepartment.data._id);
222+
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${conversation.data.room._id}`);
223+
await expect(inquiryResp).toBeOK();
224+
const inquiryBody = await inquiryResp.json();
225+
expect(inquiryBody.inquiry.status).toBe('taken');
226+
expect(inquiryBody.inquiry.department).toBe(forwardToOfflineDepartment.data._id);
275227
});
276228
});
277229
});

0 commit comments

Comments
 (0)