From 067361327bba0cb7a8b28190485699da7deb22bb Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Fri, 14 Apr 2017 21:09:16 +0100 Subject: Updated units --- app/assets/javascripts/raven/index.js | 16 +-- app/assets/javascripts/raven/raven_config.js | 4 +- spec/javascripts/raven/index_spec.js | 6 +- spec/javascripts/raven/raven_config_spec.js | 154 ++++++++++++++------------- 4 files changed, 96 insertions(+), 84 deletions(-) diff --git a/app/assets/javascripts/raven/index.js b/app/assets/javascripts/raven/index.js index 373f9f29c79..3c5656040b9 100644 --- a/app/assets/javascripts/raven/index.js +++ b/app/assets/javascripts/raven/index.js @@ -1,11 +1,15 @@ import RavenConfig from './raven_config'; -const index = RavenConfig.init.bind(RavenConfig, { - sentryDsn: gon.sentry_dsn, - currentUserId: gon.current_user_id, - whitelistUrls: [gon.gitlab_url], - isProduction: gon.is_production, -}); +const index = function index() { + RavenConfig.init({ + sentryDsn: gon.sentry_dsn, + currentUserId: gon.current_user_id, + whitelistUrls: [gon.gitlab_url], + isProduction: gon.is_production, + }); + + return RavenConfig; +}; index(); diff --git a/app/assets/javascripts/raven/raven_config.js b/app/assets/javascripts/raven/raven_config.js index 1157a10d96f..bb9be7cb196 100644 --- a/app/assets/javascripts/raven/raven_config.js +++ b/app/assets/javascripts/raven/raven_config.js @@ -8,8 +8,6 @@ const RavenConfig = { this.configure(); this.bindRavenErrors(); if (this.options.currentUserId) this.setUser(); - - return this; }, configure() { @@ -44,6 +42,6 @@ const RavenConfig = { }, }); }, -} +}; export default RavenConfig; diff --git a/spec/javascripts/raven/index_spec.js b/spec/javascripts/raven/index_spec.js index efde37b1f8e..85ec1de4e4e 100644 --- a/spec/javascripts/raven/index_spec.js +++ b/spec/javascripts/raven/index_spec.js @@ -1,7 +1,7 @@ import RavenConfig from '~/raven/raven_config'; import index from '~/raven/index'; -fdescribe('RavenConfig options', () => { +describe('RavenConfig options', () => { let sentryDsn; let currentUserId; let gitlabUrl; @@ -21,13 +21,13 @@ fdescribe('RavenConfig options', () => { is_production: isProduction, }; - spyOn(RavenConfig.init, 'bind'); + spyOn(RavenConfig, 'init'); indexReturnValue = index(); }); it('should init with .sentryDsn, .currentUserId, .whitelistUrls and .isProduction', () => { - expect(RavenConfig.init.bind).toHaveBeenCalledWith(RavenConfig, { + expect(RavenConfig.init).toHaveBeenCalledWith({ sentryDsn, currentUserId, whitelistUrls: [gitlabUrl], diff --git a/spec/javascripts/raven/raven_config_spec.js b/spec/javascripts/raven/raven_config_spec.js index 64cf63702bc..3885cfde6bf 100644 --- a/spec/javascripts/raven/raven_config_spec.js +++ b/spec/javascripts/raven/raven_config_spec.js @@ -1,47 +1,46 @@ +import $ from 'jquery'; import Raven from 'raven-js'; import RavenConfig from '~/raven/raven_config'; -describe('RavenConfig', () => { +fdescribe('RavenConfig', () => { describe('init', () => { + let options; + beforeEach(() => { + options = { + sentryDsn: '//sentryDsn', + ravenAssetUrl: '//ravenAssetUrl', + currentUserId: 1, + whitelistUrls: ['//gitlabUrl'], + isProduction: true, + }; + spyOn(RavenConfig, 'configure'); spyOn(RavenConfig, 'bindRavenErrors'); spyOn(RavenConfig, 'setUser'); - }); - - describe('when called', () => { - let options; - beforeEach(() => { - options = { - sentryDsn: '//sentryDsn', - ravenAssetUrl: '//ravenAssetUrl', - currentUserId: 1, - whitelistUrls: ['//gitlabUrl'], - isProduction: true, - }; - - RavenConfig.init(options); - }); + RavenConfig.init(options); + }); - it('should set the options property', () => { - expect(RavenConfig.options).toEqual(options); - }); + it('should set the options property', () => { + expect(RavenConfig.options).toEqual(options); + }); - it('should call the configure method', () => { - expect(RavenConfig.configure).toHaveBeenCalled(); - }); + it('should call the configure method', () => { + expect(RavenConfig.configure).toHaveBeenCalled(); + }); - it('should call the error bindings method', () => { - expect(RavenConfig.bindRavenErrors).toHaveBeenCalled(); - }); + it('should call the error bindings method', () => { + expect(RavenConfig.bindRavenErrors).toHaveBeenCalled(); + }); - it('should call setUser', () => { - expect(RavenConfig.setUser).toHaveBeenCalled(); - }); + it('should call setUser', () => { + expect(RavenConfig.setUser).toHaveBeenCalled(); }); it('should not call setUser if there is no current user ID', () => { + RavenConfig.setUser.calls.reset(); + RavenConfig.init({ sentryDsn: '//sentryDsn', ravenAssetUrl: '//ravenAssetUrl', @@ -55,72 +54,83 @@ describe('RavenConfig', () => { }); describe('configure', () => { - describe('when called', () => { - let options; - let raven; + let options; + let raven; - beforeEach(() => { - options = { - sentryDsn: '//sentryDsn', - whitelistUrls: ['//gitlabUrl'], - isProduction: true, - }; + beforeEach(() => { + options = { + sentryDsn: '//sentryDsn', + whitelistUrls: ['//gitlabUrl'], + isProduction: true, + }; - raven = jasmine.createSpyObj('raven', ['install']); + raven = jasmine.createSpyObj('raven', ['install']); - spyOn(Raven, 'config').and.returnValue(raven); - spyOn(Raven, 'install'); + spyOn(Raven, 'config').and.returnValue(raven); - RavenConfig.configure.call({ - options, - }); + RavenConfig.configure.call({ + options, }); + }); - it('should call Raven.config', () => { - expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, { - whitelistUrls: options.whitelistUrls, - environment: 'production', - }); + it('should call Raven.config', () => { + expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, { + whitelistUrls: options.whitelistUrls, + environment: 'production', }); + }); - it('should call Raven.install', () => { - expect(Raven.install).toHaveBeenCalled(); + it('should call Raven.install', () => { + expect(raven.install).toHaveBeenCalled(); + }); + + it('should set .environment to development if isProduction is false', () => { + options.isProduction = false; + + RavenConfig.configure.call({ + options, }); - describe('if isProduction is false', () => { - beforeEach(() => { - options.isProduction = false; - - RavenConfig.configure.call({ - options, - }); - }); - - it('should set .environment to development', () => { - expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, { - whitelistUrls: options.whitelistUrls, - environment: 'development', - }); - }); + expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, { + whitelistUrls: options.whitelistUrls, + environment: 'development', }); }); }); describe('setUser', () => { - describe('when called', () => { - beforeEach(() => {}); + let ravenConfig; + + beforeEach(() => { + ravenConfig = { options: { currentUserId: 1 } }; + spyOn(Raven, 'setUserContext'); + + RavenConfig.setUser.call(ravenConfig); + }); + + it('should call .setUserContext', function () { + expect(Raven.setUserContext).toHaveBeenCalledWith({ + id: ravenConfig.options.currentUserId, + }); }); }); describe('bindRavenErrors', () => { - describe('when called', () => { - beforeEach(() => {}); + beforeEach(() => { + RavenConfig.bindRavenErrors(); + }); + + it('should query for document using jquery', () => { + console.log($, 'or', $.fn); + // expect($).toHaveBeenCalledWith() + }); + + it('should call .on', function () { + // expect($document.on).toHaveBeenCalledWith('ajaxError.raven', RavenConfig.handleRavenErrors); }); }); describe('handleRavenErrors', () => { - describe('when called', () => { - beforeEach(() => {}); - }); + beforeEach(() => {}); }); }); -- cgit v1.2.1