diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/lib/gitlab/tracking | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/gitlab/tracking')
-rw-r--r-- | spec/lib/gitlab/tracking/docs/helper_spec.rb | 91 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/docs/renderer_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/event_definition_spec.rb | 101 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/standard_context_spec.rb | 16 |
4 files changed, 231 insertions, 0 deletions
diff --git a/spec/lib/gitlab/tracking/docs/helper_spec.rb b/spec/lib/gitlab/tracking/docs/helper_spec.rb new file mode 100644 index 00000000000..5f7965502f1 --- /dev/null +++ b/spec/lib/gitlab/tracking/docs/helper_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::Docs::Helper do + let_it_be(:klass) do + Class.new do + include Gitlab::Tracking::Docs::Helper + end + end + + describe '#auto_generated_comment' do + it 'renders information about missing description' do + expect(klass.new.auto_generated_comment).to match /This documentation is auto generated by a script/ + end + end + + describe '#render_description' do + context 'description is empty' do + it 'renders information about missing description' do + object = double(description: '') + + expect(klass.new.render_description(object)).to eq('Missing description') + end + end + + context 'description is present' do + it 'render description' do + object = double(description: 'some description') + + expect(klass.new.render_description(object)).to eq('some description') + end + end + end + + describe '#render_event_taxonomy' do + it 'render table with event taxonomy' do + attributes = { + category: 'epics', + action: 'promote', + label: nil, + property_description: 'String with issue id', + value_description: 'Integer issue id' + } + object = double(attributes: attributes) + event_taxonomy = <<~MD.chomp + | category | action | label | property | value | + |---|---|---|---|---| + | `epics` | `promote` | `` | `String with issue id` | `Integer issue id` | + MD + + expect(klass.new.render_event_taxonomy(object)).to eq(event_taxonomy) + end + end + + describe '#md_link_to' do + it 'render link in md format' do + expect(klass.new.md_link_to('zelda', 'link')).to eq('[zelda](link)') + end + end + + describe '#render_owner' do + it 'render information about group owning event' do + object = double(product_group: "group::product intelligence") + + expect(klass.new.render_owner(object)).to eq("Owner: `group::product intelligence`") + end + end + + describe '#render_tiers' do + it 'render information about tiers' do + object = double(tiers: %w[bronze silver gold]) + + expect(klass.new.render_tiers(object)).to eq("Tiers: `bronze`, `silver`, `gold`") + end + end + + describe '#render_yaml_definition_path' do + it 'render relative location of yaml definition' do + object = double(yaml_path: 'config/events/button_click.yaml') + + expect(klass.new.render_yaml_definition_path(object)).to eq("YAML definition: `config/events/button_click.yaml`") + end + end + + describe '#backtick' do + it 'wraps string in backticks chars' do + expect(klass.new.backtick('test')).to eql("`test`") + end + end +end diff --git a/spec/lib/gitlab/tracking/docs/renderer_spec.rb b/spec/lib/gitlab/tracking/docs/renderer_spec.rb new file mode 100644 index 00000000000..386aea6c23a --- /dev/null +++ b/spec/lib/gitlab/tracking/docs/renderer_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::Docs::Renderer do + describe 'contents' do + let(:dictionary_path) { described_class::DICTIONARY_PATH } + let(:items) { Gitlab::Tracking::EventDefinition.definitions.first(10).to_h } + + it 'generates dictionary for given items' do + generated_dictionary = described_class.new(items).contents + table_of_contents_items = items.values.map { |item| "#{item.category} #{item.action}"} + + generated_dictionary_keys = RDoc::Markdown + .parse(generated_dictionary) + .table_of_contents + .select { |metric_doc| metric_doc.level == 3 } + .map { |item| item.text.match(%r{<code>(.*)</code>})&.captures&.first } + + expect(generated_dictionary_keys).to match_array(table_of_contents_items) + end + end +end diff --git a/spec/lib/gitlab/tracking/event_definition_spec.rb b/spec/lib/gitlab/tracking/event_definition_spec.rb new file mode 100644 index 00000000000..51c62840819 --- /dev/null +++ b/spec/lib/gitlab/tracking/event_definition_spec.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::EventDefinition do + let(:attributes) do + { + description: 'Created issues', + category: 'issues', + action: 'create', + label_description: 'API', + property_description: 'The string "issue_id"', + value_description: 'ID of the issue', + extra_properties: { confidential: false }, + product_category: 'collection', + product_stage: 'growth', + product_section: 'dev', + product_group: 'group::product analytics', + distribution: %w(ee ce), + tier: %w(free premium ultimate) + } + end + + let(:path) { File.join('events', 'issues_create.yml') } + let(:definition) { described_class.new(path, attributes) } + let(:yaml_content) { attributes.deep_stringify_keys.to_yaml } + + def write_metric(metric, path, content) + path = File.join(metric, path) + dir = File.dirname(path) + FileUtils.mkdir_p(dir) + File.write(path, content) + end + + it 'has all definitions valid' do + expect { described_class.definitions }.not_to raise_error(Gitlab::Tracking::InvalidEventError) + end + + describe '#validate' do + using RSpec::Parameterized::TableSyntax + + where(:attribute, :value) do + :description | 1 + :category | nil + :action | nil + :label_description | 1 + :property_description | 1 + :value_description | 1 + :extra_properties | 'smth' + :product_category | 1 + :product_stage | 1 + :product_section | nil + :product_group | nil + :distributions | %[be eb] + :tiers | %[pro] + end + + with_them do + before do + attributes[attribute] = value + end + + it 'raise exception' do + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).at_least(:once).with(instance_of(Gitlab::Tracking::InvalidEventError)) + + described_class.new(path, attributes).validate! + end + end + end + + describe '.definitions' do + let(:metric1) { Dir.mktmpdir('metric1') } + let(:metric2) { Dir.mktmpdir('metric2') } + + before do + allow(described_class).to receive(:paths).and_return( + [ + File.join(metric1, '**', '*.yml'), + File.join(metric2, '**', '*.yml') + ] + ) + end + + subject { described_class.definitions } + + it 'has empty list when there are no definition files' do + is_expected.to be_empty + end + + it 'has one metric when there is one file' do + write_metric(metric1, path, yaml_content) + + is_expected.to be_one + end + + after do + FileUtils.rm_rf(metric1) + FileUtils.rm_rf(metric2) + end + end +end diff --git a/spec/lib/gitlab/tracking/standard_context_spec.rb b/spec/lib/gitlab/tracking/standard_context_spec.rb index dacd08cf12b..289818266bd 100644 --- a/spec/lib/gitlab/tracking/standard_context_spec.rb +++ b/spec/lib/gitlab/tracking/standard_context_spec.rb @@ -57,6 +57,22 @@ RSpec.describe Gitlab::Tracking::StandardContext do expect(snowplow_context.to_json.dig(:data, :source)).to eq(described_class::GITLAB_RAILS_SOURCE) end + context 'plan' do + context 'when namespace is not available' do + it 'is nil' do + expect(snowplow_context.to_json.dig(:data, :plan)).to be_nil + end + end + + context 'when namespace is available' do + subject { described_class.new(namespace: create(:namespace)) } + + it 'contains plan name' do + expect(snowplow_context.to_json.dig(:data, :plan)).to eq(Plan::DEFAULT) + end + end + end + context 'with extra data' do subject { described_class.new(extra_key_1: 'extra value 1', extra_key_2: 'extra value 2') } |