diff options
Diffstat (limited to 'spec/lib/gitlab/tracking')
-rw-r--r-- | spec/lib/gitlab/tracking/snowplow_schema_validation_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/standard_context_spec.rb | 22 |
2 files changed, 53 insertions, 2 deletions
diff --git a/spec/lib/gitlab/tracking/snowplow_schema_validation_spec.rb b/spec/lib/gitlab/tracking/snowplow_schema_validation_spec.rb new file mode 100644 index 00000000000..32c601ae47d --- /dev/null +++ b/spec/lib/gitlab/tracking/snowplow_schema_validation_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Snowplow Schema Validation' do + context 'snowplow events definition' do + shared_examples 'matches schema' do + it 'conforms schema json' do + paths = Dir[Rails.root.join(yaml_path)] + + events = paths.each_with_object([]) do |path, metrics| + metrics.push( + YAML.safe_load(File.read(path), aliases: true) + ) + end + + expect(events).to all match_schema(Rails.root.join('config/events/schema.json')) + end + end + + describe 'matches the schema for CE' do + let(:yaml_path) { 'config/events/*.yml' } + + it_behaves_like 'matches schema' + end + + describe 'matches the schema for EE' do + let(:yaml_path) { 'ee/config/events/*.yml' } + + it_behaves_like 'matches schema' + end + end +end diff --git a/spec/lib/gitlab/tracking/standard_context_spec.rb b/spec/lib/gitlab/tracking/standard_context_spec.rb index a0fb6a270a5..ca7a6b6b1c3 100644 --- a/spec/lib/gitlab/tracking/standard_context_spec.rb +++ b/spec/lib/gitlab/tracking/standard_context_spec.rb @@ -87,8 +87,26 @@ RSpec.describe Gitlab::Tracking::StandardContext do end end - it 'does not contain any ids' do - expect(snowplow_context.to_json[:data].keys).not_to include(:user_id, :project_id, :namespace_id) + it 'does not contain user id' do + expect(snowplow_context.to_json[:data].keys).not_to include(:user_id) + end + + it 'contains namespace and project ids' do + expect(snowplow_context.to_json[:data].keys).to include(:project_id, :namespace_id) + end + + it 'accepts just project id as integer' do + expect { described_class.new(project: 1).to_context }.not_to raise_error + end + + context 'without add_namespace_and_project_to_snowplow_tracking feature' do + before do + stub_feature_flags(add_namespace_and_project_to_snowplow_tracking: false) + end + + it 'does not contain any ids' do + expect(snowplow_context.to_json[:data].keys).not_to include(:user_id, :project_id, :namespace_id) + end end end end |