Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return correct response if user was not updated #820

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/models/src/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ userSchema.methods.updateUser = function updateUser ({ email, language, name, cu
return user.save();
})
.then(function (updatedUser) {
if (updatedUser.updated === false) {
return updatedUser;
}

return { updated: true, signOut, messages: msgs, updatedUser };
})
.catch(function (err) {
Expand Down
18 changes: 18 additions & 0 deletions tests/tests/004-users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ describe('openSenseMap API Routes: /users', function () {
});
});

it('should return that no changed properties are applied and user remains unchanged', function () {
return chakram
.put(
`${BASE_URL}/users/me`,
{ name: 'new Name' },
{ headers: { Authorization: `Bearer ${jwt}` } }
)
.then(function (response) {
expect(response).to.have.status(200);
expect(response).to.have.json(
'message',
'No changed properties supplied. User remains unchanged.'
);

return chakram.wait();
});
});

it('should deny to change name to existing name', function () {
return chakram.put(`${BASE_URL}/users/me`, { name: 'this is just a nickname', currentPassword: '12345678' }, { headers: { 'Authorization': `Bearer ${jwt}` } })
.then(function (response) {
Expand Down
Loading