Skip to content

Commit

Permalink
Merge pull request #172 from dsimmons/fix/failling-specs
Browse files Browse the repository at this point in the history
[Fix]: Amend failing Travis specs.
  • Loading branch information
sahat committed Oct 26, 2014
2 parents 7933978 + fb04973 commit 16f8600
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
4 changes: 4 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ describe('satellizer.config', function() {
});

it('should set authHeader', function() {
var configDefault = this.$authProvider.authHeader;

this.$authProvider.authHeader = 'x-new-header';
expect(this.config.authHeader).toEqual('x-new-header');
expect(this.$authProvider.authHeader).toEqual('x-new-header');

this.$authProvider.authHeader = configDefault;
});

it('should get loginOnSignup', function() {
Expand Down
58 changes: 35 additions & 23 deletions test/http.spec.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,72 @@
describe('$http', function() {

beforeEach(function() {
var _this = this;
var self = this;
module('satellizer', function($authProvider) {
_this.$authProvider = $authProvider;
self.$authProvider = $authProvider;
});
});

beforeEach(inject([
'$http',
'$httpBackend',
'$auth',
'$window',
'satellizer.config',
'satellizer.local',
function($httpBackend, $auth, config, local) {
'satellizer.shared',
function($http, $httpBackend, $window, config, local, shared) {
var mockResponse = {};

this.$http = $http;
this.$httpBackend = $httpBackend;
this.$auth = $auth;
this.$window = $window;
this.config = config;
this.local = local;
this.shared = shared;

$window.localStorage.clear();

mockResponse[this.config.tokenName] = 'ABCDEFG123456';
$httpBackend.expectPOST(this.config.loginUrl).respond(mockResponse);
}]));

it('should handle the default Authorization header', function() {
var self = this;
this.$authProvider.authHeader = 'Authorization';

this.local.login()
.then(function(response) {
return response.config.headers;
})
.then(function(headers) {
var token = headers[self.config.authHeader];
expect(token).toBeDefined();
expect(token).toMatch(/Bearer\s+\w+/);
});
this.$httpBackend.flush()

this.$httpBackend.expectGET('/some/arbitrary/endpoint', function(headers) {
var token = headers[self.config.authHeader];
expect(token).toBeDefined();
expect(token).toMatch(/Bearer\s+\w+/);
return headers;
}).respond(200);

this.$http.get('/some/arbitrary/endpoint');
this.$httpBackend.flush();
});

it('should handle a custom header', function() {
var _this = this;
var self = this;
this.$authProvider.authHeader = 'x-new-header';

this.local.login()
.then(function(response) {
return response.config.headers;
})
.then(function(headers) {
var token = headers[_this.config.authHeader];
expect(token).toBeDefined();
expect(token).not.toMatch(/Bearer\s+\w+/);
});
this.$httpBackend.flush()

this.$httpBackend.expectGET('/some/arbitrary/endpoint', function(headers) {
var token = headers[self.config.authHeader];
expect(token).toBeDefined();
expect(token).not.toMatch(/Bearer\s+\w+/);
return headers;
}).respond(200);

this.$http.get('/some/arbitrary/endpoint');
this.$httpBackend.flush();
});

afterEach(function() {
this.shared.logout();
this.$authProvider.authHeader = 'Authorization';
});

Expand Down

0 comments on commit 16f8600

Please sign in to comment.