blob: 3a5d035a5e23bbeeef561607af7e453c68a6f40e [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function () {
'use strict';
describe('The xos.helper module', function(){
let SetCSRFToken, httpProviderObj, httpBackend, http, cookies;
const fakeToken = 'aiuhsnds98234ndASd';
beforeEach(function() {
module(
'xos.helpers',
function ($httpProvider) {
//save our interceptor
httpProviderObj = $httpProvider;
}
);
inject(function (_SetCSRFToken_, _$httpBackend_, _$http_, _$cookies_) {
SetCSRFToken = _SetCSRFToken_;
httpBackend = _$httpBackend_;
http = _$http_;
cookies = _$cookies_
// mocking $cookie service
spyOn(cookies, 'get').and.returnValue(fakeToken);
});
});
describe('the SetCSRFToken', () => {
it('should exist', () => {
expect(SetCSRFToken).toBeDefined();
});
it('should attach token the request', (done) => {
httpBackend.when('POST', 'http://example.com', null, function(headers) {
expect(headers['X-CSRFToken']).toBe(fakeToken);
done();
return headers;
}).respond(200, {name: 'example' });
http.post('http://example.com');
httpBackend.flush();
});
});
it('should set SetCSRFToken interceptor', () => {
expect(httpProviderObj).toBeDefined();
expect(httpProviderObj.interceptors).toContain('SetCSRFToken');
});
});
})();