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