Skip to content

Commit

Permalink
Merge pull request #161 from MichaelBailly/81-support-dynamic-restang…
Browse files Browse the repository at this point in the history
…ular-instances-setHeaders

linagora/esn-frontend-account#81 setHaeders on restangular inst…
  • Loading branch information
MichaelBailly authored Dec 29, 2020
2 parents 50c9965 + 7349126 commit e75e2a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/frontend/js/modules/http-configurer.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('The esn.http httpConfigurer service', function() {

describe('manageRestangular fn', function() {
it('should prepend the current baseUrl', function() {
var raInstance = {
setBaseUrl: sinon.spy()
const raInstance = {
setBaseUrl: sinon.spy(),
setDefaultHeaders: sinon.spy()
};

httpConfigurer.setBaseUrl('/test1');
Expand All @@ -26,8 +27,9 @@ describe('The esn.http httpConfigurer service', function() {
});

it('should update the baseUrl when setBaseUrl is called', function() {
var raInstance = {
setBaseUrl: function() {}
const raInstance = {
setBaseUrl: sinon.spy(),
setDefaultHeaders: sinon.spy()
};

httpConfigurer.setBaseUrl('/test1');
Expand All @@ -37,6 +39,36 @@ describe('The esn.http httpConfigurer service', function() {

expect(raInstance.setBaseUrl).to.have.been.calledWith('/test2/mod1/api');
});

it('should set the headers to restangular instances', function() {
const headers = { Authorization: 'bearer 1234' };
const raInstance = {
setBaseUrl: sinon.spy(),
setDefaultHeaders: sinon.spy()
};

httpConfigurer.setBaseUrl('/test1');
httpConfigurer.setHeaders(headers);
httpConfigurer.manageRestangular(raInstance, '/mod1/api');

expect(raInstance.setDefaultHeaders).to.have.been.calledWith(headers);
});

it('should update the headers when setHeaders is called', function() {
const headers = { Authorization: 'bearer 1234' };
const raInstance = {
setBaseUrl: sinon.spy(),
setDefaultHeaders: sinon.spy()
};

httpConfigurer.setBaseUrl('/test1');
httpConfigurer.setHeaders({ foo: 'bar' });
httpConfigurer.manageRestangular(raInstance, '/mod1/api');
raInstance.setDefaultHeaders = sinon.spy();
httpConfigurer.setHeaders(headers);

expect(raInstance.setDefaultHeaders).to.have.been.calledWith(headers);
});
});

describe('getUrl()', function() {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/js/modules/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ angular.module('esn.http', [
var moduleRestangular = { restangular: restangular, baseUri: baseUri };

updateRestangularBaseUrl(moduleRestangular);
updateRestangularHeaders(moduleRestangular);
restangulars.push(moduleRestangular);
}

Expand Down

0 comments on commit e75e2a7

Please sign in to comment.