2021-02-01 10:08:56 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Groups::EmailCampaignsController 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) }
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2021-02-01 10:08:56 -05:00
|
|
|
let(:track) { 'create' }
|
|
|
|
let(:series) { '0' }
|
|
|
|
let(:schema) { described_class::EMAIL_CAMPAIGNS_SCHEMA_URL }
|
2021-05-19 05:10:19 -04:00
|
|
|
let(:subject_line_text) { Gitlab::Email::Message::InProductMarketing.for(track.to_sym).new(group: group, user: user, series: series.to_i).subject_line }
|
2021-02-01 10:08:56 -05:00
|
|
|
let(:data) do
|
|
|
|
{
|
|
|
|
namespace_id: group.id,
|
|
|
|
track: track.to_sym,
|
|
|
|
series: series.to_i,
|
2021-04-01 14:13:56 -04:00
|
|
|
subject_line: subject_line_text
|
2021-02-01 10:08:56 -05:00
|
|
|
}
|
|
|
|
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
|
2021-04-01 14:13:56 -04:00
|
|
|
it 'redirects' do
|
|
|
|
expect(subject).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
|
2021-04-19 11:09:08 -04:00
|
|
|
context 'on .com' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:com?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
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 }
|
2021-06-01 23:09:51 -04:00
|
|
|
}],
|
|
|
|
user: user,
|
|
|
|
namespace: group
|
2021-04-19 11:09:08 -04:00
|
|
|
)
|
|
|
|
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
|
2021-02-01 10:08:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'no track and 404' do
|
2021-04-01 14:13:56 -04:00
|
|
|
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
|
2021-02-01 10:08:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'track parameter' do
|
|
|
|
context 'when valid' do
|
2022-03-28 11:07:51 -04:00
|
|
|
where(track: Namespaces::InProductMarketingEmailsService::TRACKS.keys.without(:experience))
|
2021-02-01 10:08:56 -05:00
|
|
|
|
|
|
|
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
|
2021-05-19 05:10:19 -04:00
|
|
|
where(series: (0..Namespaces::InProductMarketingEmailsService::TRACKS[:create][:interval_days].length - 1).to_a)
|
2021-02-01 10:08:56 -05:00
|
|
|
|
|
|
|
with_them do
|
|
|
|
it_behaves_like 'track and redirect'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when invalid' do
|
2021-05-19 05:10:19 -04:00
|
|
|
where(series: [-1, nil, Namespaces::InProductMarketingEmailsService::TRACKS[:create][:interval_days].length])
|
2021-02-01 10:08:56 -05:00
|
|
|
|
|
|
|
with_them do
|
|
|
|
it_behaves_like 'no track and 404'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|