debian-mirror-gitlab/spec/lib/gitlab/tracking/standard_context_spec.rb

79 lines
2.2 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Tracking::StandardContext do
let_it_be(:project) { create(:project) }
let_it_be(:namespace) { create(:namespace) }
let(:snowplow_context) { subject.to_context }
describe '#to_context' do
2021-03-11 19:13:27 +05:30
context 'environment' do
shared_examples 'contains environment' do |expected_environment|
it 'contains environment' do
expect(snowplow_context.to_json.dig(:data, :environment)).to eq(expected_environment)
2021-03-08 18:12:59 +05:30
end
end
2021-03-11 19:13:27 +05:30
context 'development or test' do
include_examples 'contains environment', 'development'
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
context 'staging' do
before do
2021-04-17 20:07:23 +05:30
stub_config_setting(url: 'https://staging.gitlab.com')
2021-03-11 19:13:27 +05:30
end
2021-03-08 18:12:59 +05:30
2021-03-11 19:13:27 +05:30
include_examples 'contains environment', 'staging'
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
context 'production' do
before do
2021-04-17 20:07:23 +05:30
stub_config_setting(url: 'https://gitlab.com')
2021-03-11 19:13:27 +05:30
end
2021-03-08 18:12:59 +05:30
2021-03-11 19:13:27 +05:30
include_examples 'contains environment', 'production'
2021-03-08 18:12:59 +05:30
end
2021-04-17 20:07:23 +05:30
context 'org' do
before do
stub_config_setting(url: 'https://dev.gitlab.org')
end
include_examples 'contains environment', 'org'
end
context 'other self-managed instance' do
before do
stub_rails_env('production')
end
include_examples 'contains environment', 'self-managed'
end
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
it 'contains source' do
expect(snowplow_context.to_json.dig(:data, :source)).to eq(described_class::GITLAB_RAILS_SOURCE)
end
context 'with extra data' do
2021-04-29 21:17:54 +05:30
subject { described_class.new(extra_key_1: 'extra value 1', extra_key_2: 'extra value 2') }
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
it 'includes extra data in `extra` hash' do
expect(snowplow_context.to_json.dig(:data, :extra)).to eq(extra_key_1: 'extra value 1', extra_key_2: 'extra value 2')
end
end
context 'without extra data' do
it 'contains an empty `extra` hash' do
expect(snowplow_context.to_json.dig(:data, :extra)).to be_empty
2021-03-08 18:12:59 +05:30
end
end
2021-03-11 19:13:27 +05:30
it 'does not contain any ids' do
expect(snowplow_context.to_json[:data].keys).not_to include(:user_id, :project_id, :namespace_id)
end
2021-03-08 18:12:59 +05:30
end
end