|
|
|
|
@ -1,22 +1,37 @@ |
|
|
|
|
/* eslint-env mocha */ |
|
|
|
|
|
|
|
|
|
import type { ILivechatAgent, ILivechatBusinessHour } from '@rocket.chat/core-typings'; |
|
|
|
|
import { ILivechatAgentStatus, LivechatBusinessHourBehaviors, LivechatBusinessHourTypes } from '@rocket.chat/core-typings'; |
|
|
|
|
import type { ILivechatAgent, ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings'; |
|
|
|
|
import { LivechatBusinessHourBehaviors, LivechatBusinessHourTypes, ILivechatAgentStatus } from '@rocket.chat/core-typings'; |
|
|
|
|
import { expect } from 'chai'; |
|
|
|
|
|
|
|
|
|
import { getCredentials, api, request, credentials } from '../../../data/api-data'; |
|
|
|
|
import { saveBusinessHour } from '../../../data/livechat/business-hours'; |
|
|
|
|
import { updateEESetting, updatePermission, updateSetting } from '../../../data/permissions.helper'; |
|
|
|
|
import { |
|
|
|
|
getDefaultBusinessHour, |
|
|
|
|
removeAllCustomBusinessHours, |
|
|
|
|
saveBusinessHour, |
|
|
|
|
openOrCloseBusinessHour, |
|
|
|
|
createCustomBusinessHour, |
|
|
|
|
getCustomBusinessHourById, |
|
|
|
|
getWorkHours, |
|
|
|
|
} from '../../../data/livechat/businessHours'; |
|
|
|
|
import { removePermissionFromAllRoles, restorePermissionToRoles, updateSetting, updateEESetting } from '../../../data/permissions.helper'; |
|
|
|
|
import { IS_EE } from '../../../e2e/config/constants'; |
|
|
|
|
import { |
|
|
|
|
addOrRemoveAgentFromDepartment, |
|
|
|
|
archiveDepartment, |
|
|
|
|
createDepartmentWithAnOnlineAgent, |
|
|
|
|
disableDepartment, |
|
|
|
|
getDepartmentById, |
|
|
|
|
deleteDepartment, |
|
|
|
|
} from '../../../data/livechat/department'; |
|
|
|
|
import { sleep } from '../../../../lib/utils/sleep'; |
|
|
|
|
import { createUser, deleteUser, getMe, login } from '../../../data/users.helper'; |
|
|
|
|
import { createAgent, makeAgentAvailable } from '../../../data/livechat/rooms'; |
|
|
|
|
import { sleep } from '../../../../lib/utils/sleep'; |
|
|
|
|
import { getDefaultBusinessHour, openOrCloseBusinessHour, getWorkHours } from '../../../data/livechat/businessHours'; |
|
|
|
|
import type { IUserCredentialsHeader } from '../../../data/user'; |
|
|
|
|
import { password } from '../../../data/user'; |
|
|
|
|
import { removeAgent } from '../../../data/livechat/users'; |
|
|
|
|
|
|
|
|
|
describe('[CE] LIVECHAT - business hours', function () { |
|
|
|
|
describe('LIVECHAT - business hours', function () { |
|
|
|
|
this.retries(0); |
|
|
|
|
|
|
|
|
|
before((done) => getCredentials(done)); |
|
|
|
|
@ -28,14 +43,15 @@ describe('[CE] LIVECHAT - business hours', function () { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let defaultBhId: any; |
|
|
|
|
describe('livechat/business-hour', () => { |
|
|
|
|
describe('[CE] livechat/business-hour', () => { |
|
|
|
|
it('should fail when user doesnt have view-livechat-business-hours permission', async () => { |
|
|
|
|
await updatePermission('view-livechat-business-hours', []); |
|
|
|
|
await removePermissionFromAllRoles('view-livechat-business-hours'); |
|
|
|
|
const response = await request.get(api('livechat/business-hour')).set(credentials).expect(403); |
|
|
|
|
expect(response.body.success).to.be.false; |
|
|
|
|
|
|
|
|
|
await restorePermissionToRoles('view-livechat-business-hours'); |
|
|
|
|
}); |
|
|
|
|
it('should fail when business hour type is not a valid BH type', async () => { |
|
|
|
|
await updatePermission('view-livechat-business-hours', ['admin', 'livechat-manager']); |
|
|
|
|
const response = await request.get(api('livechat/business-hour')).set(credentials).query({ type: 'invalid' }).expect(200); |
|
|
|
|
expect(response.body.success).to.be.true; |
|
|
|
|
expect(response.body.businessHour).to.be.null; |
|
|
|
|
@ -87,14 +103,15 @@ describe('[CE] LIVECHAT - business hours', function () { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
(IS_EE ? describe : describe.skip)('[EE] LIVECHAT - business hours', () => { |
|
|
|
|
(IS_EE ? describe : describe.skip)('[EE] livechat/business-hour', () => { |
|
|
|
|
it('should fail if user doesnt have view-livechat-business-hours permission', async () => { |
|
|
|
|
await updatePermission('view-livechat-business-hours', []); |
|
|
|
|
await removePermissionFromAllRoles('view-livechat-business-hours'); |
|
|
|
|
const response = await request.get(api('livechat/business-hours')).set(credentials).expect(403); |
|
|
|
|
expect(response.body.success).to.be.false; |
|
|
|
|
|
|
|
|
|
await restorePermissionToRoles('view-livechat-business-hours'); |
|
|
|
|
}); |
|
|
|
|
it('should return a list of business hours', async () => { |
|
|
|
|
await updatePermission('view-livechat-business-hours', ['admin', 'livechat-manager']); |
|
|
|
|
const response = await request.get(api('livechat/business-hours')).set(credentials).expect(200); |
|
|
|
|
expect(response.body.success).to.be.true; |
|
|
|
|
expect(response.body.businessHours).to.be.an('array').with.lengthOf.greaterThan(0); |
|
|
|
|
@ -233,6 +250,429 @@ describe('[CE] LIVECHAT - business hours', function () { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Scenario: Assume we have a BH linked to a department, and we archive the department
|
|
|
|
|
// Expected result:
|
|
|
|
|
// 1) If BH is open and only linked to that department, it should be closed
|
|
|
|
|
// 2) If BH is open and linked to other departments, it should remain open
|
|
|
|
|
// 3) Agents within the archived department should be assigned to default BH
|
|
|
|
|
// 3.1) We'll also need to handle the case where if an agent is assigned to "dep1"
|
|
|
|
|
// and "dep2" and both these depts are connected to same BH, then in this case after
|
|
|
|
|
// archiving "dep1", we'd still need to BH within this user's cache since he's part of
|
|
|
|
|
// "dep2" which is linked to BH
|
|
|
|
|
(IS_EE ? describe : describe.skip)('[EE] BH operations post department archiving', () => { |
|
|
|
|
let defaultBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let customBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let deptLinkedToCustomBH: ILivechatDepartment; |
|
|
|
|
let agentLinkedToDept: Awaited<ReturnType<typeof createDepartmentWithAnOnlineAgent>>['agent']; |
|
|
|
|
|
|
|
|
|
before(async () => { |
|
|
|
|
await updateSetting('Livechat_business_hour_type', LivechatBusinessHourBehaviors.MULTIPLE); |
|
|
|
|
// wait for the callbacks to be registered
|
|
|
|
|
await sleep(1000); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
beforeEach(async () => { |
|
|
|
|
// cleanup any existing business hours
|
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
|
|
|
|
|
// get default business hour
|
|
|
|
|
defaultBusinessHour = await getDefaultBusinessHour(); |
|
|
|
|
|
|
|
|
|
// close default business hour
|
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, false); |
|
|
|
|
|
|
|
|
|
// create custom business hour and link it to a department
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([department._id]); |
|
|
|
|
agentLinkedToDept = agent; |
|
|
|
|
deptLinkedToCustomBH = department; |
|
|
|
|
|
|
|
|
|
// open custom business hour
|
|
|
|
|
await openOrCloseBusinessHour(customBusinessHour, true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon archiving a department, if BH is open and only linked to that department, it should be closed', async () => { |
|
|
|
|
// archive department
|
|
|
|
|
await archiveDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if department is archived and BH link is removed
|
|
|
|
|
const department = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(department).to.be.an('object'); |
|
|
|
|
expect(department).to.have.property('archived', true); |
|
|
|
|
expect(department.businessHourId).to.be.undefined; |
|
|
|
|
|
|
|
|
|
// verify if BH is closed
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', false); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').that.is.empty; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon archiving a department, if BH is open and linked to other departments, it should remain open', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
// archive department
|
|
|
|
|
await archiveDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if department is archived and BH link is removed
|
|
|
|
|
const archivedDepartment = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(archivedDepartment).to.be.an('object'); |
|
|
|
|
expect(archivedDepartment).to.have.property('archived', true); |
|
|
|
|
expect(archivedDepartment.businessHourId).to.be.undefined; |
|
|
|
|
// verify if other department is not archived and BH link is not removed
|
|
|
|
|
const otherDepartment = await getDepartmentById(department._id); |
|
|
|
|
expect(otherDepartment).to.be.an('object'); |
|
|
|
|
expect(otherDepartment.businessHourId).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon archiving a department, agents within the archived department should be assigned to default BH', async () => { |
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, true); |
|
|
|
|
|
|
|
|
|
// archive department
|
|
|
|
|
await archiveDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(defaultBusinessHour._id); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon archiving a department, overlapping agents should still have BH within their cache', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
// create overlapping agent by adding previous agent to newly created department
|
|
|
|
|
await addOrRemoveAgentFromDepartment( |
|
|
|
|
department._id, |
|
|
|
|
{ |
|
|
|
|
agentId: agentLinkedToDept.user._id, |
|
|
|
|
username: agentLinkedToDept.user.username || '', |
|
|
|
|
}, |
|
|
|
|
true, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// archive department
|
|
|
|
|
await archiveDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if department is archived and BH link is removed
|
|
|
|
|
const archivedDepartment = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(archivedDepartment).to.be.an('object'); |
|
|
|
|
expect(archivedDepartment).to.have.property('archived', true); |
|
|
|
|
expect(archivedDepartment.businessHourId).to.be.undefined; |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]?._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// verify if overlapping agent still has BH within his cache
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if other agent still has BH within his cache
|
|
|
|
|
const otherAgent: ILivechatAgent = await getMe(agent.credentials as any); |
|
|
|
|
expect(otherAgent).to.be.an('object'); |
|
|
|
|
expect(otherAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(otherAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(async () => { |
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
await deleteUser(agentLinkedToDept.user); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
(IS_EE ? describe : describe.skip)('[EE] BH operations post department disablement', () => { |
|
|
|
|
let defaultBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let customBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let deptLinkedToCustomBH: ILivechatDepartment; |
|
|
|
|
let agentLinkedToDept: Awaited<ReturnType<typeof createDepartmentWithAnOnlineAgent>>['agent']; |
|
|
|
|
|
|
|
|
|
before(async () => { |
|
|
|
|
await updateSetting('Livechat_business_hour_type', LivechatBusinessHourBehaviors.MULTIPLE); |
|
|
|
|
// wait for the callbacks to be registered
|
|
|
|
|
await sleep(1000); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
beforeEach(async () => { |
|
|
|
|
// cleanup any existing business hours
|
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
|
|
|
|
|
// get default business hour
|
|
|
|
|
defaultBusinessHour = await getDefaultBusinessHour(); |
|
|
|
|
|
|
|
|
|
// close default business hour
|
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, false); |
|
|
|
|
|
|
|
|
|
// create custom business hour and link it to a department
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([department._id]); |
|
|
|
|
agentLinkedToDept = agent; |
|
|
|
|
deptLinkedToCustomBH = department; |
|
|
|
|
|
|
|
|
|
// open custom business hour
|
|
|
|
|
await openOrCloseBusinessHour(customBusinessHour, true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon disabling a department, if BH is open and only linked to that department, it should be closed', async () => { |
|
|
|
|
// disable department
|
|
|
|
|
await disableDepartment(deptLinkedToCustomBH); |
|
|
|
|
|
|
|
|
|
// verify if BH link is removed
|
|
|
|
|
const department = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(department).to.be.an('object'); |
|
|
|
|
expect(department.businessHourId).to.be.undefined; |
|
|
|
|
|
|
|
|
|
// verify if BH is closed
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH.active).to.be.false; |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').that.is.empty; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon disabling a department, if BH is open and linked to other departments, it should remain open', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
// disable department
|
|
|
|
|
await disableDepartment(deptLinkedToCustomBH); |
|
|
|
|
|
|
|
|
|
// verify if BH link is removed
|
|
|
|
|
const disabledDepartment = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(disabledDepartment).to.be.an('object'); |
|
|
|
|
expect(disabledDepartment.businessHourId).to.be.undefined; |
|
|
|
|
|
|
|
|
|
// verify if other department BH link is not removed
|
|
|
|
|
const otherDepartment = await getDepartmentById(department._id); |
|
|
|
|
expect(otherDepartment).to.be.an('object'); |
|
|
|
|
expect(otherDepartment.businessHourId).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon disabling a department, agents within the disabled department should be assigned to default BH', async () => { |
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, true); |
|
|
|
|
|
|
|
|
|
// disable department
|
|
|
|
|
await disableDepartment(deptLinkedToCustomBH); |
|
|
|
|
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(defaultBusinessHour._id); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon disabling a department, overlapping agents should still have BH within their cache', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
// create overlapping agent by adding previous agent to newly created department
|
|
|
|
|
await addOrRemoveAgentFromDepartment( |
|
|
|
|
department._id, |
|
|
|
|
{ |
|
|
|
|
agentId: agentLinkedToDept.user._id, |
|
|
|
|
username: agentLinkedToDept.user.username || '', |
|
|
|
|
}, |
|
|
|
|
true, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// disable department
|
|
|
|
|
await disableDepartment(deptLinkedToCustomBH); |
|
|
|
|
|
|
|
|
|
// verify if BH link is removed
|
|
|
|
|
const disabledDepartment = await getDepartmentById(deptLinkedToCustomBH._id); |
|
|
|
|
expect(disabledDepartment).to.be.an('object'); |
|
|
|
|
expect(disabledDepartment.businessHourId).to.be.undefined; |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]?._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// verify if overlapping agent still has BH within his cache
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if other agent still has BH within his cache
|
|
|
|
|
const otherAgent: ILivechatAgent = await getMe(agent.credentials as any); |
|
|
|
|
expect(otherAgent).to.be.an('object'); |
|
|
|
|
expect(otherAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(otherAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(async () => { |
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
await deleteUser(agentLinkedToDept.user); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
(IS_EE ? describe : describe.skip)('[EE] BH operations post department removal', () => { |
|
|
|
|
let defaultBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let customBusinessHour: ILivechatBusinessHour; |
|
|
|
|
let deptLinkedToCustomBH: ILivechatDepartment; |
|
|
|
|
let agentLinkedToDept: Awaited<ReturnType<typeof createDepartmentWithAnOnlineAgent>>['agent']; |
|
|
|
|
|
|
|
|
|
before(async () => { |
|
|
|
|
await updateSetting('Livechat_business_hour_type', LivechatBusinessHourBehaviors.MULTIPLE); |
|
|
|
|
// wait for the callbacks to be registered
|
|
|
|
|
await sleep(1000); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
beforeEach(async () => { |
|
|
|
|
// cleanup any existing business hours
|
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
|
|
|
|
|
// get default business hour
|
|
|
|
|
defaultBusinessHour = await getDefaultBusinessHour(); |
|
|
|
|
|
|
|
|
|
// close default business hour
|
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, false); |
|
|
|
|
|
|
|
|
|
// create custom business hour and link it to a department
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([department._id]); |
|
|
|
|
agentLinkedToDept = agent; |
|
|
|
|
deptLinkedToCustomBH = department; |
|
|
|
|
|
|
|
|
|
// open custom business hour
|
|
|
|
|
await openOrCloseBusinessHour(customBusinessHour, true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon deleting a department, if BH is open and only linked to that department, it should be closed', async () => { |
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if BH is closed
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH.active).to.be.false; |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').that.is.empty; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon deleting a department, if BH is open and linked to other departments, it should remain open', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if other department BH link is not removed
|
|
|
|
|
const otherDepartment = await getDepartmentById(department._id); |
|
|
|
|
expect(otherDepartment).to.be.an('object'); |
|
|
|
|
expect(otherDepartment.businessHourId).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon deleting a department, agents within the disabled department should be assigned to default BH', async () => { |
|
|
|
|
await openOrCloseBusinessHour(defaultBusinessHour, true); |
|
|
|
|
|
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(defaultBusinessHour._id); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('upon deleting a department, overlapping agents should still have BH within their cache', async () => { |
|
|
|
|
// create another department and link it to the same BH
|
|
|
|
|
const { department, agent } = await createDepartmentWithAnOnlineAgent(); |
|
|
|
|
await removeAllCustomBusinessHours(); |
|
|
|
|
customBusinessHour = await createCustomBusinessHour([deptLinkedToCustomBH._id, department._id]); |
|
|
|
|
|
|
|
|
|
// create overlapping agent by adding previous agent to newly created department
|
|
|
|
|
await addOrRemoveAgentFromDepartment( |
|
|
|
|
department._id, |
|
|
|
|
{ |
|
|
|
|
agentId: agentLinkedToDept.user._id, |
|
|
|
|
username: agentLinkedToDept.user.username || '', |
|
|
|
|
}, |
|
|
|
|
true, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
await deleteDepartment(deptLinkedToCustomBH._id); |
|
|
|
|
|
|
|
|
|
// verify if BH is still open
|
|
|
|
|
const latestCustomBH = await getCustomBusinessHourById(customBusinessHour._id); |
|
|
|
|
expect(latestCustomBH).to.be.an('object'); |
|
|
|
|
expect(latestCustomBH).to.have.property('active', true); |
|
|
|
|
expect(latestCustomBH.departments).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestCustomBH?.departments?.[0]?._id).to.be.equal(department._id); |
|
|
|
|
|
|
|
|
|
// verify if overlapping agent still has BH within his cache
|
|
|
|
|
const latestAgent: ILivechatAgent = await getMe(agentLinkedToDept.credentials as any); |
|
|
|
|
expect(latestAgent).to.be.an('object'); |
|
|
|
|
expect(latestAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(latestAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// verify if other agent still has BH within his cache
|
|
|
|
|
const otherAgent: ILivechatAgent = await getMe(agent.credentials as any); |
|
|
|
|
expect(otherAgent).to.be.an('object'); |
|
|
|
|
expect(otherAgent.openBusinessHours).to.be.an('array').of.length(1); |
|
|
|
|
expect(otherAgent?.openBusinessHours?.[0]).to.be.equal(customBusinessHour._id); |
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
await deleteDepartment(department._id); |
|
|
|
|
await deleteUser(agent.user); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(async () => { |
|
|
|
|
await deleteUser(agentLinkedToDept.user); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
describe('BH behavior upon new agent creation/deletion', () => { |
|
|
|
|
let defaultBH: ILivechatBusinessHour; |
|
|
|
|
let agent: ILivechatAgent; |
|
|
|
|
|