Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: fallback offline department #33009

Merged
merged 8 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class QueueManager {

const name = (roomInfo?.fname as string) || guest.name || guest.username;

const room = await createLivechatRoom(rid, name, guest, roomInfo, {
const room = await createLivechatRoom(rid, name, { ...guest, ...(department && { department }) }, roomInfo, {
...extraData,
...(Boolean(customFields) && { customFields }),
});
Expand Down
21 changes: 18 additions & 3 deletions apps/meteor/tests/data/livechat/department.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ const updateDepartment = async (departmentId: string, departmentData: Partial<Li
return response.body.department;
};

const createDepartmentWithMethod = (initialAgents: { agentId: string; username: string }[] = [], allowReceiveForwardOffline = false) =>
const createDepartmentWithMethod = (
initialAgents: { agentId: string; username: string }[] = [],
{
allowReceiveForwardOffline = false,
fallbackForwardDepartment,
}: {
allowReceiveForwardOffline?: boolean;
fallbackForwardDepartment?: string;
} = {},
) =>
new Promise((resolve, reject) => {
void request
.post(methodCall('livechat:saveDepartment'))
Expand All @@ -56,6 +65,7 @@ const createDepartmentWithMethod = (initialAgents: { agentId: string; username:
name: `new department ${Date.now()}`,
description: 'created from api',
allowReceiveForwardOffline,
fallbackForwardDepartment,
},
initialAgents,
],
Expand Down Expand Up @@ -126,8 +136,10 @@ export const addOrRemoveAgentFromDepartment = async (

export const createDepartmentWithAnOfflineAgent = async ({
allowReceiveForwardOffline = false,
fallbackForwardDepartment,
}: {
allowReceiveForwardOffline: boolean;
allowReceiveForwardOffline?: boolean;
fallbackForwardDepartment?: string;
}): Promise<{
department: ILivechatDepartment;
agent: {
Expand All @@ -137,7 +149,10 @@ export const createDepartmentWithAnOfflineAgent = async ({
}> => {
const { user, credentials } = await createAnOfflineAgent();

const department = (await createDepartmentWithMethod(undefined, allowReceiveForwardOffline)) as ILivechatDepartment;
const department = (await createDepartmentWithMethod(undefined, {
allowReceiveForwardOffline,
fallbackForwardDepartment,
})) as ILivechatDepartment;

await addOrRemoveAgentFromDepartment(department._id, { agentId: user._id, username: user.username }, true);

Expand Down
39 changes: 39 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,45 @@ describe('LIVECHAT - rooms', () => {
roomId = newRoom._id;
visitorToken = newVisitor.token;
});
(IS_EE ? describe : describe.skip)('fallback department', () => {
let fallbackDepartment: Awaited<ReturnType<typeof createDepartmentWithAnOnlineAgent>>['department'];
let initialDepartment: Awaited<ReturnType<typeof createDepartmentWithAnOfflineAgent>>['department'];
let newVisitor: ILivechatVisitor;
let latestRoom: IOmnichannelRoom;
before(async () => {
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');

fallbackDepartment = (await createDepartmentWithAnOnlineAgent()).department;
initialDepartment = (
await createDepartmentWithAnOfflineAgent({
fallbackForwardDepartment: fallbackDepartment._id,
})
).department;

expect(initialDepartment.fallbackForwardDepartment).to.be.equal(fallbackDepartment._id);
});

after(async () => {
await Promise.all([
deleteDepartment(fallbackDepartment._id),
deleteDepartment(initialDepartment._id),
deleteVisitor(newVisitor._id),
closeOmnichannelRoom(latestRoom._id),
]);
});

it('should redirect chat to fallback department when all agents in the initial department are offline', async () => {
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');

newVisitor = await createVisitor(initialDepartment._id);
const newRoom = await createLivechatRoom(newVisitor.token);

latestRoom = await getLivechatRoomInfo(newRoom._id);

expect(latestRoom).to.have.property('departmentId');
expect(latestRoom.departmentId).to.be.equal(fallbackDepartment._id);
});
});
(IS_EE ? it : it.skip)('system messages sent on transfer should be properly generated', async () => {
const messagesList = await fetchMessages(roomId, visitorToken);

Expand Down
Loading