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