Skip to content

Commit

Permalink
regression: fallback offline department (#33009)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <[email protected]>
  • Loading branch information
jessicaschelly and ggazzo committed Aug 8, 2024
1 parent f92ffd8 commit 69661b3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
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

0 comments on commit 69661b3

Please sign in to comment.