Commit fc7c71d6 authored by Dallas Reedy's avatar Dallas Reedy

Refactor the EE::RegistrationsController spec

- Separate out the two sub-sections of the #update_registration tests
- Improve test readability by dissolving complex table-syntax into
more expressive, direct, & structured tests based on code path
possibilities
parent bcbc7388
...@@ -63,6 +63,7 @@ RSpec.describe RegistrationsController do ...@@ -63,6 +63,7 @@ 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' } } }
describe 'redirection' do
it { is_expected.to redirect_to dashboard_projects_path } 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
...@@ -96,66 +97,103 @@ RSpec.describe RegistrationsController do ...@@ -96,66 +97,103 @@ RSpec.describe RegistrationsController do
it { is_expected.not_to redirect_to new_users_sign_up_group_path } 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
true | false | false | false | false | true | nil
true | false | false | true | false | true | nil
true | false | true | false | false | true | nil
true | false | true | true | false | true | nil
true | true | false | false | false | true | :experimental
true | true | false | false | false | false | :control
true | true | true | false | false | true | nil
true | true | false | true | false | true | nil
true | true | false | false | true | true | nil
true | true | true | true | true | true | nil
end
with_them do
before do before do
allow(::Gitlab).to receive(:com?).and_return(on_gitlab_com) allow(::Gitlab).to receive(:com?).and_return(on_gitlab_com)
stub_experiment(onboarding_issues: experiment_enabled) stub_experiment(onboarding_issues: experiment_enabled)
stub_experiment_for_user(onboarding_issues: experiment_enabled_for_user)
allow(controller.helpers).to receive(:in_subscription_flow?).and_return(in_subscription_flow) 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_invitation_flow?).and_return(in_invitation_flow)
allow(controller.helpers).to receive(:in_oauth_flow?).and_return(in_oauth_flow)
allow(controller.helpers).to receive(:in_trial_flow?).and_return(in_trial_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 end
it 'adds a user to experiments when appropriate' do context 'when on GitLab.com' do
if experiment_group let(:on_gitlab_com) { true }
expect(::Experiment).to receive(:add_user).with(:onboarding_issues, experiment_group, user)
else context 'and the onboarding issues experiment is enabled' do
expect(::Experiment).not_to receive(:add_user) let(:experiment_enabled) { true }
context 'and we’re not in the subscription, invitation, oauth, or trial flow' do
where(:experiment_enabled_for_user, :group_type) do
true | :experimental
false | :control
end 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 update_registration
end end
it 'tracks a signed_up event when appropriate' do it 'tracks a signed_up event' do
if experiment_group
expect(Gitlab::Tracking).to receive(:event).with( expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues', 'Growth::Conversion::Experiment::OnboardingIssues',
'signed_up', 'signed_up',
label: anything, label: anything,
property: "#{experiment_group}_group" property: "#{group_type}_group"
) )
else
update_registration
end
end
end
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) expect(Gitlab::Tracking).not_to receive(:event)
update_registration
end
end
end
end
end end
context 'when not on GitLab.com, regardless of whether or not the experiment is enabled' do
where(experiment_enabled: [true, false])
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 update_registration
end end
end end
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