Skip to content

Commit 4237478

Browse files
committed
tests
1 parent 84a2754 commit 4237478

File tree

5 files changed

+162
-76
lines changed

5 files changed

+162
-76
lines changed

apps/meteor/tests/e2e/omnichannel/omnichannel-assign-room-tags.spec.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { createFakeVisitor } from '../../mocks/data';
22
import { IS_EE } from '../config/constants';
33
import { Users } from '../fixtures/userStates';
44
import { HomeOmnichannel } from '../page-objects';
5+
import { setSettingValueById } from '../utils';
56
import { createAgent } from '../utils/omnichannel/agents';
67
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
7-
import { createConversation } from '../utils/omnichannel/rooms';
8+
import { createConversation, waitForInquiryToBeTaken } from '../utils/omnichannel/rooms';
89
import { createTag } from '../utils/omnichannel/tags';
910
import { test, expect } from '../utils/test';
1011

@@ -23,6 +24,14 @@ test.describe('OC - Tags Visibility', () => {
2324
let agent: Awaited<ReturnType<typeof createAgent>>;
2425
let tags: Awaited<ReturnType<typeof createTag>>[] = [];
2526

27+
test.beforeAll('Configure queue settings', async ({ api }) => {
28+
const responses = await Promise.all([
29+
setSettingValueById(api, 'Livechat_waiting_queue', true),
30+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 1),
31+
]);
32+
responses.forEach((res) => expect(res.status()).toBe(200));
33+
});
34+
2635
test.beforeAll('Create departments', async ({ api }) => {
2736
departmentA = await createDepartment(api, { name: 'Department A' });
2837
departmentB = await createDepartment(api, { name: 'Department B' });
@@ -53,30 +62,39 @@ test.describe('OC - Tags Visibility', () => {
5362
});
5463

5564
test.beforeAll('Create conversations', async ({ api }) => {
56-
const conversationA = await createConversation(api, {
57-
visitorName: visitorA.name,
58-
agentId: 'user1',
59-
departmentId: departmentA.data._id,
60-
});
61-
const conversationB = await createConversation(api, {
62-
visitorName: visitorB.name,
63-
agentId: 'user1',
64-
departmentId: departmentB.data._id,
65-
});
66-
conversations = [conversationA, conversationB];
65+
conversations = await Promise.all([
66+
createConversation(api, {
67+
visitorName: visitorA.name,
68+
agentId: 'user1',
69+
departmentId: departmentA.data._id,
70+
}),
71+
createConversation(api, {
72+
visitorName: visitorB.name,
73+
agentId: 'user1',
74+
departmentId: departmentB.data._id,
75+
}),
76+
]);
77+
await waitForInquiryToBeTaken(
78+
api,
79+
conversations.map((c) => c.data.room._id),
80+
);
6781
});
6882

6983
test.beforeEach(async ({ page }) => {
7084
poOmnichannel = new HomeOmnichannel(page);
7185
await page.goto('/');
7286
});
7387

74-
test.afterAll(async () => {
75-
await Promise.all(conversations.map((conversation) => conversation.delete()));
76-
await Promise.all(tags.map((tag) => tag.delete()));
77-
await agent.delete();
78-
await departmentA.delete();
79-
await departmentB.delete();
88+
test.afterAll(async ({ api }) => {
89+
await Promise.all([
90+
...conversations.map((conversation) => conversation.delete()),
91+
...tags.map((tag) => tag.delete()),
92+
agent.delete(),
93+
departmentA.delete(),
94+
departmentB.delete(),
95+
setSettingValueById(api, 'Livechat_waiting_queue', false),
96+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 5),
97+
]);
8098
});
8199

82100
test('Verify agent should see correct tags based on department association', async () => {

apps/meteor/tests/e2e/omnichannel/omnichannel-chat-transfers.spec.ts

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { IS_EE } from '../config/constants';
44
import { createAuxContext } from '../fixtures/createAuxContext';
55
import { Users } from '../fixtures/userStates';
66
import { HomeOmnichannel } from '../page-objects';
7+
import { setSettingValueById } from '../utils';
78
import { createAgent, makeAgentAvailable } from '../utils/omnichannel/agents';
89
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
910
import { createManager } from '../utils/omnichannel/managers';
1011
import { createMonitor } from '../utils/omnichannel/monitors';
11-
import { createConversation } from '../utils/omnichannel/rooms';
12+
import { createConversation, waitForInquiryToBeTaken } from '../utils/omnichannel/rooms';
1213
import { createOrUpdateUnit } from '../utils/omnichannel/units';
1314
import { expect, test } from '../utils/test';
1415

@@ -28,6 +29,14 @@ test.describe('OC - Chat transfers [Monitor role]', () => {
2829

2930
let poOmnichannel: HomeOmnichannel;
3031

32+
test.beforeAll(async ({ api }) => {
33+
const responses = await Promise.all([
34+
setSettingValueById(api, 'Livechat_waiting_queue', true),
35+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 1),
36+
]);
37+
responses.forEach((res) => expect(res.status()).toBe(200));
38+
});
39+
3140
// Create agents
3241
test.beforeAll(async ({ api }) => {
3342
agents = await Promise.all([createAgent(api, 'user1'), createAgent(api, 'user2'), createAgent(api, 'rocketchat.internal.admin.test')]);
@@ -59,19 +68,25 @@ test.describe('OC - Chat transfers [Monitor role]', () => {
5968
test.beforeAll(async ({ api }) => {
6069
const [departmentA] = departments.map(({ data }) => data);
6170

62-
const conversationA = await createConversation(api, {
63-
agentId: `user1`,
64-
departmentId: departmentA._id,
65-
});
66-
const conversationB = await createConversation(api, {
67-
agentId: `user1`,
68-
departmentId: departmentA._id,
69-
});
70-
const conversationC = await createConversation(api, {
71-
agentId: `user1`,
72-
departmentId: departmentA._id,
73-
});
74-
conversations = [conversationA, conversationB, conversationC];
71+
conversations = await Promise.all([
72+
createConversation(api, {
73+
agentId: `user1`,
74+
departmentId: departmentA._id,
75+
}),
76+
createConversation(api, {
77+
agentId: `user1`,
78+
departmentId: departmentA._id,
79+
}),
80+
createConversation(api, {
81+
agentId: `user1`,
82+
departmentId: departmentA._id,
83+
}),
84+
]);
85+
86+
await waitForInquiryToBeTaken(
87+
api,
88+
conversations.map((c) => c.data.room._id),
89+
);
7590
});
7691

7792
// Create monitors
@@ -115,13 +130,15 @@ test.describe('OC - Chat transfers [Monitor role]', () => {
115130
await Promise.all(sessions.map(({ page }) => page.close()));
116131
});
117132

118-
test.afterAll(async () => {
133+
test.afterAll(async ({ api }) => {
119134
await Promise.all([
120135
...conversations.map((conversation) => conversation.delete()),
121136
...monitors.map((monitor) => monitor.delete()),
122137
...agents.map((agent) => agent.delete()),
123138
...units.map((unit) => unit.delete()),
124139
...departments.map((department) => department.delete()),
140+
setSettingValueById(api, 'Livechat_waiting_queue', false),
141+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 5),
125142
]);
126143
});
127144

@@ -266,6 +283,14 @@ test.describe('OC - Chat transfers [Manager role]', () => {
266283

267284
let poOmnichannel: HomeOmnichannel;
268285

286+
test.beforeAll(async ({ api }) => {
287+
const responses = await Promise.all([
288+
setSettingValueById(api, 'Livechat_waiting_queue', true),
289+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 1),
290+
]);
291+
responses.forEach((res) => expect(res.status()).toBe(200));
292+
});
293+
269294
// Create agents
270295
test.beforeAll(async ({ api }) => {
271296
agents = await Promise.all([createAgent(api, 'user1'), createAgent(api, 'user2'), createAgent(api, 'rocketchat.internal.admin.test')]);
@@ -302,19 +327,25 @@ test.describe('OC - Chat transfers [Manager role]', () => {
302327
test.beforeAll(async ({ api }) => {
303328
const [departmentA] = departments.map(({ data }) => data);
304329

305-
const conversationA = await createConversation(api, {
306-
agentId: `user1`,
307-
departmentId: departmentA._id,
308-
});
309-
const conversationB = await createConversation(api, {
310-
agentId: `user1`,
311-
departmentId: departmentA._id,
312-
});
313-
const conversationC = await createConversation(api, {
314-
agentId: `user1`,
315-
departmentId: departmentA._id,
316-
});
317-
conversations = [conversationA, conversationB, conversationC];
330+
conversations = await Promise.all([
331+
createConversation(api, {
332+
agentId: `user1`,
333+
departmentId: departmentA._id,
334+
}),
335+
createConversation(api, {
336+
agentId: `user1`,
337+
departmentId: departmentA._id,
338+
}),
339+
createConversation(api, {
340+
agentId: `user1`,
341+
departmentId: departmentA._id,
342+
}),
343+
]);
344+
345+
await waitForInquiryToBeTaken(
346+
api,
347+
conversations.map((c) => c.data.room._id),
348+
);
318349
});
319350

320351
// Create sessions
@@ -337,12 +368,14 @@ test.describe('OC - Chat transfers [Manager role]', () => {
337368
await Promise.all(sessions.map(({ page }) => page.close()));
338369
});
339370

340-
test.afterAll(async () => {
371+
test.afterAll(async ({ api }) => {
341372
await Promise.all([
342373
...conversations.map((conversation) => conversation.delete()),
343374
...managers.map((manager) => manager.delete()),
344375
...agents.map((agent) => agent.delete()),
345376
...departments.map((department) => department.delete()),
377+
setSettingValueById(api, 'Livechat_waiting_queue', false),
378+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 5),
346379
]);
347380
});
348381

apps/meteor/tests/e2e/omnichannel/omnichannel-contact-center-chats-filters.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Users } from '../fixtures/userStates';
44
import { OmnichannelChats } from '../page-objects/omnichannel-contact-center-chats';
55
import { setSettingValueById } from '../utils';
66
import { createAgent, makeAgentAvailable } from '../utils/omnichannel/agents';
7-
import { createConversation } from '../utils/omnichannel/rooms';
7+
import { createConversation, waitForInquiryToBeTaken } from '../utils/omnichannel/rooms';
88
import { test, expect } from '../utils/test';
99

1010
test.use({ storageState: Users.user1.state });
@@ -30,9 +30,17 @@ test.describe('OC - Contact Center - Chats', () => {
3030
});
3131

3232
test.beforeAll(async ({ api }) => {
33+
// run synchronously because this test runs in the CE environment,
34+
// which lacks the waiting queue setting. with parallel execution,
35+
// the agent lock would prevent the second assignment and keep the
36+
// conversation in READY state (see RoutingManager.ts:118)
3337
const conversationA = await createConversation(api, { agentId: `user1`, visitorName: visitorA });
3438
const conversationB = await createConversation(api, { agentId: `user1`, visitorName: visitorB });
3539
conversations = [conversationA, conversationB];
40+
await waitForInquiryToBeTaken(
41+
api,
42+
conversations.map((c) => c.data.room._id),
43+
);
3644
});
3745

3846
test.beforeEach(async ({ page }) => {

apps/meteor/tests/e2e/omnichannel/omnichannel-contact-center-filters.spec.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { IS_EE } from '../config/constants';
33
import { Users } from '../fixtures/userStates';
44
import { OmnichannelContacts } from '../page-objects/omnichannel-contacts-list';
55
import { OmnichannelSection } from '../page-objects/omnichannel-section';
6+
import { setSettingValueById } from '../utils';
67
import { createAgent, makeAgentAvailable } from '../utils/omnichannel/agents';
78
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
8-
import { createConversation, updateRoom } from '../utils/omnichannel/rooms';
9+
import { createConversation, updateRoom, waitForInquiryToBeTaken } from '../utils/omnichannel/rooms';
910
import { createTag } from '../utils/omnichannel/tags';
1011
import { createOrUpdateUnit } from '../utils/omnichannel/units';
1112
import { test, expect } from '../utils/test';
@@ -31,11 +32,12 @@ test.describe('OC - Contact Center', async () => {
3132
let poContacts: OmnichannelContacts;
3233
let poOmniSection: OmnichannelSection;
3334

34-
// Allow manual on hold
3535
test.beforeAll(async ({ api }) => {
3636
const responses = await Promise.all([
37-
api.post('/settings/Livechat_allow_manual_on_hold', { value: true }),
38-
api.post('/settings/Livechat_allow_manual_on_hold_upon_agent_engagement_only', { value: false }),
37+
setSettingValueById(api, 'Livechat_allow_manual_on_hold', true),
38+
setSettingValueById(api, 'Livechat_allow_manual_on_hold_upon_agent_engagement_only', false),
39+
setSettingValueById(api, 'Livechat_waiting_queue', true),
40+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 1),
3941
]);
4042
responses.forEach((res) => expect(res.status()).toBe(200));
4143
});
@@ -93,36 +95,38 @@ test.describe('OC - Contact Center', async () => {
9395
test.beforeAll(async ({ api }) => {
9496
const [departmentA, departmentB] = departments.map(({ data }) => data);
9597

96-
const conversationA = await createConversation(api, {
97-
visitorName: visitorA,
98-
visitorToken: visitorA,
99-
agentId: `user1`,
100-
departmentId: departmentA._id,
101-
});
102-
103-
const conversationB = await createConversation(api, {
104-
visitorName: visitorB,
105-
visitorToken: visitorB,
106-
agentId: `user2`,
107-
departmentId: departmentB._id,
108-
});
98+
conversations = await Promise.all([
99+
createConversation(api, {
100+
visitorName: visitorA,
101+
visitorToken: visitorA,
102+
agentId: `user1`,
103+
departmentId: departmentA._id,
104+
}),
105+
createConversation(api, {
106+
visitorName: visitorB,
107+
visitorToken: visitorB,
108+
agentId: `user2`,
109+
departmentId: departmentB._id,
110+
}),
111+
createConversation(api, {
112+
visitorName: visitorC,
113+
visitorToken: visitorC,
114+
}),
115+
]);
109116

110-
const conversationC = await createConversation(api, {
111-
visitorName: visitorC,
112-
visitorToken: visitorC,
113-
});
117+
await waitForInquiryToBeTaken(api, [conversations[0].data.room._id, conversations[1].data.room._id]);
114118

115-
conversations = [conversationA, conversationB, conversationC];
119+
const [conversationA, conversationB] = conversations.map(({ data }) => data);
116120

117121
await Promise.all([
118122
updateRoom(api, {
119-
roomId: conversationA.data.room._id,
120-
visitorId: conversationA.data.visitor._id,
123+
roomId: conversationA.room._id,
124+
visitorId: conversationA.visitor._id,
121125
tags: ['tagA'],
122126
}),
123127
updateRoom(api, {
124-
roomId: conversationB.data.room._id,
125-
visitorId: conversationB.data.visitor._id,
128+
roomId: conversationB.room._id,
129+
visitorId: conversationB.visitor._id,
126130
tags: ['tagB'],
127131
}),
128132
]);
@@ -141,8 +145,10 @@ test.describe('OC - Contact Center', async () => {
141145
// Delete units
142146
...units.map((unit) => unit.delete()),
143147
// Reset setting
144-
api.post('/settings/Livechat_allow_manual_on_hold', { value: false }),
145-
api.post('/settings/Livechat_allow_manual_on_hold_upon_agent_engagement_only', { value: true }),
148+
setSettingValueById(api, 'Livechat_allow_manual_on_hold', false),
149+
setSettingValueById(api, 'Livechat_allow_manual_on_hold_upon_agent_engagement_only', true),
150+
setSettingValueById(api, 'Livechat_waiting_queue', false),
151+
setSettingValueById(api, 'Omnichannel_queue_delay_timeout', 5),
146152
]);
147153
});
148154

apps/meteor/tests/e2e/utils/omnichannel/rooms.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,24 @@ export const createConversation = async (
121121
},
122122
};
123123
};
124+
125+
export const waitForInquiryToBeTaken = async (api: BaseTest['api'], roomIds: string | string[], maxAttempts = 10, intervalMs = 1000) => {
126+
const ids = Array.isArray(roomIds) ? roomIds : [roomIds];
127+
128+
const checkInquiry = async (roomId: string) => {
129+
for await (const [index] of Array(maxAttempts).entries()) {
130+
const inquiry = await api.get('/livechat/inquiries.getOne', { roomId });
131+
const inquiryData = await inquiry.json();
132+
if (inquiryData.inquiry?.status !== 'queued') {
133+
return;
134+
}
135+
136+
if (index < maxAttempts - 1) {
137+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
138+
}
139+
}
140+
throw new Error(`Inquiry for room ${roomId} was not taken after ${maxAttempts * intervalMs}ms`);
141+
};
142+
143+
await Promise.all(ids.map(checkInquiry));
144+
};

0 commit comments

Comments
 (0)