Skip to content
Snippets Groups Projects
Commit 6d4989d8 authored by Arturo Herrero's avatar Arturo Herrero
Browse files

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

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

See merge request !52375
parents f1b43a88 2c0ec5e5
No related branches found
No related tags found
3 merge requests!53395Handle unreachable ES host in settings check,!52525[Part 1] Break down pipeline editor into smaller components,!52375Add standard_context to Snowplow test helper [RUN AS-IF-FOSS]
Pipeline #246980246 passed
......@@ -767,12 +767,14 @@ describe '#show', :snowplow do
expect_snowplow_event(
category: 'Experiment',
action: 'start',
standard_context: { namespace: group, project: project }
)
expect_snowplow_event(
category: 'Experiment',
action: 'sent',
property: 'property',
label: 'label'
label: 'label',
standard_context: { namespace: group, project: project }
)
end
end
......
......@@ -65,7 +65,7 @@
subject.execute(issue)
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
it 'creates a new epic with correct attributes' do
......@@ -201,7 +201,7 @@
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,
standard_context: kind_of(Gitlab::Tracking::StandardContext))
standard_context: { namespace: group, project: project })
end
it 'copies note attachments' do
......@@ -211,7 +211,7 @@
expect(epic.notes.user.first.attachment).to be_kind_of(AttachmentUploader)
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
......
......@@ -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
kwargs[:context] = []
context.each do |c|
......@@ -56,6 +56,14 @@ def expect_snowplow_event(category:, action:, context: nil, **kwargs)
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
.with(category, action, **kwargs).at_least(:once)
end
......
......@@ -18,6 +18,7 @@
stub_application_setting(snowplow_enabled: true)
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
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment