Skip to content

Commit

Permalink
Adds extra test for local request white listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Conolly committed Dec 10, 2015
1 parent 96878f8 commit e9c6574
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions app/src/js/httpMethodInterceptor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ describe('httpMethodInterceptor', function () {
var httpMethodInterceptor, httpMethodInterceptorProvider, mockQ,
mockRootScope, mockRejectPromise;

describe('request method', function () {
beforeEach(function () {
mockRejectPromise = { 'foo': 'bar' };
mockQ = jasmine.createSpyObj('$q', ['when', 'reject']);
mockQ.reject.andReturn(mockRejectPromise);
mockRootScope = jasmine.createSpyObj('$rootScope', ['$emit']);
beforeEach(function () {
mockRejectPromise = { 'foo': 'bar' };
mockQ = jasmine.createSpyObj('$q', ['when', 'reject']);
mockQ.reject.andReturn(mockRejectPromise);
mockRootScope = jasmine.createSpyObj('$rootScope', ['$emit']);
});

describe('request method with local requests disabled', function () {
beforeEach(function () {
module('ng.httpLoader.httpMethodInterceptor',
function ($provide, _httpMethodInterceptorProvider_) {
httpMethodInterceptorProvider = _httpMethodInterceptorProvider_;
httpMethodInterceptorProvider.whitelistDomain('foo.bar');
httpMethodInterceptorProvider.whitelistLocalRequests();
$provide.value('$rootScope', mockRootScope);
}
);
Expand Down Expand Up @@ -51,7 +52,7 @@ describe('httpMethodInterceptor', function () {
.toHaveBeenCalledWith('loaderShow', config.method);
});

it("should broadcast the show loader event for local request when enbaled",
it("should not broadcast the show loader event for local request",
function () {
//Arrange.
var config = { method: 'GET', url: '/my/api' };
Expand All @@ -60,8 +61,7 @@ describe('httpMethodInterceptor', function () {
httpMethodInterceptor.request(config);

//Assert.
expect(mockRootScope.$emit)
.toHaveBeenCalledWith('loaderShow', config.method);
expect(mockRootScope.$emit).not.toHaveBeenCalled();
});

it("should return the config", function () {
Expand All @@ -76,13 +76,37 @@ describe('httpMethodInterceptor', function () {
});
});

describe('response method', function () {
describe('request method with local requests enabled', function () {
beforeEach(function () {
mockRejectPromise = { 'foo': 'bar' };
mockQ = jasmine.createSpyObj('$q', ['when', 'reject']);
mockQ.reject.andReturn(mockRejectPromise);
mockRootScope = jasmine.createSpyObj('$rootScope', ['$emit']);
module('ng.httpLoader.httpMethodInterceptor',
function ($provide, _httpMethodInterceptorProvider_) {
httpMethodInterceptorProvider = _httpMethodInterceptorProvider_;
httpMethodInterceptorProvider.whitelistLocalRequests();
$provide.value('$rootScope', mockRootScope);
}
);

inject(function (_httpMethodInterceptor_) {
httpMethodInterceptor = _httpMethodInterceptor_;
});
});

it("should broadcast the show loader event for local request",
function () {
//Arrange.
var config = { method: 'GET', url: '/my/api' };

//Act.
httpMethodInterceptor.request(config);

//Assert.
expect(mockRootScope.$emit)
.toHaveBeenCalledWith('loaderShow', config.method);
});
});

describe('response method', function () {
beforeEach(function () {
module('ng.httpLoader.httpMethodInterceptor',
function ($provide, _httpMethodInterceptorProvider_) {
httpMethodInterceptorProvider = _httpMethodInterceptorProvider_;
Expand Down

0 comments on commit e9c6574

Please sign in to comment.