-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for empty bio field and modify mocha configuration (incomplete)
- Added a new test file to check the behavior when updating a user's bio to an empty field. - Altered .mocharc.js configuration to include the new test file for execution. - The update is still a work in progress and may need further adjustments.
- Loading branch information
1 parent
0c4fcec
commit cec3761
Showing
3 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/meteor/tests/server/methods/users/saveUserProfile.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters