Commit d47ebd07 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'allow-access-to-trials-controllers-in-dev-env' into 'master'

Allow access to trials controllers in dev env

See merge request gitlab-org/gitlab!35092
parents 731bd999 53d801c4
...@@ -9,8 +9,8 @@ module EE ...@@ -9,8 +9,8 @@ module EE
around_action :set_current_ip_address around_action :set_current_ip_address
end end
def check_if_gl_com def check_if_gl_com_or_dev
render_404 unless ::Gitlab.com? render_404 unless ::Gitlab.dev_env_or_com?
end end
def verify_namespace_plan_check_enabled def verify_namespace_plan_check_enabled
......
...@@ -7,7 +7,7 @@ class TrialRegistrationsController < RegistrationsController ...@@ -7,7 +7,7 @@ class TrialRegistrationsController < RegistrationsController
skip_before_action :require_no_authentication skip_before_action :require_no_authentication
before_action :check_if_gl_com before_action :check_if_gl_com_or_dev
before_action :set_redirect_url, only: [:new] before_action :set_redirect_url, only: [:new]
def new def new
......
...@@ -5,7 +5,7 @@ class TrialsController < ApplicationController ...@@ -5,7 +5,7 @@ class TrialsController < ApplicationController
layout 'trial' layout 'trial'
before_action :check_if_gl_com before_action :check_if_gl_com_or_dev
before_action :authenticate_user! before_action :authenticate_user!
before_action :find_or_create_namespace, only: :apply before_action :find_or_create_namespace, only: :apply
......
...@@ -3,47 +3,57 @@ ...@@ -3,47 +3,57 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe TrialRegistrationsController do RSpec.describe TrialRegistrationsController do
describe '#new' do let(:dev_env_or_com) { true }
let(:user) { create(:user) }
before do before do
allow(Gitlab).to receive(:com?).and_return(true) allow(Gitlab).to receive(:dev_env_or_com?).and_return(dev_env_or_com)
end end
context 'when customer is authenticated' do shared_examples 'a dot-com only feature' do
before do let(:success_status) { :ok }
sign_in(user)
end
it 'redirects to the new trial page' do context 'when not on gitlab.com and not in development environment' do
get :new let(:dev_env_or_com) { false }
expect(response).to redirect_to(new_trial_url) it { is_expected.to have_gitlab_http_status(:not_found) }
end end
it 'redirect keeps the query string parameters' do context 'when on gitlab.com or in dev environment' do
get_params = { glm_source: 'some_source', glm_content: 'some_content' } it { is_expected.to have_gitlab_http_status(success_status) }
end
end
describe '#new' do
let(:logged_in_user) { nil }
let(:get_params) { {} }
before do
sign_in(logged_in_user) if logged_in_user.present?
get :new, params: get_params get :new, params: get_params
end
subject { response }
it_behaves_like 'a dot-com only feature'
context 'when customer is authenticated' do
let_it_be(:logged_in_user) { create(:user) }
it { is_expected.to redirect_to(new_trial_url) }
expect(response).to redirect_to(new_trial_url(get_params)) context 'when there are additional query params' do
let(:get_params) { { glm_source: 'some_source', glm_content: 'some_content' } }
it { is_expected.to redirect_to(new_trial_url(get_params)) }
end end
end end
context 'when customer is not authenticated' do context 'when customer is not authenticated' do
it 'renders the regular template' do it { is_expected.to render_template(:new) }
get :new
expect(response).to render_template(:new)
end
end end
end end
describe '#create' do describe '#create' do
before do
stub_application_setting(send_user_confirmation_email: true)
end
let(:user_params) do let(:user_params) do
{ {
first_name: 'John', first_name: 'John',
...@@ -54,36 +64,24 @@ RSpec.describe TrialRegistrationsController do ...@@ -54,36 +64,24 @@ RSpec.describe TrialRegistrationsController do
} }
end end
context 'when invalid - instance is not GL.com' do
before do before do
allow(Gitlab).to receive(:com?).and_return(false) stub_application_setting(send_user_confirmation_email: true)
end
it 'returns 404 not found' do
post :create, params: { user: user_params } post :create, params: { user: user_params }
expect(response).to have_gitlab_http_status(:not_found)
end
end end
context 'when valid' do it_behaves_like 'a dot-com only feature' do
before do let(:success_status) { :found }
allow(Gitlab).to receive(:com?).and_return(true) subject { response }
end end
it 'marks the account as unconfirmed' do it 'marks the account as unconfirmed' do
post :create, params: { user: user_params }
expect(User.last).not_to be_confirmed expect(User.last).not_to be_confirmed
end end
context 'derivation of name' do context 'derivation of name' do
it 'sets name from first and last name' do it 'sets name from first and last name' do
post :create, params: { user: user_params }
expect(User.last.name).to eq("#{user_params[:first_name]} #{user_params[:last_name]}") expect(User.last.name).to eq("#{user_params[:first_name]} #{user_params[:last_name]}")
end end
end end
end end
end
end end
...@@ -3,74 +3,87 @@ ...@@ -3,74 +3,87 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe TrialsController do RSpec.describe TrialsController do
shared_examples 'an authenticated endpoint' do |verb, action| let_it_be(:user) { create(:user, email_opted_in: true) }
it 'redirects to login page' do
send(verb, action)
expect(response).to redirect_to(new_trial_registration_url) let(:dev_env_or_com) { true }
end let(:logged_in) { true }
end
before do before do
allow(::Gitlab).to receive(:com?).and_return(true) allow(::Gitlab).to receive(:dev_env_or_com?).and_return(dev_env_or_com)
sign_in(user) if logged_in
end end
describe '#new' do shared_examples 'an authenticated endpoint' do
it_behaves_like 'an authenticated endpoint', :get, :new let(:success_status) { :ok }
context 'when invalid - instance is not GL.com' do context 'when not authenticated' do
it 'returns 404 not found' do let(:logged_in) { false }
allow(::Gitlab).to receive(:com?).and_return(false)
get :new it { is_expected.to redirect_to(new_trial_registration_url) }
end
expect(response).to have_gitlab_http_status(:not_found) context 'when authenticated' do
it { is_expected.to have_gitlab_http_status(success_status) }
end end
end end
shared_examples 'a dot-com only feature' do
let(:success_status) { :ok }
context 'when not on gitlab.com and not in development environment' do
let(:dev_env_or_com) { false }
it { is_expected.to have_gitlab_http_status(:not_found) }
end end
describe '#create_lead' do context 'when on gitlab.com or in dev environment' do
it_behaves_like 'an authenticated endpoint', :post, :create_lead it { is_expected.to have_gitlab_http_status(success_status) }
end
end
describe 'authenticated' do describe '#new' do
let(:user) { create(:user, email_opted_in: true) } subject do
let(:create_lead_result) { nil } get :new
response
end
before do it_behaves_like 'an authenticated endpoint'
sign_in(user) it_behaves_like 'a dot-com only feature'
end end
context 'response url' do describe '#create_lead' do
let(:post_params) { {} }
let(:create_lead_result) { nil }
before do before do
allow_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service| allow_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service|
expect(lead_service).to receive(:execute).and_return({ success: create_lead_result }) expect(lead_service).to receive(:execute).and_return({ success: create_lead_result })
end end
end end
subject do
post :create_lead, params: post_params
response
end
it_behaves_like 'an authenticated endpoint'
it_behaves_like 'a dot-com only feature'
context 'on success' do context 'on success' do
let(:create_lead_result) { true } let(:create_lead_result) { true }
it 'redirects user to Step 3' do it { is_expected.to redirect_to(select_trials_url) }
post :create_lead
expect(response).to redirect_to(select_trials_url)
end
end end
context 'on failure' do context 'on failure' do
let(:create_lead_result) { false } let(:create_lead_result) { false }
it 'renders the :new template' do it { is_expected.to render_template(:new) }
post :create_lead
expect(response).to render_template(:new)
end
end
end end
context 'request params to Lead Service' do context 'request params to Lead Service' do
it 'sends appropriate request params' do let(:post_params) do
params = { {
company_name: 'Gitlab', company_name: 'Gitlab',
company_size: '1-99', company_size: '1-99',
first_name: user.first_name, first_name: user.first_name,
...@@ -79,7 +92,10 @@ RSpec.describe TrialsController do ...@@ -79,7 +92,10 @@ RSpec.describe TrialsController do
number_of_users: "20", number_of_users: "20",
country: 'IN' country: 'IN'
} }
extra_params = { end
let(:extra_params) do
{
work_email: user.email, work_email: user.email,
uid: user.id, uid: user.id,
skip_email_confirmation: true, skip_email_confirmation: true,
...@@ -87,49 +103,62 @@ RSpec.describe TrialsController do ...@@ -87,49 +103,62 @@ RSpec.describe TrialsController do
provider: 'gitlab', provider: 'gitlab',
newsletter_segment: user.email_opted_in newsletter_segment: user.email_opted_in
} }
expected_params = ActionController::Parameters.new(params).merge(extra_params).permit! end
let(:expected_params) do
ActionController::Parameters.new(post_params).merge(extra_params).permit!
end
it 'sends appropriate request params' do
expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service| expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service|
expect(lead_service).to receive(:execute).with({ trial_user: expected_params }).and_return({ success: true }) expect(lead_service).to receive(:execute).with({ trial_user: expected_params }).and_return({ success: true })
end end
post :create_lead, params: params subject
end
end end
end end
end end
describe '#select' do describe '#select' do
it_behaves_like 'an authenticated endpoint', :get, :select subject do
get :select
response
end
it_behaves_like 'an authenticated endpoint'
it_behaves_like 'a dot-com only feature'
end end
describe '#apply' do describe '#apply' do
let(:user) { create(:user) } let_it_be(:namespace) { create(:namespace, owner_id: user.id, path: 'namespace-test') }
let(:namespace) { create(:namespace, owner_id: user.id, path: 'namespace-test') }
let(:apply_trial_result) { nil } let(:apply_trial_result) { nil }
let(:post_params) { { namespace_id: namespace.id } }
before do before do
sign_in(user)
allow_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do allow_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do
{ success: apply_trial_result } { success: apply_trial_result }
end end
end end
subject do
post :apply, params: post_params
response
end
it_behaves_like 'an authenticated endpoint'
it_behaves_like 'a dot-com only feature'
context 'on success' do context 'on success' do
let(:apply_trial_result) { true } let(:apply_trial_result) { true }
it "redirects to group's path with the parameter trial as true" do it { is_expected.to redirect_to("/#{namespace.path}?trial=true") }
post :apply, params: { namespace_id: namespace.id }
expect(response).to redirect_to("/#{namespace.path}?trial=true")
end
context 'with a new Group' do context 'with a new Group' do
let(:post_params) { { new_group_name: 'GitLab' } }
it 'creates the Group' do it 'creates the Group' do
expect do expect { subject }.to change { Group.count }.to(1)
post :apply, params: { new_group_name: 'GitLab' }
end.to change { Group.count }.to(1)
end end
end end
end end
...@@ -137,18 +166,15 @@ RSpec.describe TrialsController do ...@@ -137,18 +166,15 @@ RSpec.describe TrialsController do
context 'on failure' do context 'on failure' do
let(:apply_trial_result) { false } let(:apply_trial_result) { false }
it 'renders the :select view' do it { is_expected.to render_template(:select) }
post :apply, params: { namespace_id: namespace.id }
expect(response).to render_template(:select)
end
context 'with a new Group' do context 'with a new Group' do
it 'renders the :select view' do let(:post_params) { { new_group_name: 'admin' } }
post :apply, params: { new_group_name: 'admin' }
it { is_expected.to render_template(:select) }
expect(response).to render_template(:select) it 'does not create the Group' do
expect(Group.count).to eq(0) expect { subject }.not_to change { Group.count }.from(0)
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