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
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
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
context 'when part of the onboarding issues experiment' do
before do
allow(controller.helpers).to receive(:in_subscription_flow?).and_return(true)
stub_experiment_for_user(onboarding_issues: true)
end
it { is_expected.not_to redirect_to new_users_sign_up_group_path }
end
it { is_expected.to redirect_to new_users_sign_up_group_path }
context 'when in invitation flow' do
before do
allow(controller.helpers).to receive(:in_invitation_flow?).and_return(true)
context 'when in subscription flow' do
before do
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
it { is_expected.not_to redirect_to new_users_sign_up_group_path }
end
context 'when in invitation flow' do
before do
allow(controller.helpers).to receive(:in_invitation_flow?).and_return(true)
end
context 'when in trial flow' do
before do
allow(controller.helpers).to receive(:in_trial_flow?).and_return(true)
it { is_expected.not_to redirect_to new_users_sign_up_group_path }
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
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
where(:on_gitlab_com, :experiment_enabled, :in_subscription_flow, :in_invitation_flow, :in_trial_flow, :experiment_enabled_for_user, :experiment_group) do
false | false | false | false | false | true | nil
false | false | false | true | false | true | nil
false | false | true | false | false | true | nil
false | false | true | true | false | true | nil
false | true | false | false | false | true | nil
false | true | false | true | false | true | nil
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
let(:on_gitlab_com) { false }
let(:experiment_enabled) { false }
let(:experiment_enabled_for_user) { false }
let(:in_subscription_flow) { false }
let(:in_invitation_flow) { false }
let(:in_oauth_flow) { false }
let(:in_trial_flow) { false }
before do
allow(::Gitlab).to receive(:com?).and_return(on_gitlab_com)
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_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)
end
with_them do
before do
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
context 'when on GitLab.com' do
let(:on_gitlab_com) { true }
it 'adds a user to experiments when appropriate' do
if experiment_group
expect(::Experiment).to receive(:add_user).with(:onboarding_issues, experiment_group, user)
else
expect(::Experiment).not_to receive(:add_user)
context 'and the onboarding issues experiment is enabled' do
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
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
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
it 'tracks a signed_up event when appropriate' do
if experiment_group
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues',
'signed_up',
label: anything,
property: "#{experiment_group}_group"
)
else
expect(Gitlab::Tracking).not_to receive(:event)
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
update_registration
it 'does not track a signed_up event' do
expect(Gitlab::Tracking).not_to receive(:event)
update_registration
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