From aaa908b91d82dfac31fb4b23f91c5ab6444bfa37 Mon Sep 17 00:00:00 2001 From: Chris Conolly Date: Fri, 11 Dec 2015 16:03:16 +0000 Subject: [PATCH] Updates method interceptor to run last on http requests - When chaining multiple http intercepetors the first interceptor will run last when the request is resolved. Updating http-loader to allow all other interceptors to run before it does on http response - Allows Angular-multimocks and Angular-http-loader to work together --- app/src/js/httpMethodInterceptor.js | 2 +- app/src/js/httpMethodInterceptor.spec.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/js/httpMethodInterceptor.js b/app/src/js/httpMethodInterceptor.js index 8e9fa28..fc0f6ee 100644 --- a/app/src/js/httpMethodInterceptor.js +++ b/app/src/js/httpMethodInterceptor.js @@ -117,5 +117,5 @@ angular }) .config(['$httpProvider', function ($httpProvider) { - $httpProvider.interceptors.push('httpMethodInterceptor'); + $httpProvider.interceptors.unshift('httpMethodInterceptor'); }]); diff --git a/app/src/js/httpMethodInterceptor.spec.js b/app/src/js/httpMethodInterceptor.spec.js index ec75221..f113bc9 100644 --- a/app/src/js/httpMethodInterceptor.spec.js +++ b/app/src/js/httpMethodInterceptor.spec.js @@ -1,4 +1,4 @@ -/* global describe, beforeEach, module, it, inject, jasmine, expect */ +/* global describe, beforeEach, module, it, inject, jasmine, expect, spyOn */ describe('httpMethodInterceptor', function () { var httpMethodInterceptor, httpMethodInterceptorProvider, mockQ, @@ -206,4 +206,23 @@ describe('httpMethodInterceptor', function () { expect(res).toBe(response); }); }); + + describe('config sets $httpProvider interceptor', function () { + var $httpProvider; + + beforeEach(function () { + module(function (_$httpProvider_) { + $httpProvider = _$httpProvider_; + spyOn($httpProvider.interceptors, 'unshift'); + }); + module('ng.httpLoader.httpMethodInterceptor'); + inject(); + }); + + it('should add to $httpProvider interceptors', function () { + expect($httpProvider.interceptors.unshift) + .toHaveBeenCalledWith('httpMethodInterceptor'); + }); + }); }); +