diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-15 06:11:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-15 06:11:57 +0300 |
commit | 1b5891ee8ce8adc6877c462ea292eaee3c4ab30b (patch) | |
tree | 6773287f5bcf34597f131c64588c285c304f1301 /spec | |
parent | 25c9c07a16a8100809542eb209df4902f5ef427c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 106 insertions, 56 deletions
diff --git a/spec/frontend/ide/stores/mutations/file_spec.js b/spec/frontend/ide/stores/mutations/file_spec.js index 1453f26c1d9..69ec2e7a6f5 100644 --- a/spec/frontend/ide/stores/mutations/file_spec.js +++ b/spec/frontend/ide/stores/mutations/file_spec.js @@ -22,7 +22,7 @@ describe('IDE store file mutations', () => { active: true, }); - expect(localFile.active).toBeTruthy(); + expect(localFile.active).toBe(true); }); it('sets pending tab as not active', () => { @@ -41,7 +41,7 @@ describe('IDE store file mutations', () => { it('adds into opened files', () => { mutations.TOGGLE_FILE_OPEN(localState, localFile.path); - expect(localFile.opened).toBeTruthy(); + expect(localFile.opened).toBe(true); expect(localState.openFiles.length).toBe(1); }); @@ -50,7 +50,7 @@ describe('IDE store file mutations', () => { mutations.TOGGLE_FILE_OPEN(localState, localFile.path); mutations.TOGGLE_FILE_OPEN(localState, localFile.path); - expect(localFile.opened).toBeFalsy(); + expect(localFile.opened).toBe(false); expect(localState.openFiles.length).toBe(0); }); }); @@ -162,7 +162,7 @@ describe('IDE store file mutations', () => { callMutationForFile(localFile); - expect(localFile.raw).toBeFalsy(); + expect(localFile.raw).toEqual(''); expect(localState.stagedFiles[0].raw).toBe('testing'); }); @@ -172,7 +172,7 @@ describe('IDE store file mutations', () => { callMutationForFile(localFile); - expect(localFile.raw).toBeFalsy(); + expect(localFile.raw).toEqual(''); expect(localFile.content).toBe('testing'); }); @@ -202,7 +202,7 @@ describe('IDE store file mutations', () => { callMutationForFile(localFile); - expect(localFile.raw).toBeFalsy(); + expect(localFile.raw).toEqual(''); expect(localState.stagedFiles[0].raw).toBe('testing'); }); }); @@ -239,7 +239,7 @@ describe('IDE store file mutations', () => { }); expect(localFile.content).toBe('testing'); - expect(localFile.changed).toBeTruthy(); + expect(localFile.changed).toBe(true); }); it('sets changed if file is a temp file', () => { @@ -250,7 +250,7 @@ describe('IDE store file mutations', () => { content: '', }); - expect(localFile.changed).toBeTruthy(); + expect(localFile.changed).toBe(true); }); }); @@ -329,7 +329,7 @@ describe('IDE store file mutations', () => { mutations.DISCARD_FILE_CHANGES(localState, localFile.path); expect(localFile.content).toBe(''); - expect(localFile.changed).toBeFalsy(); + expect(localFile.changed).toBe(false); }); it('adds to root tree if deleted', () => { @@ -527,7 +527,7 @@ describe('IDE store file mutations', () => { changed: true, }); - expect(localFile.changed).toBeTruthy(); + expect(localFile.changed).toBe(true); }); }); diff --git a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb index 1b73e5269d7..84a6f338282 100644 --- a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb @@ -6,7 +6,12 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git let_it_be(:user1) { build(:user, id: 1) } let_it_be(:user2) { build(:user, id: 2) } let_it_be(:user3) { build(:user, id: 3) } + let_it_be(:project) { build(:project) } + let_it_be(:category) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_CATEGORY } + let_it_be(:event_action) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_ACTION } + let_it_be(:event_label) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_LABEL } + let(:event_property) { action } let(:time) { Time.zone.now } context 'for Issue title edit actions' do @@ -120,8 +125,8 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git end context 'for Issue cloned actions' do - it_behaves_like 'a daily tracked issuable event' do - let(:action) { described_class::ISSUE_CLONED } + it_behaves_like 'daily tracked issuable snowplow and service ping events with project' do + let_it_be(:action) { described_class::ISSUE_CLONED } def track_action(params) described_class.track_issue_cloned_action(**params) @@ -239,8 +244,8 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git end end - context 'for Issue comment added actions' do - it_behaves_like 'a daily tracked issuable event' do + context 'for Issue comment added actions', :snowplow do + it_behaves_like 'daily tracked issuable snowplow and service ping events with project' do let(:action) { described_class::ISSUE_COMMENT_ADDED } def track_action(params) @@ -249,8 +254,8 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git end end - context 'for Issue comment edited actions' do - it_behaves_like 'a daily tracked issuable event' do + context 'for Issue comment edited actions', :snowplow do + it_behaves_like 'daily tracked issuable snowplow and service ping events with project' do let(:action) { described_class::ISSUE_COMMENT_EDITED } def track_action(params) @@ -259,8 +264,8 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git end end - context 'for Issue comment removed actions' do - it_behaves_like 'a daily tracked issuable event' do + context 'for Issue comment removed actions', :snowplow do + it_behaves_like 'daily tracked issuable snowplow and service ping events with project' do let(:action) { described_class::ISSUE_COMMENT_REMOVED } def track_action(params) diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 53b75a3c991..ed64663260e 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -69,20 +69,31 @@ RSpec.describe Notes::CreateService do end end - it 'tracks issue comment usage data', :clean_gitlab_redis_shared_state do - event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED - counter = Gitlab::UsageDataCounters::HLLRedisCounter + describe 'event tracking', :snowplow do + let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED } + let(:execute_create_service) { described_class.new(project, user, opts).execute } - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_added_action).with(author: user).and_call_original - expect do - described_class.new(project, user, opts).execute - end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) - end + it 'tracks issue comment usage data', :clean_gitlab_redis_shared_state do + counter = Gitlab::UsageDataCounters::HLLRedisCounter - it 'does not track merge request usage data' do - expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_create_comment_action) + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_added_action) + .with(author: user, project: project) + .and_call_original + expect do + execute_create_service + end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + end - described_class.new(project, user, opts).execute + it 'does not track merge request usage data' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_create_comment_action) + + execute_create_service + end + + it_behaves_like 'issue_edit snowplow tracking' do + let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED } + subject(:service_action) { execute_create_service } + end end context 'in a merge request' do diff --git a/spec/services/notes/destroy_service_spec.rb b/spec/services/notes/destroy_service_spec.rb index 55acdabef82..be95a4bb181 100644 --- a/spec/services/notes/destroy_service_spec.rb +++ b/spec/services/notes/destroy_service_spec.rb @@ -25,15 +25,25 @@ RSpec.describe Notes::DestroyService do .to change { user.todos_pending_count }.from(1).to(0) end - it 'tracks issue comment removal usage data', :clean_gitlab_redis_shared_state do - note = create(:note, project: project, noteable: issue) - event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_REMOVED - counter = Gitlab::UsageDataCounters::HLLRedisCounter + describe 'comment removed event tracking', :snowplow do + let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_REMOVED } + let(:note) { create(:note, project: project, noteable: issue) } + let(:service_action) { described_class.new(project, user).execute(note) } + + it 'tracks issue comment removal usage data', :clean_gitlab_redis_shared_state do + counter = Gitlab::UsageDataCounters::HLLRedisCounter + + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_removed_action) + .with(author: user, project: project) + .and_call_original + expect do + service_action + end.to change { counter.unique_events(event_names: property, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + end - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_removed_action).with(author: user).and_call_original - expect do - described_class.new(project, user).execute(note) - end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + it_behaves_like 'issue_edit snowplow tracking' do + subject(:execute_service_action) { service_action } + end end it 'tracks merge request usage data' do diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb index ae7bea30944..989ca7b8df1 100644 --- a/spec/services/notes/update_service_spec.rb +++ b/spec/services/notes/update_service_spec.rb @@ -47,21 +47,31 @@ RSpec.describe Notes::UpdateService do end end - it 'does not track usage data when params is blank' do - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action) - expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_edit_comment_action) + describe 'event tracking', :snowplow do + let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED } - update_note({}) - end + it 'does not track usage data when params is blank' do + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_edit_comment_action) - it 'tracks issue usage data', :clean_gitlab_redis_shared_state do - event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED - counter = Gitlab::UsageDataCounters::HLLRedisCounter + update_note({}) + end - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_edited_action).with(author: user).and_call_original - expect do - update_note(note: 'new text') - end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + it 'tracks issue usage data', :clean_gitlab_redis_shared_state do + counter = Gitlab::UsageDataCounters::HLLRedisCounter + + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_edited_action) + .with(author: user, project: project) + .and_call_original + expect do + update_note(note: 'new text') + end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + end + + it_behaves_like 'issue_edit snowplow tracking' do + let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED } + subject(:service_action) { update_note(note: 'new text') } + end end context 'when note text was changed' do diff --git a/spec/services/system_notes/issuables_service_spec.rb b/spec/services/system_notes/issuables_service_spec.rb index 70f6ce8926c..d0e68bf0ddb 100644 --- a/spec/services/system_notes/issuables_service_spec.rb +++ b/spec/services/system_notes/issuables_service_spec.rb @@ -712,15 +712,20 @@ RSpec.describe ::SystemNotes::IssuablesService do end end - context 'cloned to' do + context 'cloned to', :snowplow do let(:direction) { :to } it 'tracks usage' do expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter) - .to receive(:track_issue_cloned_action).with(author: author) + .to receive(:track_issue_cloned_action).with(author: author, project: project ) subject end + + it_behaves_like 'issue_edit snowplow tracking' do + let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_CLONED } + let(:user) { author } + end end end end diff --git a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb index c2b26d4decd..481e11bcf0e 100644 --- a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb @@ -74,12 +74,10 @@ RSpec.shared_examples 'a daily tracked issuable snowplow and service ping events end end -RSpec.shared_examples 'a daily tracked issuable snowplow and service ping events' do +RSpec.shared_examples 'daily tracked issuable snowplow and service ping events with project' do it_behaves_like 'a daily tracked issuable snowplow and service ping events for given event params' do - let_it_be(:track_params) { { project: project } } - let_it_be(:event_params) { track_params.merge(namespace: project.namespace) } - let_it_be(:category) { 'issues_edit' } - let_it_be(:event_action) { action } + let(:track_params) { { project: project } } + let(:event_params) { track_params.merge(label: event_label, property: event_property, namespace: project.namespace) } end end diff --git a/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb b/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb new file mode 100644 index 00000000000..0687be6f429 --- /dev/null +++ b/spec/support/shared_examples/services/snowplow_tracking_shared_examples.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +shared_examples 'issue_edit snowplow tracking' do + let(:category) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_CATEGORY } + let(:action) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_ACTION } + let(:label) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_LABEL } + let(:namespace) { project.namespace } + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + + it_behaves_like 'Snowplow event tracking' +end |