Skip to content

Commit

Permalink
added options to pass on transport options to underlying axjx through…
Browse files Browse the repository at this point in the history
… run
  • Loading branch information
narenranjit committed Jul 17, 2014
1 parent 6c11457 commit 369d58b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/epicenter.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/epicenter.min.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/service/auth-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
* Account to log-in into. Required to log-in as an end-user. Defaults to picking it up from the path.
* @type {String}
*/
account: ''
account: '',

//Options to pass on to the underlying transport layer
transport: {}
};
var serviceOptions = $.extend({}, defaults, config);

Expand All @@ -67,9 +69,10 @@
serviceOptions.account = urlConfig.accountPath;
}

var http = new TransportFactory({
var httpOptions = $.extend(true, {}, serviceOptions.transport, {
url: urlConfig.getAPIPath('authentication')
});
var http = new TransportFactory(httpOptions);

var EPI_COOKIE_KEY = 'epicenter.token';
var store = new StorageFactory(serviceOptions.store);
Expand Down
13 changes: 8 additions & 5 deletions src/service/data-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
token: store.get('epicenter.token') || '',

apiKey: '',
domain: 'forio.com'
domain: 'forio.com',

//Options to pass on to the underlying transport layer
transport: {}
};
var serviceOptions = $.extend({}, defaults, config);

Expand All @@ -77,9 +80,9 @@
return url;
};

var httpOptions = {
var httpOptions = $.extend(true, {}, serviceOptions.transport, {
url: getURL
};
});
if (serviceOptions.token) {
httpOptions.headers = {
'Authorization': 'Bearer ' + serviceOptions.token
Expand Down Expand Up @@ -176,8 +179,8 @@
* ds.saveAs('student1',
* {firstName: 'john', lastName: 'smith'},
* {root: 'students'});
* ds.saveAs('mgmt100/groupB',
* {scenarioYear: '2015'},
* ds.saveAs('mgmt100/groupB',
* {scenarioYear: '2015'},
* {root: 'myclasses'});
*
* **Parameters**
Expand Down
1 change: 0 additions & 1 deletion src/service/run-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
*/
complete: $.noop,


//Options to pass on to the underlying transport layer
transport: {}
};
Expand Down
9 changes: 8 additions & 1 deletion tests/spec/test-auth-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@
token = null;
});

afterEach(function() {
it('should pass in transport options to the underlying ajax handler', function () {
var callback = sinon.spy();
var as = new AuthService({transport: {beforeSend: callback}});
as.login({userName: 'john', password: 'y'});

server.respond();
callback.should.have.been.called;
});

describe('#login', function () {
it('should require username and password', function () {
var as = new AuthService();
Expand Down
9 changes: 9 additions & 0 deletions tests/spec/test-data-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
req.requestHeaders.Authorization.should.equal('Bearer abc');
});

it('should pass in transport options to the underlying ajax handler', function () {
var callback = sinon.spy();
var ds = new DataService({ root: 'person', account: 'forio', project: 'js-libs', transport: {beforeSend: callback}});
ds.load('name');

server.respond();
callback.should.have.been.called;
});

describe('#load', function () {
it('Should do a GET', function () {
var ds = new DataService({ root: 'person', account: 'forio', project: 'js-libs'});
Expand Down
10 changes: 5 additions & 5 deletions tests/spec/test-run-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
});

it('should pass in transport options to the underlying ajax handler', function () {
var callback = sinon.spy();
var rs = new RunService({account: 'forio', project: 'js-libs', transport: {beforeSend: callback}});
rs.create('model.jl');
var callback = sinon.spy();
var rs = new RunService({account: 'forio', project: 'js-libs', transport: {beforeSend: callback}});
rs.create('model.jl');

server.respond();
callback.should.have.been.called;
server.respond();
callback.should.have.been.called;
});

describe('#create()', function () {
Expand Down

0 comments on commit 369d58b

Please sign in to comment.