Commit 1118c24c authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'nicolasdular/clean-up-snowplow-specs' into 'master'

Use snowplow test helper

See merge request gitlab-org/gitlab!46028
parents 55a0089f 37540943
......@@ -186,18 +186,12 @@ RSpec/ExpectChange:
# Offense count: 47
RSpec/ExpectGitlabTracking:
Exclude:
- 'ee/spec/controllers/projects/settings/operations_controller_spec.rb'
- 'ee/spec/requests/api/visual_review_discussions_spec.rb'
- 'ee/spec/services/epics/issue_promote_service_spec.rb'
- 'spec/controllers/groups/registry/repositories_controller_spec.rb'
- 'spec/controllers/projects/registry/repositories_controller_spec.rb'
- 'spec/controllers/projects/registry/tags_controller_spec.rb'
- 'spec/controllers/projects/settings/operations_controller_spec.rb'
- 'spec/controllers/registrations_controller_spec.rb'
- 'spec/lib/api/helpers_spec.rb'
- 'spec/requests/api/project_container_repositories_spec.rb'
- 'spec/support/shared_examples/controllers/trackable_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/discussions_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/packages_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/tracking_shared_examples.rb'
......
......@@ -42,15 +42,15 @@ RSpec.describe API::VisualReviewDiscussions do
expect { request }.to change(merge_request.notes, :count).by(1)
end
it 'tracks a visual review feedback event' do
expect(Gitlab::Tracking).to receive(:event) do |category, action, data|
expect(category).to eq('Notes::CreateService')
expect(action).to eq('execute')
expect(data[:label]).to eq('anonymous_visual_review_note')
expect(data[:value]).to be_an(Integer)
end
it 'tracks a visual review feedback event', :snowplow do
request
expect_snowplow_event(
category: 'Notes::CreateService',
action: 'execute',
label: 'anonymous_visual_review_note',
value: merge_request.notes.last.id
)
end
context 'with notes_create_service_tracking feature flag disabled' do
......
......@@ -57,15 +57,16 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
end
end
context 'when promoting issue' do
context 'when promoting issue', :snowplow do
let!(:issue_mentionable_note) { create(:note, noteable: issue, author: user, project: project, note: "note with mention #{user.to_reference}") }
let!(:issue_note) { create(:note, noteable: issue, author: user, project: project, note: "note without mention") }
before do
allow(Gitlab::Tracking).to receive(:event).with('epics', 'promote', an_instance_of(Hash))
allow(ProductAnalytics::Tracker).to receive(:event).with('epics', 'promote', an_instance_of(Hash))
subject.execute(issue)
expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id)
end
it 'creates a new epic with correct attributes' do
......@@ -188,9 +189,8 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
end
end
context 'when issue has notes' do
context 'when issue has notes', :snowplow do
before do
allow(Gitlab::Tracking).to receive(:event).with('epics', 'promote', an_instance_of(Hash))
allow(ProductAnalytics::Tracker).to receive(:event).with('epics', 'promote', an_instance_of(Hash))
issue.reload
end
......@@ -202,6 +202,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
expect(epic.notes.count).to eq(issue.notes.count)
expect(epic.notes.where(discussion_id: discussion.discussion_id).count).to eq(0)
expect(issue.notes.where(discussion_id: discussion.discussion_id).count).to eq(1)
expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id)
end
it 'copies note attachments' do
......@@ -210,6 +211,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
epic = subject.execute(issue)
expect(epic.notes.user.first.attachment).to be_kind_of(AttachmentUploader)
expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id)
end
end
......
......@@ -64,12 +64,11 @@ RSpec.describe Groups::Registry::RepositoriesController do
context 'html format' do
let(:format) { :html }
it 'show index page' do
expect(Gitlab::Tracking).not_to receive(:event)
it 'show index page', :snowplow do
subject
expect(response).to have_gitlab_http_status(:ok)
expect_no_snowplow_event
end
end
......
......@@ -117,15 +117,10 @@ RSpec.shared_examples 'discussions API' do |parent_type, noteable_type, id_name,
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'tracks a Notes::CreateService event' do
expect(Gitlab::Tracking).to receive(:event) do |category, action, data|
expect(category).to eq('Notes::CreateService')
expect(action).to eq('execute')
expect(data[:label]).to eq('note')
expect(data[:value]).to be_an(Integer)
end
it 'tracks a Notes::CreateService event', :snowplow do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), params: { body: 'hi!' }
expect_snowplow_event(category: 'Notes::CreateService', action: 'execute', label: 'note', value: anything)
end
context 'with notes_create_service_tracking feature flag disabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment