@@ -199,6 +199,57 @@ describe('rest create', () => {
199
199
} ) ;
200
200
} ) ;
201
201
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
+
202
253
it ( 'stores pointers with a _p_ prefix' , ( done ) => {
203
254
var obj = {
204
255
foo : 'bar' ,
0 commit comments