forked from strongloop/loopback
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request strongloop#4108 from horstmannmat/fix_4105
Fix crash when modifying a user with an unknown id
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -63,6 +63,39 @@ describe('users - integration', function() { | |
}); | ||
}); | ||
|
||
it('returns error when replacing user that does not exist', function() { | ||
const credentials = {email: '[email protected]', password: 'pass'}; | ||
const User = app.models.User; | ||
let user; | ||
|
||
let hookEnabled = true; | ||
User.beforeRemote('replaceOrCreate', (ctx, unused, next) => { | ||
// don't affect subsequent tests! | ||
if (!hookEnabled) return; | ||
hookEnabled = false; | ||
|
||
// Delete the user *AFTER* the PUT request was authorized | ||
// but *BEFORE* replaceOrCreate is invoked | ||
User.deleteById(user.id, next); | ||
}); | ||
|
||
return User.create(credentials) | ||
.then(u => { | ||
user = u; | ||
return User.login(credentials); | ||
}) | ||
.then(token => { | ||
return this.put('/api/users') | ||
.set('Authorization', token.id) | ||
.send({ | ||
id: user.id, | ||
email: '[email protected]', | ||
password: 'x', | ||
}) | ||
.expect(404); | ||
}); | ||
}); | ||
|
||
it('should create post for a given user', function(done) { | ||
var url = '/api/users/' + userId + '/posts?access_token=' + accessToken; | ||
this.post(url) | ||
|