Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 15, 2020
1 parent e367c54 commit 7d86be2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ usersAPI.create = async function (caller, data) {
};

usersAPI.update = async function (caller, data) {
if (!data || !data.uid) {
throw new Error('[[error:invalid-data]]');
}
if (!caller.uid) {
throw new Error('[[error:invalid-uid]]');
}
const oldUserData = await user.getUserFields(data.uid, ['email', 'username']);
if (!oldUserData || !oldUserData.username) {
throw new Error('[[error:invalid-data]]');
Expand Down Expand Up @@ -66,6 +72,7 @@ usersAPI.update = async function (caller, data) {
if (userData.username !== oldUserData.username) {
await log('username-change', { oldUsername: oldUserData.username, newUsername: userData.username });
}
return userData;
};

usersAPI.delete = async function (caller, data) {
Expand Down
4 changes: 2 additions & 2 deletions test/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ describe('User', function () {

describe('not logged in', function () {
it('should return error if not logged in', function (done) {
socketUser.updateProfile({ uid: 0 }, {}, function (err) {
socketUser.updateProfile({ uid: 0 }, { uid: 1 }, function (err) {
assert.equal(err.message, '[[error:invalid-uid]]');
done();
});
Expand Down Expand Up @@ -806,7 +806,7 @@ describe('User', function () {
birthday: '01/01/1980',
signature: 'nodebb is good',
};
socketUser.updateProfile({ uid: uid }, data, function (err, result) {
socketUser.updateProfile({ uid: uid }, { ...data, password: '123456' }, function (err, result) {
assert.ifError(err);

assert.equal(result.username, 'updatedUserName');
Expand Down

0 comments on commit 7d86be2

Please sign in to comment.