Skip to content

Commit

Permalink
authHeader test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sahat committed Oct 25, 2014
1 parent 7d64534 commit 7933978
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions test/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,55 @@ describe('$http', function() {
});
});

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

this.$httpBackend = $httpBackend;
this.$auth = $auth;
this.config = config;
this.local = local;
this.$auth = $auth;
this.config = config;
this.local = local;

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

it('should handle the default Authorization header', function() {
var _this = this;
var self = this;
this.$authProvider.authHeader = 'Authorization';
this.local.login()
.then(function(response) { return response.config.headers; })
.then(function(response) {
return response.config.headers;
})
.then(function(headers) {
token = headers[_this.config.authHeader]
var token = headers[self.config.authHeader];
expect(token).toBeDefined();
expect(token).toMatch(/Bearer\s+\w+/);
});

this.$httpBackend.flush()
this.$httpBackend.flush();
});

it('should handle a custom header', function() {
var _this = this;
this.$authProvider.authHeader = 'x-new-header';
this.local.login()
.then(function(response) { return response.config.headers; })
.then(function(response) {
return response.config.headers;
})
.then(function(headers) {
token = headers[_this.config.authHeader]
var token = headers[_this.config.authHeader];
expect(token).toBeDefined();
expect(token).not.toMatch(/Bearer\s+\w+/);
});

this.$httpBackend.flush()
this.$httpBackend.flush();

this.$authProvider.authHeader = 'Authorization';
});

});

1 comment on commit 7933978

@dsimmons
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Missing semicolons and var's -- it's apparent that it's been a while since I've worked in vanilla JS!

On a sidenote, I didn't want to introduce to much as part of this PR, but additionally using something like Sinon might be useful for sandboxing changes as to not affect the overall state of the configuration (eg. so resetting like in L58 isn't necessary).

Please sign in to comment.