snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import { registerModel, BaseRaw } from '@rocket.chat/models';
|
||||
import { expect } from 'chai';
|
||||
import { before, describe, it } from 'mocha';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import { BeforeSaveCannedResponse } from '../../../../../server/hooks/messages/BeforeSaveCannedResponse';
|
||||
|
||||
const createMessage = (msg?: string, extra: any = {}) => ({
|
||||
_id: 'msg-id',
|
||||
rid: 'GENERAL',
|
||||
ts: new Date(),
|
||||
u: {
|
||||
_id: 'user-id',
|
||||
username: 'user',
|
||||
},
|
||||
_updatedAt: new Date(),
|
||||
msg: msg as string,
|
||||
...extra,
|
||||
});
|
||||
|
||||
const createRoom = (extra: any = {}) => ({
|
||||
_id: 'GENERAL',
|
||||
name: 'general',
|
||||
...extra,
|
||||
});
|
||||
|
||||
const createUser = (extra: any = {}) => ({
|
||||
_id: 'user-id',
|
||||
name: 'User Name',
|
||||
username: 'user',
|
||||
emails: [{ address: 'user@user.com' }],
|
||||
...extra,
|
||||
});
|
||||
|
||||
class LivechatVisitorsModel extends BaseRaw<any> {
|
||||
findOneEnabledById() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
class UsersModel extends BaseRaw<any> {
|
||||
override async findOneById(): Promise<any> {
|
||||
return {
|
||||
name: 'John Doe Agent',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const db = {
|
||||
collection: () => ({}),
|
||||
};
|
||||
|
||||
describe('Omnichannel canned responses', () => {
|
||||
before(() => {
|
||||
registerModel('ILivechatVisitorsModel', () => new LivechatVisitorsModel(db as unknown as any, 'visitor'));
|
||||
registerModel('IUsersModel', () => new UsersModel(db as unknown as any, 'user'));
|
||||
});
|
||||
|
||||
it('should do nothing if canned response is disabled', async () => {
|
||||
BeforeSaveCannedResponse.enabled = false;
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom({ t: 'l', servedBy: { _id: 'agent' }, v: { _id: 'visitor' } }),
|
||||
user: createUser(),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', '{{agent.name}}');
|
||||
});
|
||||
|
||||
it('should do nothing if not an omnichannel room', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom(),
|
||||
user: createUser(),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', '{{agent.name}}');
|
||||
});
|
||||
|
||||
it('should do nothing if the message is from a visitor', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom({ t: 'l', servedBy: { _id: 'agent' }, v: { _id: 'visitor' } }),
|
||||
user: createUser({ token: 'visitor-token' }),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', '{{agent.name}}');
|
||||
});
|
||||
|
||||
it('should do nothing if room is not served by an agent', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom({ t: 'l', v: { _id: 'visitor' } }),
|
||||
user: createUser(),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', '{{agent.name}}');
|
||||
});
|
||||
|
||||
it('should do nothing for an empty message', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage(''),
|
||||
room: createRoom({ t: 'l', servedBy: { _id: 'agent' }, v: { _id: 'visitor' } }),
|
||||
user: createUser(),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', '');
|
||||
});
|
||||
|
||||
it('should replace {{agent.name}} without finding the user from DB (sender is the agent of room)', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const usersModel = new UsersModel(db as unknown as any, 'user');
|
||||
const spy = sinon.spy(usersModel, 'findOneById');
|
||||
|
||||
registerModel('IUsersModel', () => usersModel);
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom({ t: 'l', servedBy: { _id: 'agent' }, v: { _id: 'visitor' } }),
|
||||
user: createUser({ _id: 'agent', name: 'User As Agent' }),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', 'User As Agent');
|
||||
expect(spy.called).to.be.false;
|
||||
});
|
||||
|
||||
it('should replace {{agent.name}} when canned response is enabled', async () => {
|
||||
BeforeSaveCannedResponse.enabled = true;
|
||||
|
||||
const usersModel = new UsersModel(db as unknown as any, 'user');
|
||||
const spy = sinon.spy(usersModel, 'findOneById');
|
||||
|
||||
registerModel('IUsersModel', () => usersModel);
|
||||
|
||||
const canned = new BeforeSaveCannedResponse();
|
||||
|
||||
const message = await canned.replacePlaceholders({
|
||||
message: createMessage('{{agent.name}}'),
|
||||
room: createRoom({ t: 'l', servedBy: { _id: 'agent' }, v: { _id: 'visitor' } }),
|
||||
user: createUser(),
|
||||
});
|
||||
|
||||
expect(message).to.have.property('msg', 'John Doe Agent');
|
||||
expect(spy.called).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import { expect } from 'chai';
|
||||
import { describe, it } from 'mocha';
|
||||
import moment from 'moment';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const settingStub = {
|
||||
watch: sinon.stub(),
|
||||
get: sinon.stub(),
|
||||
};
|
||||
|
||||
const queueMonitorStub = {
|
||||
scheduleInquiry: sinon.stub(),
|
||||
};
|
||||
|
||||
const { afterInquiryQueuedFunc: afterInquiryQueued } = proxyquire
|
||||
.noCallThru()
|
||||
.load('../../../../../server/hooks/omnichannel/afterInquiryQueued.ts', {
|
||||
'../../../../server/settings': {
|
||||
settings: settingStub,
|
||||
},
|
||||
'../../lib/omnichannel/QueueInactivityMonitor': {
|
||||
OmnichannelQueueInactivityMonitor: queueMonitorStub,
|
||||
},
|
||||
'../../../../server/lib/omnichannel/hooks': {
|
||||
afterInquiryQueued: { patch: sinon.stub() },
|
||||
},
|
||||
});
|
||||
|
||||
describe('hooks/afterInquiryQueued', () => {
|
||||
beforeEach(() => {
|
||||
queueMonitorStub.scheduleInquiry.resetHistory();
|
||||
settingStub.get.resetHistory();
|
||||
});
|
||||
|
||||
it('should return undefined if no inquiry is passed, or if inquiry doesnt have valid properties', async () => {
|
||||
expect(await afterInquiryQueued(null)).to.be.equal(undefined);
|
||||
expect(await afterInquiryQueued({})).to.be.equal(undefined);
|
||||
expect(await afterInquiryQueued({ _id: 'invalid' })).to.be.equal(undefined);
|
||||
expect(await afterInquiryQueued({ _updatedAt: new Date() }));
|
||||
expect(await afterInquiryQueued({ _updatedAt: null, _id: 'afsd34asdX' })).to.be.equal(undefined);
|
||||
});
|
||||
|
||||
it('should do nothing if timer is set to 0 or less', async () => {
|
||||
const inquiry = {
|
||||
_id: 'afsd34asdX',
|
||||
_updatedAt: new Date(),
|
||||
};
|
||||
|
||||
settingStub.get.returns(0);
|
||||
await afterInquiryQueued(inquiry);
|
||||
expect(queueMonitorStub.scheduleInquiry.callCount).to.be.equal(0);
|
||||
|
||||
settingStub.get.returns(-1);
|
||||
await afterInquiryQueued(inquiry);
|
||||
expect(queueMonitorStub.scheduleInquiry.callCount).to.be.equal(0);
|
||||
});
|
||||
|
||||
it('should call .scheduleInquiry with proper data', async () => {
|
||||
const inquiry = {
|
||||
_id: 'afsd34asdX',
|
||||
_updatedAt: new Date(),
|
||||
};
|
||||
|
||||
settingStub.get.returns(1);
|
||||
await afterInquiryQueued(inquiry);
|
||||
|
||||
const newQueueTime = moment(inquiry._updatedAt).add(1, 'minutes');
|
||||
|
||||
expect(queueMonitorStub.scheduleInquiry.calledWith(inquiry._id, new Date(newQueueTime.format()))).to.be.true;
|
||||
});
|
||||
|
||||
it('should call .scheduleInquiry with proper data when more than 1 min is passed as param', async () => {
|
||||
const inquiry = {
|
||||
_id: 'afv34avzx',
|
||||
_updatedAt: new Date(),
|
||||
};
|
||||
|
||||
settingStub.get.returns(3);
|
||||
await afterInquiryQueued(inquiry);
|
||||
|
||||
const newQueueTime = moment(inquiry._updatedAt).add(3, 'minutes');
|
||||
|
||||
expect(queueMonitorStub.scheduleInquiry.calledWith(inquiry._id, new Date(newQueueTime.format()))).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,181 @@
|
||||
import { expect } from 'chai';
|
||||
import { describe, it } from 'mocha';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const livechatDepartmentStub = {
|
||||
findOneById: sinon.stub(),
|
||||
addDepartmentToUnit: sinon.stub(),
|
||||
removeDepartmentFromUnit: sinon.stub(),
|
||||
};
|
||||
|
||||
const livechatUnitStub = {
|
||||
findOneById: sinon.stub(),
|
||||
decrementDepartmentsCount: sinon.stub(),
|
||||
incrementDepartmentsCount: sinon.stub(),
|
||||
};
|
||||
|
||||
const hasAnyRoleStub = sinon.stub();
|
||||
const getUnitsFromUserStub = sinon.stub();
|
||||
|
||||
const { manageDepartmentUnit } = proxyquire.noCallThru().load('../../../../../server/hooks/omnichannel/manageDepartmentUnit.ts', {
|
||||
'@rocket.chat/omni-core-ee': {
|
||||
getUnitsFromUser: getUnitsFromUserStub,
|
||||
},
|
||||
'../../../../server/lib/authorization/hasRole': {
|
||||
hasAnyRoleAsync: hasAnyRoleStub,
|
||||
},
|
||||
'@rocket.chat/models': {
|
||||
LivechatDepartment: livechatDepartmentStub,
|
||||
LivechatUnit: livechatUnitStub,
|
||||
},
|
||||
});
|
||||
|
||||
describe('hooks/manageDepartmentUnit', () => {
|
||||
beforeEach(() => {
|
||||
livechatDepartmentStub.findOneById.reset();
|
||||
livechatDepartmentStub.addDepartmentToUnit.reset();
|
||||
livechatDepartmentStub.removeDepartmentFromUnit.reset();
|
||||
livechatUnitStub.findOneById.reset();
|
||||
livechatUnitStub.decrementDepartmentsCount.reset();
|
||||
livechatUnitStub.incrementDepartmentsCount.reset();
|
||||
hasAnyRoleStub.reset();
|
||||
});
|
||||
|
||||
it('should not perform any operation when an invalid department is provided', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves(null);
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(['unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it('should not perform any operation if the provided department is already in unit', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(['unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it("should not perform any operation if user is a monitor and can't manage new unit", async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(false);
|
||||
getUnitsFromUserStub.resolves(['unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'new-unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it("should not perform any operation if user is a monitor and can't manage current unit", async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(false);
|
||||
getUnitsFromUserStub.resolves(['new-unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'new-unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it('should not perform any operation if user is an admin/manager but an invalid unit is provided', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
livechatUnitStub.findOneById.resolves(undefined);
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(undefined);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'new-unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it('should remove department from its current unit if user is an admin/manager', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(undefined);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: undefined });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.calledOnceWith('department-id')).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
});
|
||||
|
||||
it('should add department to a unit if user is an admin/manager', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id' });
|
||||
livechatUnitStub.findOneById.resolves({ _id: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(undefined);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.calledOnceWith('department-id', 'unit-id', ['unit-id'])).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it('should move department to a new unit if user is an admin/manager', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
livechatUnitStub.findOneById.resolves({ _id: 'new-unit-id' });
|
||||
hasAnyRoleStub.resolves(true);
|
||||
getUnitsFromUserStub.resolves(undefined);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'new-unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.calledOnceWith('department-id', 'new-unit-id', ['new-unit-id'])).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.calledOnceWith('new-unit-id')).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
});
|
||||
|
||||
it('should remove department from its current unit if user is a monitor that supervises the current unit', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(false);
|
||||
getUnitsFromUserStub.resolves(['unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: undefined });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.notCalled).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.calledOnceWith('department-id')).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
});
|
||||
|
||||
it('should add department to a unit if user is a monitor that supervises the new unit', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id' });
|
||||
livechatUnitStub.findOneById.resolves({ _id: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(false);
|
||||
getUnitsFromUserStub.resolves(['unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.calledOnceWith('department-id', 'unit-id', ['unit-id'])).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.notCalled).to.be.true;
|
||||
});
|
||||
|
||||
it('should move department to a new unit if user is a monitor that supervises the current and new units', async () => {
|
||||
livechatDepartmentStub.findOneById.resolves({ _id: 'department-id', ancestors: ['unit-id'], parentId: 'unit-id' });
|
||||
livechatUnitStub.findOneById.resolves({ _id: 'unit-id' });
|
||||
hasAnyRoleStub.resolves(false);
|
||||
getUnitsFromUserStub.resolves(['unit-id', 'new-unit-id']);
|
||||
|
||||
await manageDepartmentUnit({ userId: 'user-id', departmentId: 'department-id', unitId: 'new-unit-id' });
|
||||
expect(livechatDepartmentStub.addDepartmentToUnit.calledOnceWith('department-id', 'new-unit-id', ['new-unit-id'])).to.be.true;
|
||||
expect(livechatUnitStub.incrementDepartmentsCount.calledOnceWith('new-unit-id')).to.be.true;
|
||||
expect(livechatDepartmentStub.removeDepartmentFromUnit.notCalled).to.be.true;
|
||||
expect(livechatUnitStub.decrementDepartmentsCount.calledOnceWith('unit-id')).to.be.true;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user