Skip to content
代码片段 群组 项目
未验证 提交 0443654e 编辑于 作者: Doug Stull's avatar Doug Stull 提交者: GitLab
浏览文件

Merge branch '448438-add-feature-spec-for-duo-pro-trial' into 'master'

Add feature spec for duo pro trial /-/trials/duo_pro/new path

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/147374



Merged-by: default avatarDoug Stull <dstull@gitlab.com>
Approved-by: default avatarRoss Byrne <robyrne@gitlab.com>
Approved-by: default avatarDoug Stull <dstull@gitlab.com>
Co-authored-by: default avatarrliu-gl <rliu@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -18,7 +18,7 @@
= yield :before_form
= gitlab_ui_form_for '', url: trials_duo_pro_path(step: GitlabSubscriptions::Trials::CreateDuoProService::TRIAL), class: 'js-saas-duo-pro-trial-group' do |f|
= gitlab_ui_form_for '', url: trials_duo_pro_path(step: GitlabSubscriptions::Trials::CreateDuoProService::TRIAL), class: 'js-saas-duo-pro-trial-group', data: { testid: 'trial-form' } do |f|
.js-namespace-selector{ data: duo_pro_trial_namespace_selector_data(local_assigns[:namespace_create_errors]) }
- if should_ask_company_question?
.form-group
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Duo Pro trial lead submission and creation with multiple eligible namespaces', :saas_trial, :js, feature_category: :purchase do
# rubocop:disable Gitlab/RSpec/AvoidSetup -- skip registration and group creation
let_it_be(:user) { create(:user) }
let_it_be(:group) do
create(:group_with_plan, plan: :ultimate_plan).tap { |record| record.add_owner(user) }
create(:group_with_plan, plan: :ultimate_plan, name: 'gitlab').tap { |record| record.add_owner(user) }
end
# rubocop:enable Gitlab/RSpec/AvoidSetup
context 'when creating lead and applying trial is successful' do
it 'fills out form, submits and lands on the group usage quotas page' do
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
submit_duo_pro_trial_company_form
expect_to_be_on_namespace_selection
fill_in_trial_selection_form
submit_duo_pro_trial_selection_form
expect_to_be_on_group_usage_quotas_page
end
context 'when new trial is selected from within an existing namespace' do
it 'fills out form, has the existing namespace preselected, submits and lands on the group usage quotas page' do
sign_in(user)
visit new_trials_duo_pro_path(namespace_id: group.id)
fill_in_company_information
submit_duo_pro_trial_company_form
expect_to_be_on_namespace_selection
fill_in_trial_selection_form(from: group.name)
submit_duo_pro_trial_selection_form
expect_to_be_on_group_usage_quotas_page
end
end
end
context 'when applying lead fails' do
it 'fills out form, submits and sent back to information form with errors and is then resolved' do
# setup
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
# lead failure
submit_duo_pro_trial_company_form(lead_success: false)
expect_to_be_on_lead_form_with_errors
# success
submit_duo_pro_trial_company_form
expect_to_be_on_namespace_selection
fill_in_trial_selection_form
submit_duo_pro_trial_selection_form
expect_to_be_on_group_usage_quotas_page
end
end
context 'when applying trial fails' do
it 'fills out form, submits and is sent to select namespace with errors and is then resolved' do
# setup
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
submit_duo_pro_trial_company_form
expect_to_be_on_namespace_selection
fill_in_trial_selection_form
# trial failure
submit_duo_pro_trial_selection_form(success: false)
expect_to_be_on_namespace_selection_with_errors
# success
fill_in_trial_selection_form(from: group.name)
submit_duo_pro_trial_selection_form
expect_to_be_on_group_usage_quotas_page
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Duo Pro trial lead submission and creation with one eligible namespace', :saas_trial, :js, feature_category: :purchase do
# rubocop:disable Gitlab/RSpec/AvoidSetup -- to skip registration and creating group
let_it_be(:user) { create(:user) }
let_it_be(:group) do
create(:group_with_plan, plan: :ultimate_plan, name: 'gitlab').tap do |record|
record.add_owner(user)
end
end
# rubocop:enable Gitlab/RSpec/AvoidSetup
context 'when creating lead and applying trial is successful' do
it 'fills out form, submits and lands on the group usage quotas page' do
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
submit_duo_pro_trial_company_form(with_trial: true)
expect_to_be_on_group_usage_quotas_page
end
end
context 'when applying lead fails' do
it 'fills out form, submits and sent back to information form with errors and is then resolved' do
# setup
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
# lead failure
submit_duo_pro_trial_company_form(lead_success: false)
expect_to_be_on_lead_form_with_errors
# success
submit_duo_pro_trial_company_form(with_trial: true)
expect_to_be_on_group_usage_quotas_page
end
end
context 'when applying trial fails' do
it 'fills out form, submits and is sent to select namespace with errors and is then resolved' do
# setup
sign_in(user)
visit new_trials_duo_pro_path
fill_in_company_information
# trial failure
submit_duo_pro_trial_company_form(with_trial: true, trial_success: false)
expect_to_be_on_namespace_selection_with_errors
# success
fill_in_trial_selection_form(group_select: false)
submit_duo_pro_trial_selection_form
expect_to_be_on_group_usage_quotas_page
end
end
end
......@@ -5,6 +5,7 @@
module Features
module TrialHelpers
include ListboxHelpers
DUO_PRO_TRIAL = 'duo_pro_trial'
def expect_to_be_on_group_page(path: 'gitlab', name: 'gitlab')
expect(page).to have_current_path("/#{path}?trial=true")
......@@ -45,6 +46,13 @@ def expect_to_be_on_group_security_dashboard(group_for_path: group)
end
end
def expect_to_be_on_group_usage_quotas_page(path: 'gitlab', name: 'gitlab')
expect(page).to have_current_path("/groups/#{path}/-/usage_quotas")
within_testid('super-sidebar') do
expect(page).to have_link(name)
end
end
def fill_in_trial_selection_form(from: 'Please select a group', group_select: true)
select_from_listbox group.name, from: from if group_select
choose :trial_entity_company
......@@ -73,7 +81,9 @@ def fill_in_company_information
select form_data.dig(:state, :name), from: 'state'
end
def submit_company_information_form(lead_success: true, trial_success: true, with_trial: false, extra_params: {})
def submit_company_information_form(
trial_type: '', lead_success: true, trial_success: true, with_trial: false,
extra_params: {})
# lead
trial_user_params = {
company_name: form_data[:company_name],
......@@ -91,6 +101,13 @@ def submit_company_information_form(lead_success: true, trial_success: true, wit
state: form_data.dig(:state, :id)
}.merge(extra_params)
if trial_type == DUO_PRO_TRIAL
trial_user_params = trial_user_params.merge(
{ product_interaction: DUO_PRO_TRIAL, preferred_language: user.preferred_language,
opt_in: user.onboarding_status_email_opt_in }
)
end
lead_params = {
trial_user: trial_user_params
}
......@@ -101,7 +118,15 @@ def submit_company_information_form(lead_success: true, trial_success: true, wit
ServiceResponse.error(message: '_lead_fail_', reason: :lead_failed)
end
expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |service|
create_lead_class =
case trial_type
when DUO_PRO_TRIAL
GitlabSubscriptions::Trials::CreateDuoProLeadService
else
GitlabSubscriptions::CreateLeadService
end
expect_next_instance_of(create_lead_class) do |service|
expect(service).to receive(:execute).with(lead_params).and_return(lead_result)
end
......@@ -110,7 +135,8 @@ def submit_company_information_form(lead_success: true, trial_success: true, wit
stub_apply_trial(
namespace_id: group.id,
success: trial_success,
extra_params: extra_params.merge(existing_group_attrs)
extra_params: extra_params.merge(existing_group_attrs),
trial_type: trial_type
)
end
......@@ -119,20 +145,37 @@ def submit_company_information_form(lead_success: true, trial_success: true, wit
wait_for_requests
end
def submit_trial_selection_form(success: true, extra_params: {})
def submit_trial_selection_form(success: true, extra_params: {}, trial_type: '')
stub_apply_trial(
namespace_id: group.id,
success: success,
extra_params: extra_with_glm_source(extra_params).merge(existing_group_attrs)
extra_params: extra_with_glm_source(extra_params).merge(existing_group_attrs),
trial_type: trial_type
)
click_button 'Start your free trial'
button_text =
case trial_type
when DUO_PRO_TRIAL
'Activate my trial'
else
'Start your free trial'
end
click_button button_text
end
def submit_new_group_trial_selection_form(success: true, extra_params: {})
stub_apply_trial(success: success, extra_params: extra_with_glm_source(extra_params))
def submit_new_group_trial_selection_form(success: true, extra_params: {}, trial_type: '')
stub_apply_trial(success: success, extra_params: extra_with_glm_source(extra_params), trial_type: trial_type)
button_text =
case trial_type
when DUO_PRO_TRIAL
'Activate my trial'
else
'Start your free trial'
end
click_button 'Start your free trial'
click_button button_text
end
def extra_with_glm_source(extra_params)
......@@ -158,7 +201,7 @@ def new_group_attrs(path: 'gitlab', name: 'gitlab')
}
end
def stub_apply_trial(namespace_id: anything, success: true, extra_params: {})
def stub_apply_trial(trial_type: '', namespace_id: anything, success: true, extra_params: {})
trial_user_params = {
namespace_id: namespace_id,
gitlab_com_trial: true,
......@@ -176,9 +219,25 @@ def stub_apply_trial(namespace_id: anything, success: true, extra_params: {})
ServiceResponse.error(message: '_trial_fail_')
end
expect_next_instance_of(GitlabSubscriptions::Trials::ApplyTrialService, service_params) do |instance|
apply_trial_class =
case trial_type
when DUO_PRO_TRIAL
GitlabSubscriptions::Trials::ApplyDuoProService
else
GitlabSubscriptions::Trials::ApplyTrialService
end
expect_next_instance_of(apply_trial_class, service_params) do |instance|
expect(instance).to receive(:execute).and_return(trial_success)
end
end
def submit_duo_pro_trial_company_form(**kwargs)
submit_company_information_form(**kwargs, trial_type: DUO_PRO_TRIAL)
end
def submit_duo_pro_trial_selection_form(**kwargs)
submit_trial_selection_form(**kwargs, trial_type: DUO_PRO_TRIAL)
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册