File: metric_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (135 lines) | stat: -rw-r--r-- 4,451 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true

require 'fast_spec_helper'

require_relative '../../../../scripts/internal_events/cli'

RSpec.describe InternalEventsCli::NewMetric, :aggregate_failures, feature_category: :service_ping do
  let(:time_frame) { '7d' }
  let(:identifier) { 'user' }
  let(:actions) { ['action_1'] }
  let(:filters) { nil }

  subject(:metric) do
    described_class.new(
      time_frame: time_frame,
      identifier: identifier,
      actions: actions,
      filters: filters
    )
  end

  it 'has expected description content' do
    expect(metric.description_prefix).to eq('Weekly count of unique users')
    expect(metric.technical_description).to eq('Weekly count of unique users who triggered action_1')
  end

  context 'when filtered' do
    let(:filters) { [] }

    it 'has expected description content' do
      expect(metric.description_prefix).to eq('Weekly count of unique users')
      expect(metric.technical_description).to eq('Weekly count of unique users who triggered the selected events')
    end
  end

  context 'when all time' do
    let(:time_frame) { 'all' }

    it 'has expected description content' do
      expect(metric.description_prefix).to eq('Total count of unique users')
      expect(metric.technical_description).to eq('Total count of unique users who triggered action_1')
    end
  end

  context 'with multiple events' do
    let(:actions) { %w[action_1 action_2] }

    it 'has expected description content' do
      expect(metric.description_prefix).to eq('Weekly count of unique users')
      expect(metric.technical_description).to eq('Weekly count of unique users who triggered the selected events')
    end
  end

  context 'when unique by default identifier' do
    let(:identifier) { 'project' }

    it 'has expected description content' do
      expect(metric.description_prefix).to eq('Weekly count of unique projects')
      expect(metric.technical_description).to eq('Weekly count of unique projects where action_1 occurred')
    end

    context 'when filtered' do
      let(:filters) { [] }

      it 'has expected description content' do
        expect(metric.description_prefix).to eq('Weekly count of unique projects')
        expect(metric.technical_description).to eq('Weekly count of unique projects where the selected events occurred')
      end
    end
  end

  context 'when unique by additional property' do
    let(:identifier) { 'label' }

    it 'has expected description content' do
      expect(metric.description_prefix).to eq('Weekly count of unique')
      expect(metric.technical_description).to eq("Weekly count of unique values for 'label' from action_1 occurrences")
    end

    context 'when filtered' do
      let(:filters) { [] }

      it 'has expected description content' do
        expect(metric.description_prefix).to eq('Weekly count of unique')
        expect(metric.technical_description).to eq(
          "Weekly count of unique values for 'label' from the selected events occurrences"
        )
      end
    end
  end
end

RSpec.describe InternalEventsCli::Metric::Identifier, :aggregate_failures, feature_category: :service_ping do
  subject(:identifier) { described_class.new(value) }

  context 'with no value' do
    let(:value) { nil }

    it 'has expected components' do
      expect(identifier.value).to eq(nil)
      expect(identifier.description).to eq('count of %s occurrences')
      expect(identifier.key_path).to eq('total')
    end
  end

  context 'when value is user' do
    let(:value) { 'user' }

    it 'has expected components' do
      expect(identifier.value).to eq('user')
      expect(identifier.description).to eq('count of unique users who triggered %s')
      expect(identifier.key_path).to eq('distinct_user_id_from')
    end
  end

  context 'when value is an identifier' do
    let(:value) { 'namespace' }

    it 'has expected components' do
      expect(identifier.value).to eq('namespace')
      expect(identifier.description).to eq('count of unique namespaces where %s occurred')
      expect(identifier.key_path).to eq('distinct_namespace_id_from')
    end
  end

  context 'when value is an additional property' do
    let(:value) { 'label' }

    it 'has expected components' do
      expect(identifier.value).to eq('label')
      expect(identifier.description).to eq("count of unique values for 'label' from %s occurrences")
      expect(identifier.key_path).to eq('distinct_label_from')
    end
  end
end