debian-mirror-gitlab/spec/frontend/sentry/sentry_config_spec.js

104 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
import * as Sentry from 'sentrybrowser7';
2019-12-26 22:10:19 +05:30
import SentryConfig from '~/sentry/sentry_config';
describe('SentryConfig', () => {
describe('init', () => {
const options = {
currentUserId: 1,
};
beforeEach(() => {
jest.spyOn(SentryConfig, 'configure');
jest.spyOn(SentryConfig, 'setUser');
SentryConfig.init(options);
});
it('should set the options property', () => {
expect(SentryConfig.options).toEqual(options);
});
it('should call the configure method', () => {
expect(SentryConfig.configure).toHaveBeenCalled();
});
it('should call setUser', () => {
expect(SentryConfig.setUser).toHaveBeenCalled();
});
it('should not call setUser if there is no current user ID', () => {
2020-01-01 13:55:28 +05:30
SentryConfig.setUser.mockClear();
2023-03-04 22:38:38 +05:30
SentryConfig.init({ currentUserId: undefined });
2019-12-26 22:10:19 +05:30
expect(SentryConfig.setUser).not.toHaveBeenCalled();
});
});
describe('configure', () => {
const sentryConfig = {};
const options = {
dsn: 'https://123@sentry.gitlab.test/123',
2023-03-04 22:38:38 +05:30
allowUrls: ['//gitlabUrl', 'webpack-internal://'],
2019-12-26 22:10:19 +05:30
environment: 'test',
release: 'revision',
tags: {
revision: 'revision',
2021-09-30 23:02:18 +05:30
feature_category: 'my_feature_category',
2019-12-26 22:10:19 +05:30
},
};
beforeEach(() => {
jest.spyOn(Sentry, 'init').mockImplementation();
2021-09-30 23:02:18 +05:30
jest.spyOn(Sentry, 'setTags').mockImplementation();
2019-12-26 22:10:19 +05:30
sentryConfig.options = options;
SentryConfig.configure.call(sentryConfig);
});
it('should call Sentry.init', () => {
expect(Sentry.init).toHaveBeenCalledWith({
dsn: options.dsn,
release: options.release,
2023-03-04 22:38:38 +05:30
allowUrls: options.allowUrls,
environment: options.environment,
2019-12-26 22:10:19 +05:30
});
});
2021-09-30 23:02:18 +05:30
it('should call Sentry.setTags', () => {
expect(Sentry.setTags).toHaveBeenCalledWith(options.tags);
});
2019-12-26 22:10:19 +05:30
it('should set environment from options', () => {
sentryConfig.options.environment = 'development';
SentryConfig.configure.call(sentryConfig);
expect(Sentry.init).toHaveBeenCalledWith({
dsn: options.dsn,
release: options.release,
2023-03-04 22:38:38 +05:30
allowUrls: options.allowUrls,
2019-12-26 22:10:19 +05:30
environment: 'development',
});
});
});
describe('setUser', () => {
let sentryConfig;
beforeEach(() => {
sentryConfig = { options: { currentUserId: 1 } };
jest.spyOn(Sentry, 'setUser');
SentryConfig.setUser.call(sentryConfig);
});
it('should call .setUser', () => {
expect(Sentry.setUser).toHaveBeenCalledWith({
id: sentryConfig.options.currentUserId,
});
});
});
});