diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/lib/gitlab/tracking | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/tracking')
-rw-r--r-- | spec/lib/gitlab/tracking/standard_context_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/gitlab/tracking/standard_context_spec.rb b/spec/lib/gitlab/tracking/standard_context_spec.rb new file mode 100644 index 00000000000..acf7aeb303a --- /dev/null +++ b/spec/lib/gitlab/tracking/standard_context_spec.rb @@ -0,0 +1,55 @@ +# 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 + context 'with no arguments' do + it 'creates a Snowplow context with no data' do + snowplow_context.to_json[:data].each do |_, v| + expect(v).to be_nil + end + end + end + + context 'with extra data' do + subject { described_class.new(foo: 'bar') } + + it 'creates a Snowplow context with the given data' do + expect(snowplow_context.to_json.dig(:data, :foo)).to eq('bar') + end + end + + context 'with namespace' do + subject { described_class.new(namespace: namespace) } + + it 'creates a Snowplow context using the given data' do + expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(namespace.id) + expect(snowplow_context.to_json.dig(:data, :project_id)).to be_nil + end + end + + context 'with project' do + subject { described_class.new(project: project) } + + it 'creates a Snowplow context using the given data' do + expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(project.namespace.id) + expect(snowplow_context.to_json.dig(:data, :project_id)).to eq(project.id) + end + end + + context 'with project and namespace' do + subject { described_class.new(namespace: namespace, project: project) } + + it 'creates a Snowplow context using the given data' do + expect(snowplow_context.to_json.dig(:data, :namespace_id)).to eq(namespace.id) + expect(snowplow_context.to_json.dig(:data, :project_id)).to eq(project.id) + end + end + end +end |