Skip to content

Commit 0f3116e

Browse files
committed
Test to show that you can't login with a old facebook user when anonymous
1 parent 2300b21 commit 0f3116e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

spec/RestCreate.spec.js

+51
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,57 @@ describe('rest create', () => {
199199
});
200200
});
201201

202+
it('test facebook login that is already have account and is logged with a anonymous user', (done) => {
203+
var dataAnonymous = {
204+
authData: {
205+
anonymous: {
206+
id: '00000000-0000-0000-0000-000000000001'
207+
}
208+
}
209+
};
210+
var data = {
211+
authData: {
212+
facebook: {
213+
id: '8675309',
214+
access_token: 'jenny'
215+
}
216+
}
217+
};
218+
var newUserSignedUpByFacebookObjectId;
219+
var anonymousResponse;
220+
rest.create(config, auth.nobody(config), '_User', data)
221+
.then((r) => {
222+
console.log('facebook user', r.response);
223+
// facebook user sign up
224+
newUserSignedUpByFacebookObjectId = r.response.objectId;
225+
return rest.create(config, auth.nobody(config), '_User', dataAnonymous);
226+
}).then((r) => {
227+
console.log('anonymous user:', r.response);
228+
// logged anonymous
229+
var anonymousResponse = r.response;
230+
data.authData.objectId = r.response.objectId;
231+
data.authData.anonymous = null;
232+
return rest.update(config, auth.nobody(config), '_User', data.authData.objectId, data);
233+
}).then((r) => {
234+
console.log('login', r);
235+
expect(typeof r.response.objectId).toEqual('string');
236+
expect(typeof r.response.createdAt).toEqual('string');
237+
expect(typeof r.response.username).toEqual('string');
238+
expect(typeof r.response.updatedAt).toEqual('string');
239+
expect(r.response.objectId).toEqual(newUserSignedUpByFacebookObjectId);
240+
return rest.find(config, auth.master(config),
241+
'_Session', {sessionToken: r.response.sessionToken});
242+
}).then((response) => {
243+
expect(response.results.length).toEqual(1);
244+
var output = response.results[0];
245+
expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId);
246+
done();
247+
})
248+
.catch((err) => {
249+
console.log('err', err);
250+
});
251+
});
252+
202253
it('stores pointers with a _p_ prefix', (done) => {
203254
var obj = {
204255
foo: 'bar',

0 commit comments

Comments
 (0)