diff --git a/apps/meteor/.mocharc.js b/apps/meteor/.mocharc.js index f11b315b8cef..131bda9b66d5 100644 --- a/apps/meteor/.mocharc.js +++ b/apps/meteor/.mocharc.js @@ -37,5 +37,6 @@ module.exports = { 'tests/unit/server/**/*.tests.ts', 'tests/unit/server/**/*.spec.ts', 'app/api/**/*.spec.ts', + 'apps/meteor/tests/**/*.spec.ts', ], }; diff --git a/apps/meteor/tests/server/methods/users/saveUserProfile.spec.ts b/apps/meteor/tests/server/methods/users/saveUserProfile.spec.ts new file mode 100644 index 000000000000..58c6b3a774bf --- /dev/null +++ b/apps/meteor/tests/server/methods/users/saveUserProfile.spec.ts @@ -0,0 +1,39 @@ +import { expect } from 'chai'; +import proxyquire from 'proxyquire'; +import sinon from 'sinon'; + +const stubs = { + Users: { + findOneById: sinon.stub(), + setBio: sinon.stub(), + }, + rcSettings: { + get: sinon.stub(), + }, +}; +const AccountsMock = { setPasswordAsync: sinon.stub() }; +const checkMock = sinon.stub(); +const MatchMock = { Maybe: sinon.stub() }; +const MeteorMock = { call: sinon.stub(), Error: sinon.stub() }; + +const { saveUserProfile } = proxyquire.noCallThru().load('../../../../server/methods/saveUserProfile', { + 'meteor/accounts-base': { 'Accounts': AccountsMock, '@global': true }, + 'meteor/check': { 'check': checkMock, 'Match': MatchMock, '@global': true }, + '@rocket.chat/models': { Users: stubs.Users }, + '../../../../app/settings/server': { settings: stubs.rcSettings }, + 'meteor/meteor': { 'Meteor': MeteorMock, '@global': true }, +}); + +describe('Users - saveUserProfile (Bio Update)', () => { + beforeEach(() => { + sinon.restore(); + stubs.rcSettings.get.withArgs('Accounts_AllowUserProfileChange').returns(true); + }); + + it('should update the bio to an empty string and call setBio', async () => { + stubs.Users.findOneById.resolves({ _id: 'userId', bio: 'Old bio text' }); + stubs.Users.setBio.resolves(true); + await saveUserProfile.call({ userId: 'userId' }, { bio: '' }, {}); + expect(stubs.Users.setBio.calledWith('userId', '')).to.be.true; + }); +}); diff --git a/apps/meteor/tests/unit/server/users/saveUserIdentity.spec.ts b/apps/meteor/tests/unit/server/users/saveUserIdentity.spec.ts index 4412b90493a5..b91165fb3ca9 100644 --- a/apps/meteor/tests/unit/server/users/saveUserIdentity.spec.ts +++ b/apps/meteor/tests/unit/server/users/saveUserIdentity.spec.ts @@ -12,7 +12,6 @@ const stubs = { updateUserReferences: sinon.stub(), setUsername: sinon.stub(), setRealName: sinon.stub(), - setBio: sinon.stub(), validateName: sinon.stub(), FileUpload: sinon.stub(), }; @@ -132,17 +131,4 @@ describe('Users - saveUserIdentity', () => { expect(stubs.updateUserReferences.called).to.be.true; expect(result).to.be.true; }); - - it('should update bio to an empty string and call setBio', async () => { - stubs.findOneUserById.returns({ bio: 'Some bio text', username: 'oldUsername' }); - stubs.setRealName.returns(true); - stubs.setUsername.returns(true); - stubs.setBio = sinon.stub(); - const result = await saveUserIdentity({ _id: 'valid_id', bio: '' }); - expect(stubs.setRealName.called).to.be.false; - expect(stubs.setUsername.called).to.be.false; - expect(stubs.updateUsernameOfEditByUserId.called).to.be.false; - expect(stubs.setBio.calledWith('valid_id', '')).to.be.true; - expect(result).to.be.true; - }); });