Welcome to mirror list, hosted at ThFree Co, Russian Federation.

in_product_marketing_email_sent_metric_spec.rb « instrumentations « metrics « usage « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0cc82773d56e79a78e60cba64d71a983807db45d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metrics::Instrumentations::InProductMarketingEmailSentMetric do
  using RSpec::Parameterized::TableSyntax

  let(:email_attributes) { { 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"."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(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: email_attributes.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
        email_attributes[options_key] = invalid_value
        described_class.new(options: email_attributes, 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
      email_attributes[options_key] = valid_value
      described_class.new(options: email_attributes, time_frame: 'all')
    end
  end
end