Skip to content

Commit e17527e

Browse files
add toBeOK on all api calls, organize the code better
1 parent 1de82a7 commit e17527e

2 files changed

Lines changed: 104 additions & 67 deletions

File tree

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.describe('OC - Routing to Idle Agents', () => {
1919
let poHomeOmnichannel: HomeOmnichannel;
2020
let poLivechat: OmnichannelLiveChat;
2121

22-
let livechatPage: Page;
22+
let livechatPage: Page | undefined;
2323

2424
let agent: Awaited<ReturnType<typeof createAgent>>;
2525
let testDepartment: Awaited<ReturnType<typeof createDepartment>>;
@@ -28,21 +28,28 @@ test.describe('OC - Routing to Idle Agents', () => {
2828
const routingMethods = ['Auto_Selection', 'Load_Balancing', 'Load_Rotation'];
2929

3030
test.beforeAll(async ({ api }) => {
31-
[agent, testDepartment] = await Promise.all([
32-
createAgent(api, 'user1'),
33-
createDepartment(api, { name: 'Idle Routing Dept' }),
31+
[agent, testDepartment] = await Promise.all([createAgent(api, 'user1'), createDepartment(api, { name: 'Idle Routing Dept' })]);
32+
33+
await expect(agent.response).toBeOK();
34+
await expect(testDepartment.response).toBeOK();
35+
36+
await addAgentToDepartment(api, { department: testDepartment.data, agentId: 'user1' });
37+
38+
const settingResponses = await Promise.all([
3439
setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300),
35-
expect(await setSettingValueById(api, 'Omnichannel_enable_department_removal', true)).toBeOK(),
40+
setSettingValueById(api, 'Omnichannel_enable_department_removal', true),
3641
]);
3742

38-
await Promise.all([addAgentToDepartment(api, { department: testDepartment.data, agentId: 'user1' })]);
43+
for (const response of settingResponses) {
44+
await expect(response).toBeOK();
45+
}
3946
});
4047

4148
test.beforeEach(async ({ page, browser, api }) => {
4249
visitor = createFakeVisitor();
4350
poHomeOmnichannel = new HomeOmnichannel(page);
44-
await page.goto('/');
45-
await page.locator('#main-content').waitFor();
51+
await poHomeOmnichannel.page.goto('/');
52+
await poHomeOmnichannel.waitForHome();
4653

4754
({ page: livechatPage } = await createAuxContext(browser, Users.user1, '/livechat', false));
4855
poLivechat = new OmnichannelLiveChat(livechatPage, api);
@@ -53,25 +60,29 @@ test.describe('OC - Routing to Idle Agents', () => {
5360
await livechatPage.context().close();
5461
}
5562

56-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300);
63+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).resolves.toBeOK();
5764
});
5865

5966
test.afterAll(async ({ api }) => {
60-
await Promise.all([
67+
const responses = await Promise.all([
6168
testDepartment.delete(),
6269
agent.delete(),
6370
setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection'),
6471
setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false),
65-
expect(await setSettingValueById(api, 'Omnichannel_enable_department_removal', false)).toBeOK(),
72+
setSettingValueById(api, 'Omnichannel_enable_department_removal', false),
6673
]);
74+
75+
for (const response of responses) {
76+
await expect(response).toBeOK();
77+
}
6778
});
6879

6980
routingMethods.forEach((routingMethod) => {
7081
test.describe(`Routing method: ${routingMethod}`, () => {
7182
test(`should not route to idle agents`, async ({ api }) => {
7283
await test.step(`Setup routing method to ${routingMethod} and ignore idle agents`, async () => {
73-
await setSettingValueById(api, 'Livechat_Routing_Method', routingMethod);
74-
await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false);
84+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).resolves.toBeOK();
85+
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false)).resolves.toBeOK();
7586
});
7687

7788
await test.step('Visitor tries to initiate a conversation with the away agent', async () => {
@@ -81,7 +92,7 @@ test.describe('OC - Routing to Idle Agents', () => {
8192
await poLivechat.onlineAgentMessage.fill('Hello from visitor');
8293

8394
// Force Agent to become away by idle timeout
84-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
95+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
8596
await poHomeOmnichannel.page.reload();
8697
await expect(poHomeOmnichannel.navbar.getUserStatusBadge('away')).toBeVisible();
8798

@@ -97,22 +108,23 @@ test.describe('OC - Routing to Idle Agents', () => {
97108

98109
test(`should route to agents even if they are idle when setting is enabled`, async ({ api }) => {
99110
await test.step(`Setup routing method to ${routingMethod} and allow idle agents`, async () => {
100-
await setSettingValueById(api, 'Livechat_Routing_Method', routingMethod);
101-
await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true);
111+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', routingMethod)).resolves.toBeOK();
112+
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).resolves.toBeOK();
102113
});
103114

104115
await test.step('Force agent to become away by idle timeout', async () => {
105-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
116+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
106117
await poHomeOmnichannel.page.reload();
107118
await expect(poHomeOmnichannel.navbar.getUserStatusBadge('away')).toBeVisible();
108119
});
109120

110121
await test.step('Visitor initiates chat', async () => {
111122
await poLivechat.page.reload();
112-
await poLivechat.openAnyLiveChat();
113-
await poLivechat.sendMessage(visitor, false);
114-
await poLivechat.onlineAgentMessage.fill('test message');
115-
await poLivechat.btnSendMessageToOnlineAgent.click();
123+
await poLivechat.openAnyLiveChatAndSendMessage({
124+
liveChatUser: visitor,
125+
message: 'test message',
126+
isOffline: false,
127+
});
116128
});
117129

118130
await test.step('Verify chat is served to an agent', async () => {

apps/meteor/tests/e2e/omnichannel/omnichannel-rooms-forward.spec.ts

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
2222
let poHomeOmnichannelAwayAgent: HomeOmnichannel;
2323
let poLivechat: OmnichannelLiveChat;
2424

25-
let livechatPage: Page;
26-
let omnichannelPage: Page;
25+
let livechatPage: Page | undefined;
26+
let omnichannelPage: Page | undefined;
2727

2828
let manager: Awaited<ReturnType<typeof createManager>>;
2929
let onlineAgent: Awaited<ReturnType<typeof createAgent>>;
@@ -39,21 +39,30 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
3939
createAgent(api, 'user2'),
4040
createDepartment(api, { name: 'Initial Dept' }),
4141
createDepartment(api, { name: 'Forward Dept', allowReceiveForwardOffline: true }),
42-
setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300),
43-
expect(await setSettingValueById(api, 'Omnichannel_enable_department_removal', true)).toBeOK(),
4442
]);
43+
await expect(manager.response).toBeOK();
44+
await expect(onlineAgent.response).toBeOK();
45+
await expect(awayAgent.response).toBeOK();
46+
await expect(initialDepartment.response).toBeOK();
47+
await expect(forwardToOfflineDepartment.response).toBeOK();
4548

46-
await Promise.all([
49+
const responses = await Promise.all([
50+
setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300),
51+
setSettingValueById(api, 'Omnichannel_enable_department_removal', true),
4752
addAgentToDepartment(api, { department: initialDepartment.data, agentId: 'user1' }),
4853
addAgentToDepartment(api, { department: forwardToOfflineDepartment.data, agentId: 'user2' }),
4954
]);
55+
56+
for (const response of responses) {
57+
await expect(response).toBeOK();
58+
}
5059
});
5160

5261
test.beforeEach(async ({ page, browser, api }) => {
5362
visitor = createFakeVisitor();
5463
poHomeOmnichannelOnlineAgent = new HomeOmnichannel(page);
55-
await page.goto('/');
56-
await page.locator('#main-content').waitFor();
64+
await poHomeOmnichannelOnlineAgent.page.goto('/');
65+
await poHomeOmnichannelOnlineAgent.waitForHome();
5766

5867
({ page: livechatPage } = await createAuxContext(browser, Users.user1, '/livechat', false));
5968
poLivechat = new OmnichannelLiveChat(livechatPage, api);
@@ -67,41 +76,45 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
6776
await omnichannelPage.context().close();
6877
}
6978

70-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300);
79+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 300)).resolves.toBeOK();
7180
});
7281

7382
test.afterAll(async ({ api }) => {
74-
await Promise.all([
83+
const responses = await Promise.all([
7584
initialDepartment.delete(),
7685
forwardToOfflineDepartment.delete(),
7786
manager.delete(),
7887
onlineAgent.delete(),
7988
awayAgent.delete(),
8089
setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection'),
8190
setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false),
82-
expect(await setSettingValueById(api, 'Omnichannel_enable_department_removal', false)).toBeOK(),
91+
setSettingValueById(api, 'Omnichannel_enable_department_removal', false),
8392
]);
93+
for (const response of responses) {
94+
await expect(response).toBeOK();
95+
}
8496
});
8597

8698
test('when manager forward to offline (agent away, accept when agent idle off) department the inquiry should be set to the queue', async ({
8799
api,
88100
browser,
89101
}) => {
90102
await test.step('Setup routing settings', async () => {
91-
await setSettingValueById(api, 'Livechat_Routing_Method', 'Manual_Selection');
92-
await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false);
103+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Manual_Selection')).resolves.toBeOK();
104+
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', false)).resolves.toBeOK();
93105
});
94106

95107
await test.step('Visitor initiates chat', async () => {
96108
await poLivechat.page.reload();
97-
await poLivechat.openAnyLiveChat();
98-
await poLivechat.sendMessage(visitor, false);
99-
await poLivechat.onlineAgentMessage.fill('test');
100-
await poLivechat.btnSendMessageToOnlineAgent.click();
109+
await poLivechat.openAnyLiveChatAndSendMessage({
110+
liveChatUser: visitor,
111+
message: 'test message',
112+
isOffline: false,
113+
});
101114
});
102115

103116
await test.step('Set user2 agent away by idle timeout', async () => {
104-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
117+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
105118
({ page: omnichannelPage } = await createAuxContext(browser, Users.user2, '/', false));
106119
poHomeOmnichannelAwayAgent = new HomeOmnichannel(omnichannelPage);
107120
await expect(poHomeOmnichannelAwayAgent.navbar.getUserStatusBadge('away')).toBeVisible();
@@ -117,10 +130,12 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
117130

118131
await test.step('Check inquiry status via API is queued', async () => {
119132
const roomInfoResp = await api.get(`/livechat/rooms`);
133+
await expect(roomInfoResp).toBeOK();
120134
const roomBody = await roomInfoResp.json();
121135
const roomId = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name)._id;
122136

123137
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${roomId}`);
138+
await expect(inquiryResp).toBeOK();
124139
const inquiryBody = await inquiryResp.json();
125140

126141
expect(inquiryBody.inquiry.status).toBe('queued');
@@ -133,27 +148,28 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
133148
browser,
134149
}) => {
135150
await test.step('Setup routing settings', async () => {
136-
await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection');
151+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
137152
});
138153

139154
await test.step('Visitor initiates chat', async () => {
140155
await poLivechat.page.reload();
141-
await poLivechat.openAnyLiveChat();
142-
await poLivechat.sendMessage(visitor, false);
143-
await poLivechat.onlineAgentMessage.fill('test');
144-
await poLivechat.btnSendMessageToOnlineAgent.click();
156+
await poLivechat.openAnyLiveChatAndSendMessage({
157+
liveChatUser: visitor,
158+
message: 'test message',
159+
isOffline: false,
160+
});
145161
});
146162

147163
await test.step('Set user2 agent away by idle timeout', async () => {
148-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
164+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
149165
({ page: omnichannelPage } = await createAuxContext(browser, Users.user2, '/', false));
150166
poHomeOmnichannelAwayAgent = new HomeOmnichannel(omnichannelPage);
151167
await expect(poHomeOmnichannelAwayAgent.navbar.getUserStatusBadge('away')).toBeVisible();
152168
});
153169

154170
await test.step('Manager enables queue and forwards chat', async () => {
155171
await poHomeOmnichannelOnlineAgent.sidebar.getSidebarItemByName(visitor.name).click();
156-
await setSettingValueById(api, 'Livechat_waiting_queue', true);
172+
await expect(setSettingValueById(api, 'Livechat_waiting_queue', true)).resolves.toBeOK();
157173

158174
await poHomeOmnichannelOnlineAgent.quickActionsRoomToolbar.forwardChat();
159175
await poHomeOmnichannelOnlineAgent.content.forwardChatModal.selectDepartment('Forward Dept');
@@ -163,18 +179,20 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
163179

164180
await test.step('Check inquiry status via API is queued', async () => {
165181
const roomInfoResp = await api.get(`/livechat/rooms`);
182+
await expect(roomInfoResp).toBeOK();
166183
const roomBody = await roomInfoResp.json();
167184
const roomId = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name)._id;
168185

169186
const inquiryResp = await api.get(`/livechat/inquiries.getOne?roomId=${roomId}`);
187+
await expect(inquiryResp).toBeOK();
170188
const inquiryBody = await inquiryResp.json();
171189

172190
expect(inquiryBody.inquiry.status).toBe('queued');
173191
expect(inquiryBody.inquiry.department).toBe(forwardToOfflineDepartment.data._id);
174192
});
175193

176194
await test.step('Disable waiting queue', async () => {
177-
await setSettingValueById(api, 'Livechat_waiting_queue', false);
195+
await expect(setSettingValueById(api, 'Livechat_waiting_queue', false)).resolves.toBeOK();
178196
});
179197
});
180198

@@ -183,30 +201,33 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
183201
browser,
184202
}) => {
185203
await test.step('Setup routing and department settings', async () => {
186-
await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection');
187-
await api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
188-
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: false },
189-
});
204+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
205+
await expect(
206+
api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
207+
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: false },
208+
}),
209+
).resolves.toBeOK();
190210
});
191211

192212
await test.step('Visitor initiates chat', async () => {
193213
await poLivechat.page.reload();
194-
await poLivechat.openAnyLiveChat();
195-
await poLivechat.sendMessage(visitor, false);
196-
await poLivechat.onlineAgentMessage.fill('test');
197-
await poLivechat.btnSendMessageToOnlineAgent.click();
214+
await poLivechat.openAnyLiveChatAndSendMessage({
215+
liveChatUser: visitor,
216+
message: 'test message',
217+
isOffline: false,
218+
});
198219
});
199220

200221
await test.step('Set user2 agent away by idle timeout', async () => {
201-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
222+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
202223
({ page: omnichannelPage } = await createAuxContext(browser, Users.user2, '/', false));
203224
poHomeOmnichannelAwayAgent = new HomeOmnichannel(omnichannelPage);
204225
await expect(poHomeOmnichannelAwayAgent.navbar.getUserStatusBadge('away')).toBeVisible();
205226
});
206227

207228
await test.step('Manager attempts to forward and sees error', async () => {
208229
await poHomeOmnichannelOnlineAgent.sidebar.getSidebarItemByName(visitor.name).click();
209-
await setSettingValueById(api, 'Livechat_waiting_queue', true);
230+
await expect(setSettingValueById(api, 'Livechat_waiting_queue', true)).resolves.toBeOK();
210231

211232
await poHomeOmnichannelOnlineAgent.quickActionsRoomToolbar.forwardChat();
212233
await poHomeOmnichannelOnlineAgent.content.forwardChatModal.selectDepartment('Forward Dept');
@@ -217,13 +238,15 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
217238
});
218239

219240
await test.step('Restore department setting', async () => {
220-
await api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
221-
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: true },
222-
});
241+
await expect(
242+
api.put(`/livechat/department/${forwardToOfflineDepartment.data._id}`, {
243+
department: { ...forwardToOfflineDepartment.data, allowReceiveForwardOffline: true },
244+
}),
245+
).resolves.toBeOK();
223246
});
224247

225248
await test.step('Disable waiting queue', async () => {
226-
await setSettingValueById(api, 'Livechat_waiting_queue', false);
249+
await expect(setSettingValueById(api, 'Livechat_waiting_queue', false)).resolves.toBeOK();
227250
});
228251
});
229252

@@ -232,20 +255,21 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
232255
browser,
233256
}) => {
234257
await test.step('Setup routing settings', async () => {
235-
await setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection');
236-
await setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true);
258+
await expect(setSettingValueById(api, 'Livechat_Routing_Method', 'Auto_Selection')).resolves.toBeOK();
259+
await expect(setSettingValueById(api, 'Livechat_enabled_when_agent_idle', true)).resolves.toBeOK();
237260
});
238261

239262
await test.step('Visitor initiates chat', async () => {
240263
await poLivechat.page.reload();
241-
await poLivechat.openAnyLiveChat();
242-
await poLivechat.sendMessage(visitor, false);
243-
await poLivechat.onlineAgentMessage.fill('test');
244-
await poLivechat.btnSendMessageToOnlineAgent.click();
264+
await poLivechat.openAnyLiveChatAndSendMessage({
265+
liveChatUser: visitor,
266+
message: 'test message',
267+
isOffline: false,
268+
});
245269
});
246270

247271
await test.step('Set user2 agent away by idle timeout', async () => {
248-
await setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1);
272+
await expect(setSettingValueById(api, 'Accounts_Default_User_Preferences_idleTimeLimit', 1)).resolves.toBeOK();
249273
({ page: omnichannelPage } = await createAuxContext(browser, Users.user2, '/', false));
250274
poHomeOmnichannelAwayAgent = new HomeOmnichannel(omnichannelPage);
251275
await expect(poHomeOmnichannelAwayAgent.navbar.getUserStatusBadge('away')).toBeVisible();
@@ -261,6 +285,7 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
261285

262286
await test.step('Check room routing via API serves to away agent', async () => {
263287
const roomInfoResp = await api.get(`/livechat/rooms`);
288+
await expect(roomInfoResp).toBeOK();
264289
const roomBody = await roomInfoResp.json();
265290
const room = roomBody.rooms.find((room: IRoom) => room.fname === visitor.name);
266291

0 commit comments

Comments
 (0)