2014-06-11 14:34:52 -04:00
|
|
|
FacebookHandler = require 'lib/FacebookHandler'
|
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
mockAuthEvent =
|
2014-06-11 14:34:52 -04:00
|
|
|
response:
|
|
|
|
authResponse:
|
2014-06-30 22:16:26 -04:00
|
|
|
accessToken: 'aksdhjflkqjrj245234b52k345q344le4j4k5l45j45s4dkljvdaskl'
|
|
|
|
userID: '4301938'
|
2014-06-11 14:34:52 -04:00
|
|
|
expiresIn: 5138
|
2014-06-30 22:16:26 -04:00
|
|
|
signedRequest: 'akjsdhfjkhea.3423nkfkdsejnfkd'
|
|
|
|
status: 'connected'
|
2014-06-11 14:34:52 -04:00
|
|
|
|
|
|
|
# Whatev, it's all public info anyway
|
|
|
|
mockMe =
|
2014-06-30 22:16:26 -04:00
|
|
|
id: '4301938'
|
|
|
|
email: 'scott@codecombat.com'
|
|
|
|
first_name: 'Scott'
|
|
|
|
gender: 'male'
|
|
|
|
last_name: 'Erickson'
|
|
|
|
link: 'https://www.facebook.com/scott.erickson.779'
|
|
|
|
locale: 'en_US'
|
|
|
|
name: 'Scott Erickson'
|
2014-06-11 14:34:52 -04:00
|
|
|
timezone: -7
|
2014-06-30 22:16:26 -04:00
|
|
|
updated_time: '2014-05-21T04:58:06+0000'
|
|
|
|
username: 'scott.erickson.779'
|
2014-06-11 14:34:52 -04:00
|
|
|
verified: true
|
|
|
|
work: [
|
|
|
|
{
|
|
|
|
employer:
|
2014-06-30 22:16:26 -04:00
|
|
|
id: '167559910060759'
|
|
|
|
name: 'CodeCombat'
|
2014-06-11 14:34:52 -04:00
|
|
|
|
|
|
|
location:
|
2014-06-30 22:16:26 -04:00
|
|
|
id: '114952118516947'
|
|
|
|
name: 'San Francisco, California'
|
2014-06-11 14:34:52 -04:00
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
start_date: '2013-02-28'
|
2014-06-11 14:34:52 -04:00
|
|
|
}
|
|
|
|
{
|
2014-06-30 22:16:26 -04:00
|
|
|
end_date: '2013-01-31'
|
2014-06-11 14:34:52 -04:00
|
|
|
employer:
|
2014-06-30 22:16:26 -04:00
|
|
|
id: '39198748555'
|
|
|
|
name: 'Skritter'
|
2014-06-11 14:34:52 -04:00
|
|
|
|
|
|
|
location:
|
2014-06-30 22:16:26 -04:00
|
|
|
id: '106109576086811'
|
|
|
|
name: 'Oberlin, Ohio'
|
2014-06-11 14:34:52 -04:00
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
start_date: '2008-06-01'
|
2014-06-11 14:34:52 -04:00
|
|
|
}
|
|
|
|
]
|
2014-06-30 22:16:26 -04:00
|
|
|
|
|
|
|
window.FB ?= {
|
2014-06-11 16:43:07 -04:00
|
|
|
api: ->
|
|
|
|
}
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-06-11 14:34:52 -04:00
|
|
|
describe 'lib/FacebookHandler.coffee', ->
|
|
|
|
it 'on facebook-logged-in, gets data from FB and sends a patch to the server', ->
|
2014-06-30 22:16:26 -04:00
|
|
|
me.clear({silent: true})
|
2014-06-11 14:34:52 -04:00
|
|
|
me.markToRevert()
|
|
|
|
me.set({_id: '12345'})
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-06-11 14:34:52 -04:00
|
|
|
spyOn FB, 'api'
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-06-11 14:34:52 -04:00
|
|
|
new FacebookHandler()
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'auth:logged-in-with-facebook', mockAuthEvent
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-06-11 14:34:52 -04:00
|
|
|
expect(FB.api).toHaveBeenCalled()
|
|
|
|
apiArgs = FB.api.calls.argsFor(0)
|
|
|
|
expect(apiArgs[0]).toBe('/me')
|
|
|
|
apiArgs[1](mockMe) # sending the 'response'
|
|
|
|
request = jasmine.Ajax.requests.mostRecent()
|
|
|
|
expect(request).toBeDefined()
|
|
|
|
params = JSON.parse request.params
|
|
|
|
expect(params.firstName).toBe(mockMe.first_name)
|
|
|
|
expect(params.lastName).toBe(mockMe.last_name)
|
|
|
|
expect(params.gender).toBe(mockMe.gender)
|
|
|
|
expect(params.email).toBe(mockMe.email)
|
|
|
|
expect(params.facebookID).toBe(mockMe.id)
|
|
|
|
expect(request.method).toBe('PATCH')
|
|
|
|
expect(_.string.startsWith(request.url, '/db/user/12345')).toBeTruthy()
|