Makes sure the location in results has the proper objectId

This commit is contained in:
Florent Vilmart
2016-03-16 20:20:08 -04:00
parent d6af77b170
commit 461ddcbd05
2 changed files with 28 additions and 1 deletions

View File

@@ -1438,6 +1438,32 @@ describe('Parse.User testing', () => {
});
});
it('should fail linking with existing', (done) => {
var provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
Parse.User._logInWith("facebook", {
success: function(model) {
let userId = model.id;
Parse.User.logOut().then(() => {
request.post({
url:Parse.serverURL+'/classes/_User',
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-REST-API-Key': 'rest'
},
json: {authData: {facebook: provider.authData}}
}, (err,res, body) => {
// make sure the location header is properly set
expect(userId).not.toBeUndefined();
expect(body.objectId).toEqual(userId);
expect(res.headers.location).toEqual(Parse.serverURL+'/users/'+userId);
done();
});
});
}
});
});
it('should have authData in beforeSave and afterSave', (done) => {
Parse.Cloud.beforeSave('_User', (request, response) => {

View File

@@ -285,11 +285,12 @@ RestWrite.prototype.handleAuthData = function(authData) {
// Login with auth data
// Short circuit
delete results[0].password;
// need to set the objectId first otherwise location has trailing undefined
this.data.objectId = results[0].objectId;
this.response = {
response: results[0],
location: this.location()
};
this.data.objectId = results[0].objectId;
} else if (this.query && this.query.objectId) {
// Trying to update auth data but users
// are different