diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb new file mode 100644 index 00000000000..cb94da11d58 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/in_product_marketing_email_cta_clicked_metric_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::InProductMarketingEmailCtaClickedMetric do + using RSpec::Parameterized::TableSyntax + + let(:email_attributes) { { cta_clicked_at: Date.yesterday, track: 'verify', series: 0 } } + let(:options) { { track: 'verify', series: 0 } } + let(:expected_value) { 2 } + let(:expected_query) do + 'SELECT COUNT("in_product_marketing_emails"."id") FROM "in_product_marketing_emails"' \ + ' WHERE "in_product_marketing_emails"."cta_clicked_at" IS NOT NULL' \ + ' AND "in_product_marketing_emails"."series" = 0'\ + ' AND "in_product_marketing_emails"."track" = 1' + end + + before do + create_list :in_product_marketing_email, 2, email_attributes + + create :in_product_marketing_email, email_attributes.merge(cta_clicked_at: nil) + create :in_product_marketing_email, email_attributes.merge(track: 'team') + create :in_product_marketing_email, email_attributes.merge(series: 1) + end + + it_behaves_like 'a correct instrumented metric value and query', { + options: { track: 'verify', series: 0 }, + time_frame: 'all' + } + + where(:options_key, :valid_value, :invalid_value) do + :track | 'admin_verify' | 'invite_team' + :series | 1 | 5 + end + + with_them do + it "raises an exception if option is not present" do + expect do + described_class.new(options: options.except(options_key), time_frame: 'all') + end.to raise_error(ArgumentError, %r{#{options_key} .* must be one of}) + end + + it "raises an exception if option has invalid value" do + expect do + options[options_key] = invalid_value + described_class.new(options: options, time_frame: 'all') + end.to raise_error(ArgumentError, %r{#{options_key} .* must be one of}) + end + + it "doesn't raise exceptions if option has valid value" do + options[options_key] = valid_value + described_class.new(options: options, time_frame: 'all') + end + end +end |