From fb04973109b92184105f138cfad1d30e838746a7 Mon Sep 17 00:00:00 2001 From: Dan Simmons Date: Sat, 25 Oct 2014 15:28:33 -0400 Subject: [PATCH] Fixed failing Travis build due to changes introduced by #171 (although tests passed locally). --- test/config.spec.js | 4 ++++ test/http.spec.js | 58 +++++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/test/config.spec.js b/test/config.spec.js index 1f3f8d13..a338fb4b 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -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() { diff --git a/test/http.spec.js b/test/http.spec.js index 459b6149..28065cd1 100644 --- a/test/http.spec.js +++ b/test/http.spec.js @@ -1,24 +1,30 @@ 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); @@ -26,35 +32,41 @@ describe('$http', function() { 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'; });