Skip to content

Commit e19da0e

Browse files
fatbattkdplewis
authored andcommitted
Fix Facebook login so it properly distinguishes between new and existing users. (#845)
* Fixes issue #831. * Adds test case and modify promise resolve for issue #831. * Modify REST returnStatus property to be non-clashing for issue #831.
1 parent c68ddad commit e19da0e

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

integration/test/ParseUserTest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('Parse User', () => {
6666
it('can sign up users via static method', (done) => {
6767
Parse.User.signUp('asdf', 'zxcv').then((user) => {
6868
assert(user.getSessionToken());
69+
expect(user.existed()).toBe(false);
6970
done();
7071
});
7172
});
@@ -76,6 +77,7 @@ describe('Parse User', () => {
7677
user.setUsername('zxcv');
7778
user.signUp().then((user) => {
7879
assert(user.getSessionToken());
80+
expect(user.existed()).toBe(false);
7981
done();
8082
});
8183
});
@@ -101,6 +103,7 @@ describe('Parse User', () => {
101103
return Parse.User.logIn('asdf', 'zxcv');
102104
}).then((user) => {
103105
assert.equal(user.get('username'), 'asdf');
106+
expect(user.existed()).toBe(true);
104107
done();
105108
});
106109
});

src/ParseObject.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,9 @@ const DefaultController = {
21342134

21352135
const RESTController = CoreManager.getRESTController();
21362136
const stateController = CoreManager.getObjectStateController();
2137+
2138+
options = options || {};
2139+
options.returnStatus = options.returnStatus || true;
21372140
if (Array.isArray(target)) {
21382141
if (target.length < 1) {
21392142
return Promise.resolve([]);
@@ -2199,9 +2202,11 @@ const DefaultController = {
21992202
batchReady.push(ready);
22002203
const task = function() {
22012204
ready.resolve();
2202-
return batchReturned.then((responses, status) => {
2205+
return batchReturned.then((responses) => {
22032206
if (responses[index].hasOwnProperty('success')) {
22042207
const objectId = responses[index].success.objectId;
2208+
const status = responses[index]._status;
2209+
delete responses[index]._status;
22052210
mapIdForPin[objectId] = obj._localId;
22062211
obj._handleSaveResponse(responses[index].success, status);
22072212
} else {
@@ -2228,9 +2233,7 @@ const DefaultController = {
22282233
return params;
22292234
})
22302235
}, options);
2231-
}).then((response, status) => {
2232-
batchReturned.resolve(response, status);
2233-
}, (error) => {
2236+
}).then(batchReturned.resolve, (error) => {
22342237
batchReturned.reject(new ParseError(ParseError.INCORRECT_TYPE, error.message));
22352238
});
22362239

@@ -2258,7 +2261,9 @@ const DefaultController = {
22582261
params.path,
22592262
params.body,
22602263
options
2261-
).then((response, status) => {
2264+
).then((response) => {
2265+
const status = response._status;
2266+
delete response._status;
22622267
targetCopy._handleSaveResponse(response, status);
22632268
}, (error) => {
22642269
targetCopy._handleSaveError();

src/RESTController.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type RequestOptions = {
1616
useMasterKey?: boolean;
1717
sessionToken?: string;
1818
installationId?: string;
19+
returnStatus?: boolean;
1920
batchSize?: number;
2021
include?: any;
2122
progress?: any;
@@ -255,8 +256,12 @@ const RESTController = {
255256
}
256257

257258
const payloadString = JSON.stringify(payload);
258-
return RESTController.ajax(method, url, payloadString, {}, options).then(({ response }) => {
259-
return response;
259+
return RESTController.ajax(method, url, payloadString, {}, options).then(({ response, status })=>{
260+
if (options.returnStatus) {
261+
return { ...response, _status: status };
262+
} else {
263+
return response;
264+
}
260265
});
261266
}).catch(function(response: { responseText: string }) {
262267
// Transform the error into an instance of ParseError by trying to parse

src/__tests__/ParseUser-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ describe('ParseUser', () => {
881881
ParseUser._clearCache();
882882
CoreManager.setRESTController({
883883
request(method, path, body, options) {
884-
expect(options).toEqual({ useMasterKey: true });
884+
expect(options).toEqual(expect.objectContaining({ useMasterKey: true }));
885885
return Promise.resolve({
886886
objectId: 'uid5',
887887
sessionToken: 'r:123abc',

src/__tests__/RESTController-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ describe('RESTController', () => {
362362
});
363363
});
364364

365+
it('includes the status code when requested', (done) => {
366+
RESTController._setXHR(mockXHR([{ status: 200, response: { success: true }}]));
367+
RESTController.request('POST', 'users', {}, { returnStatus: true })
368+
.then((response) => {
369+
expect(response).toEqual(expect.objectContaining({ success: true }));
370+
expect(response._status).toBe(200);
371+
done();
372+
});
373+
});
374+
365375
it('throws when attempted to use an unprovided master key', () => {
366376
CoreManager.set('MASTER_KEY', undefined);
367377
const xhr = {

0 commit comments

Comments
 (0)