Commit bb19877a authored by Arturo Herrero's avatar Arturo Herrero

Merge branch...

Merge branch '300557-follow-up-from-add-click-tracking-to-in-product-marketing-email-campaigns' into 'master'

Resolve "Follow-up from "Add click tracking to in product marketing email campaigns""

See merge request gitlab-org/gitlab!53029
parents b50d85b0 ba9feac9
...@@ -12,6 +12,15 @@ RSpec.describe Groups::EmailCampaignsController do ...@@ -12,6 +12,15 @@ RSpec.describe Groups::EmailCampaignsController do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:track) { 'create' } let(:track) { 'create' }
let(:series) { '0' } let(:series) { '0' }
let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL }
let(:data) do
{
namespace_id: group.id,
track: track.to_sym,
series: series.to_i,
subject_line: subject_line(track.to_sym, series.to_i)
}
end
before do before do
sign_in(user) sign_in(user)
...@@ -19,72 +28,58 @@ RSpec.describe Groups::EmailCampaignsController do ...@@ -19,72 +28,58 @@ RSpec.describe Groups::EmailCampaignsController do
allow(Gitlab::Tracking).to receive(:self_describing_event) allow(Gitlab::Tracking).to receive(:self_describing_event)
end end
subject(:get_index) do subject do
get group_email_campaigns_url(group, track: track, series: series) get group_email_campaigns_url(group, track: track, series: series)
response response
end end
RSpec::Matchers.define :track_event do |*args| shared_examples 'track and redirect' do
match do it do
expect(Gitlab::Tracking).to have_received(:self_describing_event).with( is_expected.to track_self_describing_event(schema, data)
described_class::EMAIL_CAMPAIGNS_SCHEMA_URL, is_expected.to have_gitlab_http_status(:redirect)
data: { end
namespace_id: group.id,
track: track.to_sym,
series: series.to_i,
subject_line: subject_line(track.to_sym, series.to_i)
}
)
end end
match_when_negated do shared_examples 'no track and 404' do
expect(Gitlab::Tracking).not_to have_received(:self_describing_event) it do
is_expected.not_to track_self_describing_event
is_expected.to have_gitlab_http_status(:not_found)
end end
end end
context 'track parameter' do describe 'track parameter' do
where(:track, :valid) do context 'when valid' do
'create' | true where(track: Namespaces::InProductMarketingEmailsService::TRACKS.keys)
'verify' | true
'trial' | true
'team' | true
'xxxx' | false
nil | false
end
with_them do with_them do
it do it_behaves_like 'track and redirect'
if valid
is_expected.to track_event
is_expected.to have_gitlab_http_status(:redirect)
else
is_expected.not_to track_event
is_expected.to have_gitlab_http_status(:not_found)
end end
end end
context 'when invalid' do
where(track: [nil, 'xxxx'])
with_them do
it_behaves_like 'no track and 404'
end end
end end
context 'series parameter' do
where(:series, :valid) do
'0' | true
'1' | true
'2' | true
'-1' | false
'3' | false
nil | false
end end
describe 'series parameter' do
context 'when valid' do
where(series: (0..Namespaces::InProductMarketingEmailsService::INTERVAL_DAYS.length - 1).to_a)
with_them do with_them do
it do it_behaves_like 'track and redirect'
if valid
is_expected.to track_event
is_expected.to have_gitlab_http_status(:redirect)
else
is_expected.not_to track_event
is_expected.to have_gitlab_http_status(:not_found)
end end
end end
context 'when invalid' do
where(series: [-1, nil, Namespaces::InProductMarketingEmailsService::INTERVAL_DAYS.length])
with_them do
it_behaves_like 'no track and 404'
end
end end
end end
end end
......
# frozen_string_literal: true
RSpec::Matchers.define :track_self_describing_event do |schema, data|
match do
expect(Gitlab::Tracking).to have_received(:self_describing_event)
.with(schema, data: data)
end
match_when_negated do
expect(Gitlab::Tracking).not_to have_received(:self_describing_event)
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