Commit 9d4003d7 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'nicolasdular/use-trial-project-for-learn-gitlab-experiment' into 'master'

Use learn gitlab utlimate template for experiment

See merge request gitlab-org/gitlab!55179
parents 13142eea 15a7997f
......@@ -24,13 +24,13 @@ module LearnGitlabHelper
private
ACTION_ISSUE_IDS = {
git_write: 2,
pipeline_created: 4,
merge_request_created: 5,
user_added: 7,
trial_started: 13,
required_mr_approvals_enabled: 15,
code_owners_enabled: 16
git_write: 6,
pipeline_created: 7,
merge_request_created: 9,
user_added: 8,
trial_started: 2,
required_mr_approvals_enabled: 11,
code_owners_enabled: 10
}.freeze
ACTION_DOC_URLS = {
......
......@@ -4,6 +4,9 @@ module Registrations
class ProjectsController < ApplicationController
layout 'checkout'
LEARN_GITLAB_TEMPLATE = 'learn_gitlab.tar.gz'
LEARN_GITLAB_ULTIMATE_TEMPLATE = 'learn_gitlab_ultimate_trial.tar.gz'
before_action :check_signup_onboarding_enabled
before_action only: [:new] do
set_namespace
......@@ -48,20 +51,12 @@ module Registrations
end
def create_learn_gitlab_project
title, filename = if helpers.in_trial_onboarding_flow?
[s_('Learn GitLab - Ultimate trial'), 'learn_gitlab_ultimate_trial.tar.gz']
else
[s_('Learn GitLab'), 'learn_gitlab.tar.gz']
end
learn_gitlab_template_path = Rails.root.join('vendor', 'project_templates', filename)
learn_gitlab_project = File.open(learn_gitlab_template_path) do |archive|
::Projects::GitlabProjectsImportService.new(
current_user,
namespace_id: @project.namespace_id,
file: archive,
name: title
name: learn_gitlab_project_name
).execute
end
......@@ -88,5 +83,24 @@ module Registrations
:visibility_level
]
end
def learn_gitlab_project_name
helpers.in_trial_onboarding_flow? ? s_('Learn GitLab - Ultimate trial') : s_('Learn GitLab')
end
def learn_gitlab_template_path
file = if helpers.in_trial_onboarding_flow? || learn_gitlab_experiment_enabled?
LEARN_GITLAB_ULTIMATE_TEMPLATE
else
LEARN_GITLAB_TEMPLATE
end
Rails.root.join('vendor', 'project_templates', file)
end
def learn_gitlab_experiment_enabled?
Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_a, subject: current_user) ||
Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_b, subject: current_user)
end
end
end
......@@ -3,8 +3,11 @@
require 'spec_helper'
RSpec.describe Registrations::ProjectsController do
include AfterNextHelpers
let_it_be(:user) { create(:user) }
let_it_be(:namespace) { create(:group) }
let_it_be(:project) { create(:project) }
describe 'GET #new' do
subject { get :new }
......@@ -76,10 +79,40 @@ RSpec.describe Registrations::ProjectsController do
expect(namespace.projects.find_by_name(s_('Learn GitLab'))).to be_import_finished
end
context 'learn gitlab project' do
using RSpec::Parameterized::TableSyntax
where(:trial, :experiment_enabled, :project_name, :template) do
false | false | 'Learn GitLab' | described_class::LEARN_GITLAB_TEMPLATE
false | true | 'Learn GitLab' | described_class::LEARN_GITLAB_ULTIMATE_TEMPLATE
true | false | 'Learn GitLab - Ultimate trial' | described_class::LEARN_GITLAB_ULTIMATE_TEMPLATE
true | true | 'Learn GitLab - Ultimate trial' | described_class::LEARN_GITLAB_ULTIMATE_TEMPLATE
end
with_them do
let(:path) { Rails.root.join('vendor', 'project_templates', template) }
let(:expected_arguments) { { namespace_id: namespace.id, file: handle, name: project_name } }
let(:handle) { double }
let(:trial_onboarding_flow_params) { { trial_onboarding_flow: trial } }
before do
stub_experiment_for_subject(learn_gitlab_a: experiment_enabled)
allow(File).to receive(:open).and_call_original
expect(File).to receive(:open).with(path).and_yield(handle)
end
specify do
expect_next(::Projects::GitlabProjectsImportService, user, expected_arguments)
.to receive(:execute).and_return(project)
subject
end
end
end
context 'when the trial onboarding is active' do
let_it_be(:trial_onboarding_flow_params) { { trial_onboarding_flow: true } }
let_it_be(:trial_onboarding_issues_enabled) { true }
let_it_be(:project) { create(:project) }
let_it_be(:first_project) { create(:project) }
let_it_be(:trial_onboarding_context) do
{ learn_gitlab_project_id: project.id, namespace_id: project.namespace_id, project_id: first_project.id }
......
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