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;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user