1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::EmailCampaignsController, feature_category: :navigation do
using RSpec::Parameterized::TableSyntax
describe 'GET #index', :snowplow do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) }
let(:track) { 'create' }
let(:series) { '0' }
let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL }
let(:subject_line_text) { Gitlab::Email::Message::InProductMarketing.for(track.to_sym).new(group: group, user: user, series: series.to_i).subject_line }
let(:data) do
{
namespace_id: group.id,
track: track.to_sym,
series: series.to_i,
subject_line: subject_line_text
}
end
before do
sign_in(user)
group.add_developer(user)
end
subject do
get group_email_campaigns_url(group, track: track, series: series)
response
end
shared_examples 'track and redirect' do
it 'redirects' do
expect(subject).to have_gitlab_http_status(:redirect)
end
context 'on SaaS', :saas do
it 'emits a snowplow event', :snowplow do
subject
expect_snowplow_event(
category: described_class.name,
action: 'click',
context: [{
schema: described_class::EMAIL_CAMPAIGNS_SCHEMA_URL,
data: { namespace_id: group.id, series: series.to_i, subject_line: subject_line_text, track: track.to_s }
}],
user: user,
namespace: group
)
end
it 'does not save the cta_click' do
expect(Users::InProductMarketingEmail).not_to receive(:save_cta_click)
subject
end
end
context 'when not on.com' do
it 'saves the cta_click' do
expect(Users::InProductMarketingEmail).to receive(:save_cta_click)
subject
end
it 'does not track snowplow events' do
subject
expect_no_snowplow_event
end
end
end
shared_examples 'no track and 404' do
it 'returns 404' do
expect(subject).to have_gitlab_http_status(:not_found)
end
it 'does not emit a snowplow event', :snowplow do
subject
expect_no_snowplow_event
end
end
describe 'track parameter' do
context 'when valid' do
where(track: Namespaces::InProductMarketingEmailsService::TRACKS.keys.without(:experience))
with_them do
it_behaves_like 'track and redirect'
end
end
context 'when invalid' do
where(track: [nil, 'xxxx'])
with_them do
it_behaves_like 'no track and 404'
end
end
end
describe 'series parameter' do
context 'when valid' do
where(series: (0..Namespaces::InProductMarketingEmailsService::TRACKS[:create][:interval_days].length - 1).to_a)
with_them do
it_behaves_like 'track and redirect'
end
end
context 'when invalid' do
where(series: [-1, nil, Namespaces::InProductMarketingEmailsService::TRACKS[:create][:interval_days].length])
with_them do
it_behaves_like 'no track and 404'
end
end
end
end
end
|