Commit 8ee39de1 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'refactor-ee-spec-controllers-registrations-controller-spec' into 'master'

Refactor the EE::RegistrationsController spec

See merge request gitlab-org/gitlab!40683
parents 44bb86cd fc7c71d6
...@@ -63,97 +63,135 @@ RSpec.describe RegistrationsController do ...@@ -63,97 +63,135 @@ RSpec.describe RegistrationsController do
subject(:update_registration) { patch :update_registration, params: { user: { role: 'software_developer', setup_for_company: 'false' } } } subject(:update_registration) { patch :update_registration, params: { user: { role: 'software_developer', setup_for_company: 'false' } } }
it { is_expected.to redirect_to dashboard_projects_path } describe 'redirection' do
it { is_expected.to redirect_to dashboard_projects_path }
context 'when part of the onboarding issues experiment' do context 'when part of the onboarding issues experiment' do
before do
stub_experiment_for_user(onboarding_issues: true)
end
it { is_expected.to redirect_to new_users_sign_up_group_path }
context 'when in subscription flow' do
before do before do
allow(controller.helpers).to receive(:in_subscription_flow?).and_return(true) stub_experiment_for_user(onboarding_issues: true)
end end
it { is_expected.not_to redirect_to new_users_sign_up_group_path } it { is_expected.to redirect_to new_users_sign_up_group_path }
end
context 'when in invitation flow' do context 'when in subscription flow' do
before do before do
allow(controller.helpers).to receive(:in_invitation_flow?).and_return(true) allow(controller.helpers).to receive(:in_subscription_flow?).and_return(true)
end
it { is_expected.not_to redirect_to new_users_sign_up_group_path }
end end
it { is_expected.not_to redirect_to new_users_sign_up_group_path } context 'when in invitation flow' do
end before do
allow(controller.helpers).to receive(:in_invitation_flow?).and_return(true)
end
context 'when in trial flow' do it { is_expected.not_to redirect_to new_users_sign_up_group_path }
before do
allow(controller.helpers).to receive(:in_trial_flow?).and_return(true)
end end
it { is_expected.not_to redirect_to new_users_sign_up_group_path } context 'when in trial flow' do
before do
allow(controller.helpers).to receive(:in_trial_flow?).and_return(true)
end
it { is_expected.not_to redirect_to new_users_sign_up_group_path }
end
end end
end end
describe 'recording experiment user and track for the onboarding issues experiment' do describe 'recording the user and tracking events for the onboarding issues experiment' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:on_gitlab_com, :experiment_enabled, :in_subscription_flow, :in_invitation_flow, :in_trial_flow, :experiment_enabled_for_user, :experiment_group) do let(:on_gitlab_com) { false }
false | false | false | false | false | true | nil let(:experiment_enabled) { false }
false | false | false | true | false | true | nil let(:experiment_enabled_for_user) { false }
false | false | true | false | false | true | nil let(:in_subscription_flow) { false }
false | false | true | true | false | true | nil let(:in_invitation_flow) { false }
false | true | false | false | false | true | nil let(:in_oauth_flow) { false }
false | true | false | true | false | true | nil let(:in_trial_flow) { false }
false | true | true | false | false | true | nil
false | true | true | true | false | true | nil before do
true | false | false | false | false | true | nil allow(::Gitlab).to receive(:com?).and_return(on_gitlab_com)
true | false | false | true | false | true | nil stub_experiment(onboarding_issues: experiment_enabled)
true | false | true | false | false | true | nil stub_experiment_for_user(onboarding_issues: experiment_enabled_for_user)
true | false | true | true | false | true | nil allow(controller.helpers).to receive(:in_subscription_flow?).and_return(in_subscription_flow)
true | true | false | false | false | true | :experimental allow(controller.helpers).to receive(:in_invitation_flow?).and_return(in_invitation_flow)
true | true | false | false | false | false | :control allow(controller.helpers).to receive(:in_oauth_flow?).and_return(in_oauth_flow)
true | true | true | false | false | true | nil allow(controller.helpers).to receive(:in_trial_flow?).and_return(in_trial_flow)
true | true | false | true | false | true | nil
true | true | false | false | true | true | nil
true | true | true | true | true | true | nil
end end
with_them do context 'when on GitLab.com' do
before do let(:on_gitlab_com) { true }
allow(::Gitlab).to receive(:com?).and_return(on_gitlab_com)
stub_experiment(onboarding_issues: experiment_enabled)
allow(controller.helpers).to receive(:in_subscription_flow?).and_return(in_subscription_flow)
allow(controller.helpers).to receive(:in_invitation_flow?).and_return(in_invitation_flow)
allow(controller.helpers).to receive(:in_trial_flow?).and_return(in_trial_flow)
stub_experiment_for_user(onboarding_issues: experiment_enabled_for_user)
end
it 'adds a user to experiments when appropriate' do context 'and the onboarding issues experiment is enabled' do
if experiment_group let(:experiment_enabled) { true }
expect(::Experiment).to receive(:add_user).with(:onboarding_issues, experiment_group, user)
else context 'and we’re not in the subscription, invitation, oauth, or trial flow' do
expect(::Experiment).not_to receive(:add_user) where(:experiment_enabled_for_user, :group_type) do
true | :experimental
false | :control
end
with_them do
it 'adds the user to the experiments table with the correct group_type' do
expect(::Experiment).to receive(:add_user).with(:onboarding_issues, group_type, user)
update_registration
end
it 'tracks a signed_up event' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues',
'signed_up',
label: anything,
property: "#{group_type}_group"
)
update_registration
end
end
end end
update_registration context 'but we’re in the subscription, invitation, oauth, or trial flow' do
where(:in_subscription_flow, :in_invitation_flow, :in_oauth_flow, :in_trial_flow) do
true | false | false | false
false | true | false | false
false | false | true | false
false | false | false | true
end
with_them do
it 'does not add the user to the experiments table' do
expect(::Experiment).not_to receive(:add_user)
update_registration
end
it 'does not track a signed_up event' do
expect(Gitlab::Tracking).not_to receive(:event)
update_registration
end
end
end
end end
end
it 'tracks a signed_up event when appropriate' do context 'when not on GitLab.com, regardless of whether or not the experiment is enabled' do
if experiment_group where(experiment_enabled: [true, false])
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues', with_them do
'signed_up', it 'does not add the user to the experiments table' do
label: anything, expect(::Experiment).not_to receive(:add_user)
property: "#{experiment_group}_group"
) update_registration
else
expect(Gitlab::Tracking).not_to receive(:event)
end end
update_registration it 'does not track a signed_up event' do
expect(Gitlab::Tracking).not_to receive(:event)
update_registration
end
end end
end end
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