BigW Consortium Gitlab

[ci skip] Index and singleton improvements with some more unit, more to come

parent cfd3d0fd
import RavenConfig from './raven_config'; import RavenConfig from './raven_config';
RavenConfig.init({ const index = RavenConfig.init.bind(RavenConfig, {
sentryDsn: gon.sentry_dsn, sentryDsn: gon.sentry_dsn,
currentUserId: gon.current_user_id, currentUserId: gon.current_user_id,
whitelistUrls: [gon.gitlab_url], whitelistUrls: [gon.gitlab_url],
isProduction: gon.is_production, isProduction: gon.is_production,
}); });
export default RavenConfig; index();
export default index;
import Raven from 'raven-js'; import Raven from 'raven-js';
import $ from 'jquery';
class RavenConfig { const RavenConfig = {
static init(options = {}) { init(options = {}) {
this.options = options; this.options = options;
this.configure(); this.configure();
this.bindRavenErrors(); this.bindRavenErrors();
if (this.options.currentUserId) this.setUser(); if (this.options.currentUserId) this.setUser();
}
static configure() { return this;
},
configure() {
Raven.config(this.options.sentryDsn, { Raven.config(this.options.sentryDsn, {
whitelistUrls: this.options.whitelistUrls, whitelistUrls: this.options.whitelistUrls,
environment: this.options.isProduction ? 'production' : 'development', environment: this.options.isProduction ? 'production' : 'development',
}).install(); }).install();
} },
static setUser() { setUser() {
Raven.setUserContext({ Raven.setUserContext({
id: this.options.currentUserId, id: this.options.currentUserId,
}); });
} },
static bindRavenErrors() { bindRavenErrors() {
$(document).on('ajaxError.raven', this.handleRavenErrors); $(document).on('ajaxError.raven', this.handleRavenErrors);
} },
static handleRavenErrors(event, req, config, err) { handleRavenErrors(event, req, config, err) {
const error = err || req.statusText; const error = err || req.statusText;
Raven.captureMessage(error, { Raven.captureMessage(error, {
...@@ -40,7 +43,7 @@ class RavenConfig { ...@@ -40,7 +43,7 @@ class RavenConfig {
event, event,
}, },
}); });
} },
} }
export default RavenConfig; export default RavenConfig;
...@@ -3,13 +3,20 @@ require 'spec_helper' ...@@ -3,13 +3,20 @@ require 'spec_helper'
describe SentryHelper do describe SentryHelper do
describe '#sentry_dsn_public' do describe '#sentry_dsn_public' do
it 'returns nil if no sentry_dsn is set' do it 'returns nil if no sentry_dsn is set' do
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return(nil) mock_sentry_dsn(nil)
expect(helper.sentry_dsn_public).to eq(nil)
expect(helper.sentry_dsn_public).to eq nil
end end
it 'returns the uri string with no password if sentry_dsn is set' do it 'returns the uri string with no password if sentry_dsn is set' do
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return('https://test:dsn@host/path') mock_sentry_dsn('https://test:dsn@host/path')
expect(helper.sentry_dsn_public).to eq('https://test@host/path')
expect(helper.sentry_dsn_public).to eq 'https://test@host/path'
end end
end end
def mock_sentry_dsn(value)
allow_message_expectations_on_nil
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return(value)
end
end end
import RavenConfig from '~/raven/index'; import RavenConfig from '~/raven/raven_config';
import index from '~/raven/index';
describe('RavenConfig options', () => { fdescribe('RavenConfig options', () => {
it('should set sentryDsn'); let sentryDsn;
let currentUserId;
let gitlabUrl;
let isProduction;
let indexReturnValue;
it('should set currentUserId'); beforeEach(() => {
sentryDsn = 'sentryDsn';
currentUserId = 'currentUserId';
gitlabUrl = 'gitlabUrl';
isProduction = 'isProduction';
it('should set whitelistUrls'); window.gon = {
sentry_dsn: sentryDsn,
current_user_id: currentUserId,
gitlab_url: gitlabUrl,
is_production: isProduction,
};
it('should set isProduction'); spyOn(RavenConfig.init, 'bind');
indexReturnValue = index();
});
it('should init with .sentryDsn, .currentUserId, .whitelistUrls and .isProduction', () => {
expect(RavenConfig.init.bind).toHaveBeenCalledWith(RavenConfig, {
sentryDsn,
currentUserId,
whitelistUrls: [gitlabUrl],
isProduction,
});
});
it('should return RavenConfig', () => {
expect(indexReturnValue).toBe(RavenConfig);
});
}); });
import Raven from 'raven-js'; import Raven from 'raven-js';
import RavenConfig from '~/raven/raven_config'; import RavenConfig from '~/raven/raven_config';
import ClassSpecHelper from '../helpers/class_spec_helper';
fdescribe('RavenConfig', () => { describe('RavenConfig', () => {
describe('init', () => { describe('init', () => {
beforeEach(() => { beforeEach(() => {
spyOn(RavenConfig, 'configure'); spyOn(RavenConfig, 'configure');
...@@ -10,8 +9,6 @@ fdescribe('RavenConfig', () => { ...@@ -10,8 +9,6 @@ fdescribe('RavenConfig', () => {
spyOn(RavenConfig, 'setUser'); spyOn(RavenConfig, 'setUser');
}); });
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'init');
describe('when called', () => { describe('when called', () => {
let options; let options;
...@@ -58,8 +55,6 @@ fdescribe('RavenConfig', () => { ...@@ -58,8 +55,6 @@ fdescribe('RavenConfig', () => {
}); });
describe('configure', () => { describe('configure', () => {
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'configure');
describe('when called', () => { describe('when called', () => {
let options; let options;
let raven; let raven;
...@@ -112,24 +107,18 @@ fdescribe('RavenConfig', () => { ...@@ -112,24 +107,18 @@ fdescribe('RavenConfig', () => {
}); });
describe('setUser', () => { describe('setUser', () => {
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'setUser');
describe('when called', () => { describe('when called', () => {
beforeEach(() => {}); beforeEach(() => {});
}); });
}); });
describe('bindRavenErrors', () => { describe('bindRavenErrors', () => {
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'bindRavenErrors');
describe('when called', () => { describe('when called', () => {
beforeEach(() => {}); beforeEach(() => {});
}); });
}); });
describe('handleRavenErrors', () => { describe('handleRavenErrors', () => {
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'handleRavenErrors');
describe('when called', () => { describe('when called', () => {
beforeEach(() => {}); beforeEach(() => {});
}); });
......
/* eslint-disable space-before-function-paren */
// PhantomJS (Teaspoons default driver) doesn't have support for
// Function.prototype.bind, which has caused confusion. Use this polyfill to
// avoid the confusion.
/*= require support/bind-poly */
// You can require your own javascript files here. By default this will include
// everything in application, however you may get better load performance if you
// require the specific files that are being used in the spec that tests them.
/*= require jquery */
/*= require jquery.turbolinks */
/*= require bootstrap */
/*= require underscore */
/*= require es6-promise.auto */
// Teaspoon includes some support files, but you can use anything from your own
// support path too.
// require support/jasmine-jquery-1.7.0
// require support/jasmine-jquery-2.0.0
/*= require support/jasmine-jquery-2.1.0 */
// require support/sinon
// require support/your-support-file
// Deferring execution
// If you're using CommonJS, RequireJS or some other asynchronous library you can
// defer execution. Call Teaspoon.execute() after everything has been loaded.
// Simple example of a timeout:
// Teaspoon.defer = true
// setTimeout(Teaspoon.execute, 1000)
// Matching files
// By default Teaspoon will look for files that match
// _spec.{js,js.es6}. Add a filename_spec.js file in your spec path
// and it'll be included in the default suite automatically. If you want to
// customize suites, check out the configuration in teaspoon_env.rb
// Manifest
// If you'd rather require your spec files manually (to control order for
// instance) you can disable the suite matcher in the configuration and use this
// file as a manifest.
// For more information: http://github.com/modeset/teaspoon
// set our fixtures path
jasmine.getFixtures().fixturesPath = '/teaspoon/fixtures';
jasmine.getJSONFixtures().fixturesPath = '/teaspoon/fixtures';
// defined in ActionDispatch::TestRequest
// see https://github.com/rails/rails/blob/v4.2.7.1/actionpack/lib/action_dispatch/testing/test_request.rb#L7
window.gl = window.gl || {};
window.gl.TEST_HOST = 'http://test.host';
window.gon = window.gon || {};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment