From 36950131288a8093b2849f67b342b5ec2b985fe5 Mon Sep 17 00:00:00 2001 From: Doug Stull <dstull@gitlab.com> Date: Wed, 17 May 2023 11:15:58 -0400 Subject: [PATCH] Add namespace params to trial submission - so that customers dot can skip the re-fetch of info from GitLab --- .../layout/first_hash_element_indentation.yml | 1 - .../base_namespace_create_service.rb | 7 ++----- .../import_namespace_create_service_spec.rb | 3 ++- .../standard_namespace_create_service_spec.rb | 3 ++- .../helpers/saas_registration_helpers.rb | 18 ++++++++++++++++-- .../trials/apply_trial_worker_spec.rb | 10 ++++++++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo/layout/first_hash_element_indentation.yml b/.rubocop_todo/layout/first_hash_element_indentation.yml index bd8bee3b69fb1..dc2f8610a51aa 100644 --- a/.rubocop_todo/layout/first_hash_element_indentation.yml +++ b/.rubocop_todo/layout/first_hash_element_indentation.yml @@ -50,7 +50,6 @@ Layout/FirstHashElementIndentation: - 'ee/app/services/elastic/cluster_reindexing_service.rb' - 'ee/app/services/gitlab_subscriptions/plan_upgrade_service.rb' - 'ee/app/services/iterations/create_service.rb' - - 'ee/app/services/registrations/base_namespace_create_service.rb' - 'ee/app/services/resource_events/change_iteration_service.rb' - 'ee/app/services/security/token_revocation_service.rb' - 'ee/app/services/timebox_report_service.rb' diff --git a/ee/app/services/registrations/base_namespace_create_service.rb b/ee/app/services/registrations/base_namespace_create_service.rb index 3b2421ca1df13..9a3907d743950 100644 --- a/ee/app/services/registrations/base_namespace_create_service.rb +++ b/ee/app/services/registrations/base_namespace_create_service.rb @@ -37,11 +37,8 @@ def in_trial_onboarding_flow? end def apply_trial - trial_user_information = glm_params.merge({ - namespace_id: group.id, - gitlab_com_trial: true, - sync_to_gl: true - }) + trial_user_information = glm_params.merge(namespace_id: group.id, gitlab_com_trial: true, sync_to_gl: true) + trial_user_information[:namespace] = group.slice(:id, :name, :path, :kind, :trial_ends_on) GitlabSubscriptions::Trials::ApplyTrialWorker.perform_async(user.id, trial_user_information.to_h) end diff --git a/ee/spec/services/registrations/import_namespace_create_service_spec.rb b/ee/spec/services/registrations/import_namespace_create_service_spec.rb index d0f3b95be28ef..a178f58610d9b 100644 --- a/ee/spec/services/registrations/import_namespace_create_service_spec.rb +++ b/ee/spec/services/registrations/import_namespace_create_service_spec.rb @@ -116,7 +116,8 @@ glm_content: 'content', namespace_id: group.id, gitlab_com_trial: true, - sync_to_gl: true + sync_to_gl: true, + namespace: group.slice(:id, :name, :path, :kind, :trial_ends_on) } ) end diff --git a/ee/spec/services/registrations/standard_namespace_create_service_spec.rb b/ee/spec/services/registrations/standard_namespace_create_service_spec.rb index d06b28442dbc2..db7341fd23ebc 100644 --- a/ee/spec/services/registrations/standard_namespace_create_service_spec.rb +++ b/ee/spec/services/registrations/standard_namespace_create_service_spec.rb @@ -197,7 +197,8 @@ glm_content: 'content', namespace_id: group.id, gitlab_com_trial: true, - sync_to_gl: true + sync_to_gl: true, + namespace: group.slice(:id, :name, :path, :kind, :trial_ends_on) } ) end diff --git a/ee/spec/support/helpers/saas_registration_helpers.rb b/ee/spec/support/helpers/saas_registration_helpers.rb index a458d6a8322fc..0ea103a370195 100644 --- a/ee/spec/support/helpers/saas_registration_helpers.rb +++ b/ee/spec/support/helpers/saas_registration_helpers.rb @@ -123,7 +123,14 @@ def expect_to_apply_trial trial_user_information = { namespace_id: anything, gitlab_com_trial: true, - sync_to_gl: true + sync_to_gl: true, + namespace: { + id: anything, + name: 'Test Group', + path: 'test-group', + kind: 'group', + trial_ends_on: nil + } }.merge(glm_params) expect(GitlabSubscriptions::Trials::ApplyTrialWorker) @@ -176,7 +183,14 @@ def fills_in_group_and_project_creation_form_with_trial trial_user_information = { namespace_id: anything, gitlab_com_trial: true, - sync_to_gl: true + sync_to_gl: true, + namespace: { + id: anything, + name: 'Test Group', + path: 'test-group', + kind: 'group', + trial_ends_on: nil + } }.merge(glm_params) expect(GitlabSubscriptions::Trials::ApplyTrialWorker) diff --git a/ee/spec/workers/gitlab_subscriptions/trials/apply_trial_worker_spec.rb b/ee/spec/workers/gitlab_subscriptions/trials/apply_trial_worker_spec.rb index f46df1b962f56..02965fb9ab087 100644 --- a/ee/spec/workers/gitlab_subscriptions/trials/apply_trial_worker_spec.rb +++ b/ee/spec/workers/gitlab_subscriptions/trials/apply_trial_worker_spec.rb @@ -11,13 +11,19 @@ context 'when valid to generate a trial' do let_it_be(:namespace) { create(:namespace) } - let(:trial_user_information) { { 'namespace_id' => namespace.id } } + let(:trial_user_information) do + { + 'namespace_id' => namespace.id, + 'namespace' => namespace.slice(:id, :name, :path, :kind, :trial_ends_on).stringify_keys + } + end context 'when trial is successfully applied' do let(:service) { instance_double(GitlabSubscriptions::Trials::ApplyTrialService) } before do - allow(GitlabSubscriptions::Trials::ApplyTrialService).to receive(:new).and_return(service) + trial_params = { uid: user.id, trial_user_information: trial_user_information.deep_symbolize_keys } + allow(GitlabSubscriptions::Trials::ApplyTrialService).to receive(:new).with(trial_params).and_return(service) allow(service).to receive(:execute).and_return(ServiceResponse.success) end -- GitLab