Commit 7e38ebf6 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'nicolasdular/use-onboarding-shared-examples' into 'master'

Use shared examples for onboarding progress specs

See merge request gitlab-org/gitlab!52325
parents 55fe1c2a eacf3983
...@@ -26,13 +26,7 @@ RSpec.describe GitlabSubscriptions::ApplyTrialService do ...@@ -26,13 +26,7 @@ RSpec.describe GitlabSubscriptions::ApplyTrialService do
expect(execute).to eq({ success: true }) expect(execute).to eq({ success: true })
end end
it 'records a namespace onboarding progress action' do it_behaves_like 'records an onboarding progress action', :trial_started
expect_next_instance_of(OnboardingProgressService) do |service|
expect(service).to receive(:execute).with(action: :trial_started)
end
execute
end
end end
context 'error while applying the trial' do context 'error while applying the trial' do
...@@ -47,11 +41,7 @@ RSpec.describe GitlabSubscriptions::ApplyTrialService do ...@@ -47,11 +41,7 @@ RSpec.describe GitlabSubscriptions::ApplyTrialService do
expect(execute).to eq(expected_response) expect(execute).to eq(expected_response)
end end
it 'does not record a namespace onboarding progress action' do it_behaves_like 'does not record an onboarding progress action'
expect(OnboardingProgressService).not_to receive(:new)
execute
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Subscriptions::CreateService do RSpec.describe Subscriptions::CreateService do
subject { described_class.new(user, group: group, customer_params: customer_params, subscription_params: subscription_params) } subject(:execute) { described_class.new(user, group: group, customer_params: customer_params, subscription_params: subscription_params).execute }
let_it_be(:user) { create(:user, id: 111, first_name: 'First name', last_name: 'Last name', email: 'first.last@gitlab.com') } let_it_be(:user) { create(:user, id: 111, first_name: 'First name', last_name: 'Last name', email: 'first.last@gitlab.com') }
let_it_be(:group) { create(:group, id: 222, name: 'Group name') } let_it_be(:group) { create(:group, id: 222, name: 'Group name') }
...@@ -39,7 +39,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -39,7 +39,7 @@ RSpec.describe Subscriptions::CreateService do
end end
it 'returns the response hash' do it 'returns the response hash' do
expect(subject.execute).to eq(success: false, data: { errors: 'failed to create customer' }) expect(execute).to eq(success: false, data: { errors: 'failed to create customer' })
end end
end end
...@@ -54,7 +54,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -54,7 +54,7 @@ RSpec.describe Subscriptions::CreateService do
.with(anything, customer_email, 'token') .with(anything, customer_email, 'token')
.and_return(success: true, data: { success: true, subscription_id: 'xxx' }) .and_return(success: true, data: { success: true, subscription_id: 'xxx' })
subject.execute execute
end end
context 'when failing to create a subscription' do context 'when failing to create a subscription' do
...@@ -63,16 +63,10 @@ RSpec.describe Subscriptions::CreateService do ...@@ -63,16 +63,10 @@ RSpec.describe Subscriptions::CreateService do
end end
it 'returns the response hash' do it 'returns the response hash' do
expect(subject.execute).to eq(success: false, data: { errors: 'failed to create subscription' }) expect(execute).to eq(success: false, data: { errors: 'failed to create subscription' })
end end
it 'does not register a namespace onboarding progress action' do it_behaves_like 'does not record an onboarding progress action'
OnboardingProgress.onboard(group)
subject.execute
expect(OnboardingProgress.completed?(group, :subscription_created)).to eq(false)
end
end end
context 'when successfully creating a subscription' do context 'when successfully creating a subscription' do
...@@ -81,7 +75,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -81,7 +75,7 @@ RSpec.describe Subscriptions::CreateService do
end end
it 'returns the response hash' do it 'returns the response hash' do
expect(subject.execute).to eq(success: true, data: { success: true, subscription_id: 'xxx' }) expect(execute).to eq(success: true, data: { success: true, subscription_id: 'xxx' })
end end
end end
end end
...@@ -95,21 +89,17 @@ RSpec.describe Subscriptions::CreateService do ...@@ -95,21 +89,17 @@ RSpec.describe Subscriptions::CreateService do
it 'passes the correct parameters for creating a customer' do it 'passes the correct parameters for creating a customer' do
expect(client).to receive(:create_customer).with(create_service_params[:customer]) expect(client).to receive(:create_customer).with(create_service_params[:customer])
subject.execute execute
end end
it 'passes the correct parameters for creating a subscription' do it 'passes the correct parameters for creating a subscription' do
expect(client).to receive(:create_subscription).with(create_service_params[:subscription], customer_email, 'token') expect(client).to receive(:create_subscription).with(create_service_params[:subscription], customer_email, 'token')
subject.execute execute
end end
it 'registers a namespace onboarding progress action' do it_behaves_like 'records an onboarding progress action', :subscription_created do
OnboardingProgress.onboard(group) let(:namespace) { group }
subject.execute
expect(OnboardingProgress.completed?(group, :subscription_created)).to eq(true)
end end
end end
end end
......
...@@ -52,12 +52,10 @@ RSpec.describe Repositories::GitHttpController do ...@@ -52,12 +52,10 @@ RSpec.describe Repositories::GitHttpController do
}.from(0).to(1) }.from(0).to(1)
end end
it 'records an onboarding progress action' do it_behaves_like 'records an onboarding progress action', :git_read do
expect_next_instance_of(OnboardingProgressService) do |service| let(:namespace) { project.namespace }
expect(service).to receive(:execute).with(action: :git_read)
end
send_request subject { send_request }
end end
end end
end end
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe MergeRequests::AfterCreateService do RSpec.describe MergeRequests::AfterCreateService do
include AfterNextHelpers
let_it_be(:merge_request) { create(:merge_request) } let_it_be(:merge_request) { create(:merge_request) }
subject(:after_create_service) do subject(:after_create_service) do
...@@ -66,15 +64,8 @@ RSpec.describe MergeRequests::AfterCreateService do ...@@ -66,15 +64,8 @@ RSpec.describe MergeRequests::AfterCreateService do
execute_service execute_service
end end
it 'registers an onboarding progress action' do it_behaves_like 'records an onboarding progress action', :merge_request_created do
OnboardingProgress.onboard(merge_request.target_project.namespace) let(:namespace) { merge_request.target_project.namespace }
expect_next(OnboardingProgressService, merge_request.target_project.namespace)
.to receive(:execute).with(action: :merge_request_created).and_call_original
execute_service
expect(OnboardingProgress.completed?(merge_request.target_project.namespace, :merge_request_created)).to be(true)
end end
end end
end end
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe PostReceiveService do RSpec.describe PostReceiveService do
include Gitlab::Routing include Gitlab::Routing
include AfterNextHelpers
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) }
...@@ -47,11 +46,7 @@ RSpec.describe PostReceiveService do ...@@ -47,11 +46,7 @@ RSpec.describe PostReceiveService do
expect(subject).to be_empty expect(subject).to be_empty
end end
it 'does not record an onboarding progress action' do it_behaves_like 'does not record an onboarding progress action'
expect_next(OnboardingProgressService).not_to receive(:execute)
subject
end
end end
context 'when repository is nil' do context 'when repository is nil' do
...@@ -88,11 +83,8 @@ RSpec.describe PostReceiveService do ...@@ -88,11 +83,8 @@ RSpec.describe PostReceiveService do
expect(response.reference_counter_decreased).to be(true) expect(response.reference_counter_decreased).to be(true)
end end
it 'records an onboarding progress action' do it_behaves_like 'records an onboarding progress action', :git_write do
expect_next(OnboardingProgressService, project.namespace) let(:namespace) { project.namespace }
.to receive(:execute).with(action: :git_write)
subject
end end
end end
......
...@@ -3,30 +3,15 @@ ...@@ -3,30 +3,15 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Namespaces::OnboardingPipelineCreatedWorker, '#perform' do RSpec.describe Namespaces::OnboardingPipelineCreatedWorker, '#perform' do
include AfterNextHelpers
let_it_be(:ci_pipeline) { create(:ci_pipeline) } let_it_be(:ci_pipeline) { create(:ci_pipeline) }
before do it_behaves_like 'records an onboarding progress action', :pipeline_created do
OnboardingProgress.onboard(ci_pipeline.project.namespace) let(:namespace) { ci_pipeline.project.namespace }
end
it 'registers an onboarding progress action' do
expect_next(OnboardingProgressService, ci_pipeline.project.namespace)
.to receive(:execute).with(action: :pipeline_created).and_call_original
subject.perform(ci_pipeline.project.namespace_id) subject { described_class.new.perform(ci_pipeline.project.namespace_id) }
expect(OnboardingProgress.completed?(ci_pipeline.project.namespace, :pipeline_created)).to eq(true)
end end
context "when a namespace doesn't exist" do it_behaves_like 'does not record an onboarding progress action' do
it 'does not register an onboarding progress action' do subject { described_class.new.perform(nil) }
expect_next(OnboardingProgressService, ci_pipeline.project.namespace).not_to receive(:execute)
subject.perform(nil)
expect(OnboardingProgress.completed?(ci_pipeline.project.namespace, :pipeline_created)).to eq(false)
end
end end
end end
...@@ -3,20 +3,9 @@ ...@@ -3,20 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Namespaces::OnboardingUserAddedWorker, '#perform' do RSpec.describe Namespaces::OnboardingUserAddedWorker, '#perform' do
include AfterNextHelpers let_it_be(:namespace) { create(:group) }
let_it_be(:group) { create(:group) } subject { described_class.new.perform(namespace.id) }
before do it_behaves_like 'records an onboarding progress action', :user_added
OnboardingProgress.onboard(group)
end
it 'registers an onboarding progress action' do
expect_next(OnboardingProgressService, group)
.to receive(:execute).with(action: :user_added).and_call_original
subject.perform(group.id)
expect(OnboardingProgress.completed?(group, :user_added)).to be(true)
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