2017-04-14 16:09:16 -04:00
|
|
|
import $ from 'jquery';
|
2017-04-04 09:58:45 -04:00
|
|
|
import Raven from 'raven-js';
|
|
|
|
import RavenConfig from '~/raven/raven_config';
|
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
fdescribe('RavenConfig', () => {
|
2017-04-04 09:58:45 -04:00
|
|
|
describe('init', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
let options;
|
|
|
|
|
2017-04-04 09:58:45 -04:00
|
|
|
beforeEach(() => {
|
2017-04-14 16:09:16 -04:00
|
|
|
options = {
|
|
|
|
sentryDsn: '//sentryDsn',
|
|
|
|
ravenAssetUrl: '//ravenAssetUrl',
|
|
|
|
currentUserId: 1,
|
|
|
|
whitelistUrls: ['//gitlabUrl'],
|
|
|
|
isProduction: true,
|
|
|
|
};
|
|
|
|
|
2017-04-04 09:58:45 -04:00
|
|
|
spyOn(RavenConfig, 'configure');
|
|
|
|
spyOn(RavenConfig, 'bindRavenErrors');
|
|
|
|
spyOn(RavenConfig, 'setUser');
|
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
RavenConfig.init(options);
|
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
it('should set the options property', () => {
|
|
|
|
expect(RavenConfig.options).toEqual(options);
|
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
it('should call the configure method', () => {
|
|
|
|
expect(RavenConfig.configure).toHaveBeenCalled();
|
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
it('should call the error bindings method', () => {
|
|
|
|
expect(RavenConfig.bindRavenErrors).toHaveBeenCalled();
|
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
it('should call setUser', () => {
|
|
|
|
expect(RavenConfig.setUser).toHaveBeenCalled();
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call setUser if there is no current user ID', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
RavenConfig.setUser.calls.reset();
|
|
|
|
|
2017-04-04 09:58:45 -04:00
|
|
|
RavenConfig.init({
|
|
|
|
sentryDsn: '//sentryDsn',
|
|
|
|
ravenAssetUrl: '//ravenAssetUrl',
|
|
|
|
currentUserId: undefined,
|
|
|
|
whitelistUrls: ['//gitlabUrl'],
|
|
|
|
isProduction: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(RavenConfig.setUser).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('configure', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
let options;
|
|
|
|
let raven;
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
options = {
|
|
|
|
sentryDsn: '//sentryDsn',
|
|
|
|
whitelistUrls: ['//gitlabUrl'],
|
|
|
|
isProduction: true,
|
|
|
|
};
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
raven = jasmine.createSpyObj('raven', ['install']);
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
spyOn(Raven, 'config').and.returnValue(raven);
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
RavenConfig.configure.call({
|
|
|
|
options,
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
2017-04-14 16:09:16 -04:00
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
it('should call Raven.config', () => {
|
|
|
|
expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, {
|
|
|
|
whitelistUrls: options.whitelistUrls,
|
|
|
|
environment: 'production',
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
2017-04-14 16:09:16 -04:00
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
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,
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
|
2017-04-14 16:09:16 -04:00
|
|
|
expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, {
|
|
|
|
whitelistUrls: options.whitelistUrls,
|
|
|
|
environment: 'development',
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setUser', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
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,
|
|
|
|
});
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('bindRavenErrors', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
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);
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleRavenErrors', () => {
|
2017-04-14 16:09:16 -04:00
|
|
|
beforeEach(() => {});
|
2017-04-04 09:58:45 -04:00
|
|
|
});
|
|
|
|
});
|