Commit 6d4989d8 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'ali/improve-testability-of-standard-context' into 'master'

Add standard_context to Snowplow test helper [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!52375
parents f1b43a88 2c0ec5e5
...@@ -767,12 +767,14 @@ describe '#show', :snowplow do ...@@ -767,12 +767,14 @@ describe '#show', :snowplow do
expect_snowplow_event( expect_snowplow_event(
category: 'Experiment', category: 'Experiment',
action: 'start', action: 'start',
standard_context: { namespace: group, project: project }
) )
expect_snowplow_event( expect_snowplow_event(
category: 'Experiment', category: 'Experiment',
action: 'sent', action: 'sent',
property: 'property', property: 'property',
label: 'label' label: 'label',
standard_context: { namespace: group, project: project }
) )
end end
end end
......
...@@ -65,7 +65,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do ...@@ -65,7 +65,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
subject.execute(issue) subject.execute(issue)
expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id, expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id,
standard_context: kind_of(Gitlab::Tracking::StandardContext)) standard_context: { namespace: group, project: project })
end end
it 'creates a new epic with correct attributes' do it 'creates a new epic with correct attributes' do
...@@ -201,7 +201,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do ...@@ -201,7 +201,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
expect(epic.notes.where(discussion_id: discussion.discussion_id).count).to eq(0) 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(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, expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id,
standard_context: kind_of(Gitlab::Tracking::StandardContext)) standard_context: { namespace: group, project: project })
end end
it 'copies note attachments' do it 'copies note attachments' do
...@@ -211,7 +211,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do ...@@ -211,7 +211,7 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
expect(epic.notes.user.first.attachment).to be_kind_of(AttachmentUploader) expect(epic.notes.user.first.attachment).to be_kind_of(AttachmentUploader)
expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id, expect_snowplow_event(category: 'epics', action: 'promote', property: 'issue_id', value: issue.id,
standard_context: kind_of(Gitlab::Tracking::StandardContext)) standard_context: { namespace: group, project: project })
end end
end end
......
...@@ -46,7 +46,7 @@ module SnowplowHelpers ...@@ -46,7 +46,7 @@ module SnowplowHelpers
# } # }
# ] # ]
# ) # )
def expect_snowplow_event(category:, action:, context: nil, **kwargs) def expect_snowplow_event(category:, action:, context: nil, standard_context: nil, **kwargs)
if context if context
kwargs[:context] = [] kwargs[:context] = []
context.each do |c| context.each do |c|
...@@ -56,6 +56,14 @@ module SnowplowHelpers ...@@ -56,6 +56,14 @@ module SnowplowHelpers
end end
end end
if standard_context
expect(Gitlab::Tracking::StandardContext)
.to have_received(:new)
.with(**standard_context)
kwargs[:standard_context] = an_instance_of(Gitlab::Tracking::StandardContext)
end
expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
.with(category, action, **kwargs).at_least(:once) .with(category, action, **kwargs).at_least(:once)
end end
......
...@@ -18,6 +18,7 @@ RSpec.configure do |config| ...@@ -18,6 +18,7 @@ RSpec.configure do |config|
stub_application_setting(snowplow_enabled: true) stub_application_setting(snowplow_enabled: true)
allow(SnowplowTracker::SelfDescribingJson).to receive(:new).and_call_original allow(SnowplowTracker::SelfDescribingJson).to receive(:new).and_call_original
allow(Gitlab::Tracking::StandardContext).to receive(:new).and_call_original
allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking
end end
......
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