summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/usage/metric_spec.rb
blob: d4a789419a4698eb4bae370b28fc13be496d4d2d (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metric do
  describe '#definition' do
    it 'returns key_path metric definiton' do
      expect(described_class.new(key_path: 'uuid').definition).to be_an(Gitlab::Usage::MetricDefinition)
    end
  end

  describe '#unflatten_default_path' do
    using RSpec::Parameterized::TableSyntax

    where(:key_path, :value, :expected_hash) do
      'uuid'                                     | nil    | { uuid: nil }
      'uuid'                                     | '1111' | { uuid: '1111' }
      'counts.issues'                            | nil    | { counts: { issues: nil } }
      'counts.issues'                            | 100    | { counts: { issues: 100 } }
      'usage_activity_by_stage.verify.ci_builds' | 100    | { usage_activity_by_stage: { verify: { ci_builds: 100 } } }
    end

    with_them do
      subject { described_class.new(key_path: key_path, value: value).unflatten_key_path }

      it { is_expected.to eq(expected_hash) }
    end
  end
end