gitlab-org--gitlab-foss/spec/javascripts/raven/raven_config_spec.js

127 lines
3.1 KiB
JavaScript
Raw Normal View History

import Raven from 'raven-js';
import RavenConfig from '~/raven/raven_config';
describe('RavenConfig', () => {
describe('init', () => {
beforeEach(() => {
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);
});
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 error bindings method', () => {
expect(RavenConfig.bindRavenErrors).toHaveBeenCalled();
});
it('should call setUser', () => {
expect(RavenConfig.setUser).toHaveBeenCalled();
});
});
it('should not call setUser if there is no current user ID', () => {
RavenConfig.init({
sentryDsn: '//sentryDsn',
ravenAssetUrl: '//ravenAssetUrl',
currentUserId: undefined,
whitelistUrls: ['//gitlabUrl'],
isProduction: true,
});
expect(RavenConfig.setUser).not.toHaveBeenCalled();
});
});
describe('configure', () => {
describe('when called', () => {
let options;
let raven;
beforeEach(() => {
options = {
sentryDsn: '//sentryDsn',
whitelistUrls: ['//gitlabUrl'],
isProduction: true,
};
raven = jasmine.createSpyObj('raven', ['install']);
spyOn(Raven, 'config').and.returnValue(raven);
spyOn(Raven, 'install');
RavenConfig.configure.call({
options,
});
});
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();
});
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',
});
});
});
});
});
describe('setUser', () => {
describe('when called', () => {
beforeEach(() => {});
});
});
describe('bindRavenErrors', () => {
describe('when called', () => {
beforeEach(() => {});
});
});
describe('handleRavenErrors', () => {
describe('when called', () => {
beforeEach(() => {});
});
});
});