Reset content provider environment
diff --git a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
index 443034d..200014d 100644
--- a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
+++ b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
@@ -1,31 +1,45 @@
'use strict';
describe('The xos.helper module', function(){
- var SetCSRFToken, httpProviderObj;
+ var SetCSRFToken, httpProviderObj, httpBackend, http, cookies;
- //beforeEach(module('xos.helpers'));
- //
- //beforeEach(inject(function($httpProvider){
- // httpProviderObj = $httpProvider;
- //}));
- //
- //beforeEach(inject(function(_SetCSRFToken_){
- // console.log('inject csrf');
- // SetCSRFToken = _SetCSRFToken_;
- //}));
+ const fakeToken = 'aiuhsnds98234ndASd';
beforeEach(function() {
- module('xos.helpers', function ($httpProvider) {
- //save our interceptor
- httpProviderObj = $httpProvider;
+ 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);
});
- inject(function (_SetCSRFToken_) {
- SetCSRFToken = _SetCSRFToken_;
- })
});
- it('should exist', () => {
- expect(SetCSRFToken).toBeDefined();
+ 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();
+ }).respond(200, {name: 'example' });
+
+ http.post('http://example.com');
+
+ httpBackend.flush();
+ });
});
it('should set SetCSRFToken interceptor', () => {
diff --git a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
new file mode 100644
index 0000000..560f4dc
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
@@ -0,0 +1,51 @@
+/**
+ * © OpenCORD
+ *
+ * Visit http://guide.xosproject.org/devguide/addview/ for more information
+ *
+ * Created by teone on 3/24/16.
+ */
+
+(function () {
+ 'use strict';
+
+ describe('The NoHyperlinks factory', () => {
+
+ let httpProviderObj, httpBackend, http, noHyperlinks;
+
+ beforeEach(() => {
+ module(
+ 'xos.helpers',
+ ($httpProvider) => {
+ //save our interceptor
+ httpProviderObj = $httpProvider;
+ }
+ );
+
+ inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
+ httpBackend = _$httpBackend_;
+ http = _$http_;
+ noHyperlinks = _NoHyperlinks_
+ });
+
+ httpProviderObj.interceptors.push('NoHyperlinks');
+
+ });
+
+ it('should set NoHyperlinks interceptor', () => {
+ expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
+ });
+
+ it('should attach ?no_hyperlinks=1 to the request url', () => {
+ let result = noHyperlinks.request({url: 'sample.url'});
+ expect(result.url).toEqual('sample.url?no_hyperlinks=1');
+ });
+
+ it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
+ let result = noHyperlinks.request({url: 'sample.html'});
+ expect(result.url).toEqual('sample.html');
+ });
+
+ });
+})();
+