Begin spec for proxy-side broker interaction

This commit is contained in:
Serene Han 2016-02-08 19:26:58 -08:00
parent 547cb9690a
commit 548c100160
3 changed files with 41 additions and 0 deletions

View file

@ -14,6 +14,7 @@ FILES = [
FILES_SPEC = [
'spec/util.spec.coffee'
'spec/ui.spec.coffee'
'spec/broker.spec.coffee'
'spec/proxypair.spec.coffee'
'spec/snowflake.spec.coffee'
]

View file

@ -17,6 +17,7 @@ class Broker
clients: 0
id: null
request: null
# When interacting with the Broker, snowflake must generate a unique session
# ID so the Broker can keep track of which signalling channel it's speaking
@ -34,6 +35,7 @@ class Broker
getClientOffer: ->
new Promise (fulfill, reject) =>
xhr = new XMLHttpRequest()
@request = xhr
try
xhr.open 'POST', @url + 'proxy'
xhr.setRequestHeader('X-Session-ID', @id)

View file

@ -0,0 +1,38 @@
###
jasmine tests for Snowflake broker
###
# fake xhr
class XMLHttpRequest
open: ->
send: ->
onreadystatechange: ->
DONE: 1
describe 'Broker', ->
it 'can be created', ->
b = new Broker('fake')
expect(b.url).toEqual 'https://fake/'
expect(b.id).not.toBeNull()
it 'polls for client offer', (done) ->
b = new Broker('fake')
# TODO: fix this
poll = b.getClientOffer()
spyOn(b.request, 'open')
spyOn(b.request, 'send').and.callFake ->
b.onreadystatechange()
poll.then = ->
done()
expect(poll).not.toBeNull()
# expect(b.request.open).toHaveBeenCalled()
# expect(b.request.send).toHaveBeenCalled()
# fake successful poll
b.request.readyState = XMLHttpRequest.DONE
b.request.status = STATUS_OK
b.request.responseText = 'test'
done()
it 'responds to the broker with answer', ->
# TODO