diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/lib/gitlab/usage_data_counters | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) | |
download | gitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb | 107 |
2 files changed, 110 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb index 5f66387c82b..9aecb8f8b25 100644 --- a/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb @@ -80,10 +80,13 @@ RSpec.describe Gitlab::UsageDataCounters::EditorUniqueCounter, :clean_gitlab_red it 'can return the count of actions per user deduplicated' do described_class.track_web_ide_edit_action(author: user1) + described_class.track_live_preview_edit_action(author: user1) described_class.track_snippet_editor_edit_action(author: user1) described_class.track_sfe_edit_action(author: user1) described_class.track_web_ide_edit_action(author: user2, time: time - 2.days) described_class.track_web_ide_edit_action(author: user3, time: time - 3.days) + described_class.track_live_preview_edit_action(author: user2, time: time - 2.days) + described_class.track_live_preview_edit_action(author: user3, time: time - 3.days) described_class.track_snippet_editor_edit_action(author: user3, time: time - 3.days) described_class.track_sfe_edit_action(author: user3, time: time - 3.days) diff --git a/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb new file mode 100644 index 00000000000..60c4424d2ae --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::IpynbDiffActivityCounter, :clean_gitlab_redis_shared_state do + let(:user) { build(:user, id: 1) } + let(:for_mr) { false } + let(:for_commit) { false } + let(:first_note) { build(:note, author: user, id: 1) } + let(:second_note) { build(:note, author: user, id: 2) } + + before do + allow(first_note).to receive(:for_merge_request?).and_return(for_mr) + allow(second_note).to receive(:for_merge_request?).and_return(for_mr) + allow(first_note).to receive(:for_commit?).and_return(for_commit) + allow(second_note).to receive(:for_commit?).and_return(for_commit) + end + + subject do + described_class.note_created(first_note) + described_class.note_created(first_note) + described_class.note_created(second_note) + end + + shared_examples_for 'an action that tracks events' do + specify do + expect { 2.times { subject } } + .to change { event_count(action) }.by(2) + .and change { event_count(per_user_action) }.by(1) + end + end + + shared_examples_for 'an action that does not track events' do + specify do + expect { 2.times { subject } } + .to change { event_count(action) }.by(0) + .and change { event_count(per_user_action) }.by(0) + end + end + + describe '#track_note_created_in_ipynb_diff' do + context 'note is for commit' do + let(:for_commit) { true } + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + end + + context 'note is for MR' do + let(:for_mr) { true } + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + end + + context 'note is for neither MR nor Commit' do + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + end + end + + private + + def event_count(event_name) + Gitlab::UsageDataCounters::HLLRedisCounter.unique_events( + event_names: event_name, + start_date: 2.weeks.ago, + end_date: 2.weeks.from_now + ) + end +end |