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

editor_unique_counter_spec.rb « usage_data_counters « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cbf4d3c82619abb4954f3bad7d000875075cadb6 (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
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::UsageDataCounters::EditorUniqueCounter, :clean_gitlab_redis_shared_state do
  let(:user) { build(:user, id: 1) }
  let(:user2) { build(:user, id: 2) }
  let(:user3) { build(:user, id: 3) }
  let(:project) { build(:project) }
  let(:namespace) { project.namespace }
  let(:time) { Time.zone.now }

  shared_examples 'tracks and counts action' do
    subject { track_action(author: user, project: project) }

    before do
      stub_application_setting(usage_ping_enabled: true)
    end

    specify do
      aggregate_failures do
        track_action(author: user, project: project)
        track_action(author: user2, project: project)
        track_action(author: user3, project: project)

        expect(count_unique(date_from: time.beginning_of_week, date_to: 1.week.from_now)).to eq(3)
      end
    end

    it_behaves_like 'internal event tracking'

    it 'does not track edit actions if author is not present' do
      track_action(author: nil, project: project)

      expect(count_unique(date_from: time.beginning_of_week, date_to: 1.week.from_now)).to eq(0)
    end
  end

  context 'for web IDE edit actions' do
    let(:event) { described_class::EDIT_BY_WEB_IDE }

    it_behaves_like 'tracks and counts action' do
      def track_action(params)
        described_class.track_web_ide_edit_action(**params)
      end

      def count_unique(params)
        described_class.count_web_ide_edit_actions(**params)
      end
    end
  end

  context 'for SFE edit actions' do
    let(:event) { described_class::EDIT_BY_SFE }

    it_behaves_like 'tracks and counts action' do
      def track_action(params)
        described_class.track_sfe_edit_action(**params)
      end

      def count_unique(params)
        described_class.count_sfe_edit_actions(**params)
      end
    end
  end

  context 'for snippet editor edit actions' do
    let(:event) { described_class::EDIT_BY_SNIPPET_EDITOR }

    it_behaves_like 'tracks and counts action' do
      def track_action(params)
        described_class.track_snippet_editor_edit_action(**params)
      end

      def count_unique(params)
        described_class.count_snippet_editor_edit_actions(**params)
      end
    end
  end
end