Implemented new broker messages for browser proxy

This commit is contained in:
Cecylia Bocovich 2019-10-25 11:29:42 -04:00
parent c4ae64905b
commit b4b538a17f
3 changed files with 33 additions and 23 deletions

View file

@ -35,8 +35,8 @@ describe('Broker', function() {
// fake successful request and response from broker.
spyOn(b, '_postRequest').and.callFake(function() {
b._xhr.readyState = b._xhr.DONE;
b._xhr.status = Broker.STATUS.OK;
b._xhr.responseText = 'fake offer';
b._xhr.status = Broker.CODE.OK;
b._xhr.responseText = '{"Status":"client match","Offer":"fake offer"}';
return b._xhr.onreadystatechange();
});
poll = b.getClientOffer();
@ -46,7 +46,7 @@ describe('Broker', function() {
expect(desc).toEqual('fake offer');
return done();
}).catch(function() {
fail('should not reject on Broker.STATUS.OK');
fail('should not reject on Broker.CODE.OK');
return done();
});
});
@ -57,14 +57,15 @@ describe('Broker', function() {
// fake timed-out request from broker
spyOn(b, '_postRequest').and.callFake(function() {
b._xhr.readyState = b._xhr.DONE;
b._xhr.status = Broker.STATUS.GATEWAY_TIMEOUT;
b._xhr.status = Broker.CODE.OK;
b._xhr.responseText = '{"Status":"no match"}';
return b._xhr.onreadystatechange();
});
poll = b.getClientOffer();
expect(poll).not.toBeNull();
expect(b._postRequest).toHaveBeenCalled();
return poll.then(function(desc) {
fail('should not fulfill on Broker.STATUS.GATEWAY_TIMEOUT');
fail('should not fulfill with "Status: no match"');
return done();
}, function(err) {
expect(err).toBe(Broker.MESSAGE.TIMEOUT);
@ -101,7 +102,7 @@ describe('Broker', function() {
var b = new Broker('fake');
spyOn(b, '_postRequest');
b.sendAnswer('fake id', 123);
expect(b._postRequest).toHaveBeenCalledWith('fake id', jasmine.any(Object), 'answer', '123');
expect(b._postRequest).toHaveBeenCalledWith(jasmine.any(Object), 'answer', '{"Version":"1.0","Sid":"fake id","Answer":"123"}');
});
it('POST XMLHttpRequests to the broker', function() {
@ -110,9 +111,8 @@ describe('Broker', function() {
spyOn(b._xhr, 'open');
spyOn(b._xhr, 'setRequestHeader');
spyOn(b._xhr, 'send');
b._postRequest(0, b._xhr, 'test', 'data');
b._postRequest(b._xhr, 'test', 'data');
expect(b._xhr.open).toHaveBeenCalled();
expect(b._xhr.setRequestHeader).toHaveBeenCalled();
expect(b._xhr.send).toHaveBeenCalled();
});