The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/livechat/server/lib/contacts/validateContactManager.spec.ts

32 lines
996 B

import { expect } from 'chai';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
const modelsMock = {
Users: {
findOneAgentById: sinon.stub(),
},
};
const { validateContactManager } = proxyquire.noCallThru().load('./validateContactManager', {
'@rocket.chat/models': modelsMock,
});
describe('validateContactManager', () => {
beforeEach(() => {
modelsMock.Users.findOneAgentById.reset();
});
it('should throw an error if the user does not exist', async () => {
modelsMock.Users.findOneAgentById.resolves(undefined);
await expect(validateContactManager('any_id')).to.be.rejectedWith('error-contact-manager-not-found');
});
it('should not throw an error if the user has the "livechat-agent" role', async () => {
const user = { _id: 'userId' };
modelsMock.Users.findOneAgentById.resolves(user);
await expect(validateContactManager('userId')).to.not.be.rejected;
expect(modelsMock.Users.findOneAgentById.getCall(0).firstArg).to.be.equal('userId');
});
});