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

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
import { expect } from 'chai';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
const modelsMock = {
'Users': {
findOneAgentById: sinon.stub(),
findOneByUsername: sinon.stub(),
},
'LivechatContacts': {
findOneById: sinon.stub(),
insertOne: sinon.stub(),
upsertContact: sinon.stub(),
updateContact: sinon.stub(),
findContactMatchingVisitor: sinon.stub(),
},
'LivechatRooms': {
findNewestByVisitorIdOrToken: sinon.stub(),
setContactIdByVisitorIdOrToken: sinon.stub(),
findByVisitorId: sinon.stub(),
},
'LivechatVisitors': {
findOneById: sinon.stub(),
updateById: sinon.stub(),
updateOne: sinon.stub(),
getVisitorByToken: sinon.stub(),
findOneGuestByEmailAddress: sinon.stub(),
},
'LivechatCustomField': {
findByScope: sinon.stub(),
},
'@global': true,
};
const { registerContact } = proxyquire.noCallThru().load('./registerContact', {
'meteor/meteor': sinon.stub(),
'@rocket.chat/models': modelsMock,
'@rocket.chat/tools': { wrapExceptions: sinon.stub() },
});
describe('registerContact', () => {
beforeEach(() => {
modelsMock.Users.findOneByUsername.reset();
modelsMock.LivechatVisitors.getVisitorByToken.reset();
modelsMock.LivechatVisitors.updateOne.reset();
modelsMock.LivechatVisitors.findOneGuestByEmailAddress.reset();
modelsMock.LivechatCustomField.findByScope.reset();
modelsMock.LivechatRooms.findByVisitorId.reset();
});
it(`should throw an error if there's no token`, async () => {
modelsMock.Users.findOneByUsername.returns(undefined);
await expect(
registerContact({
email: 'test@test.com',
username: 'username',
name: 'Name',
contactManager: {
username: 'unknown',
},
}),
).to.eventually.be.rejectedWith('error-invalid-contact-data');
});
it(`should throw an error if the token is not a string`, async () => {
modelsMock.Users.findOneByUsername.returns(undefined);
await expect(
registerContact({
token: 15,
email: 'test@test.com',
username: 'username',
name: 'Name',
contactManager: {
username: 'unknown',
},
}),
).to.eventually.be.rejectedWith('error-invalid-contact-data');
});
it(`should throw an error if there's an invalid manager username`, async () => {
modelsMock.Users.findOneByUsername.returns(undefined);
await expect(
registerContact({
token: 'token',
email: 'test@test.com',
username: 'username',
name: 'Name',
contactManager: {
username: 'unknown',
},
}),
).to.eventually.be.rejectedWith('error-contact-manager-not-found');
});
it(`should throw an error if the manager username does not belong to a livechat agent`, async () => {
modelsMock.Users.findOneByUsername.returns({ roles: ['user'] });
await expect(
registerContact({
token: 'token',
email: 'test@test.com',
username: 'username',
name: 'Name',
contactManager: {
username: 'username',
},
}),
).to.eventually.be.rejectedWith('error-invalid-contact-manager');
});
it('should register a contact when passing valid data', async () => {
modelsMock.LivechatVisitors.getVisitorByToken.returns({ _id: 'visitor1' });
modelsMock.LivechatCustomField.findByScope.returns({ toArray: () => [] });
modelsMock.LivechatRooms.findByVisitorId.returns({ toArray: () => [] });
modelsMock.LivechatVisitors.updateOne.returns(undefined);
await expect(
registerContact({
token: 'token',
email: 'test@test.com',
username: 'username',
name: 'Name',
}),
).to.eventually.be.equal('visitor1');
});
});