Commit db82a385 authored by Alex Buijs's avatar Alex Buijs

Convert all calls to OnboardingProgress model

Instead of the NamespaceOnboardingAction model
parent 66a8e157
......@@ -8,6 +8,6 @@ class OnboardingProgressService
def execute(action:)
return unless @namespace
NamespaceOnboardingAction.create_action(@namespace, action)
OnboardingProgress.register(@namespace, action)
end
end
......@@ -66,10 +66,12 @@ RSpec.describe Subscriptions::CreateService do
expect(subject.execute).to eq(success: false, data: { errors: 'failed to create subscription' })
end
it 'does not create a namespace onboarding action' do
it 'does not register a namespace onboarding progress action' do
OnboardingProgress.onboard(group)
subject.execute
expect(NamespaceOnboardingAction.completed?(group, :subscription_created)).to eq(false)
expect(OnboardingProgress.completed?(group, :subscription_created)).to eq(false)
end
end
......@@ -102,10 +104,12 @@ RSpec.describe Subscriptions::CreateService do
subject.execute
end
it 'creates a namespace onboarding action' do
it 'registers a namespace onboarding progress action' do
OnboardingProgress.onboard(group)
subject.execute
expect(NamespaceOnboardingAction.completed?(group, :subscription_created)).to eq(true)
expect(OnboardingProgress.completed?(group, :subscription_created)).to eq(true)
end
end
end
......
......@@ -13,14 +13,20 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
subject(:execute_service) { described_class.new(user, params).execute(source) }
before do
source.is_a?(Project) ? source.add_maintainer(user) : source.add_owner(user)
if source.is_a?(Project)
source.add_maintainer(user)
OnboardingProgress.onboard(source.namespace)
else
source.add_owner(user)
OnboardingProgress.onboard(source)
end
end
context 'when passing valid parameters' do
it 'adds a user to members' do
expect(execute_service[:status]).to eq(:success)
expect(source.users).to include member
expect(NamespaceOnboardingAction.completed?(source.namespace, :user_added)).to be(true)
expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(true)
end
context 'when executing on a group' do
......@@ -29,7 +35,7 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
it 'adds a user to members' do
expect(execute_service[:status]).to eq(:success)
expect(source.users).to include member
expect(NamespaceOnboardingAction.completed?(source, :user_added)).to be(true)
expect(OnboardingProgress.completed?(source, :user_added)).to be(true)
end
end
end
......@@ -41,7 +47,7 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
expect(execute_service[:status]).to eq(:error)
expect(execute_service[:message]).to be_present
expect(source.users).not_to include member
expect(NamespaceOnboardingAction.completed?(source.namespace, :user_added)).to be(false)
expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(false)
end
end
......@@ -52,7 +58,7 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
expect(execute_service[:status]).to eq(:error)
expect(execute_service[:message]).to be_present
expect(source.users).not_to include member
expect(NamespaceOnboardingAction.completed?(source.namespace, :user_added)).to be(false)
expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(false)
end
end
......@@ -63,7 +69,7 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
expect(execute_service[:status]).to eq(:error)
expect(execute_service[:message]).to include("#{member.username}: Access level is not included in the list")
expect(source.users).not_to include member
expect(NamespaceOnboardingAction.completed?(source.namespace, :user_added)).to be(false)
expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(false)
end
end
......@@ -73,7 +79,7 @@ RSpec.describe Members::CreateService, :clean_gitlab_redis_shared_state, :sideki
it 'does not add a member' do
expect(execute_service[:status]).to eq(:error)
expect(execute_service[:message]).to eq('Invite email has already been taken')
expect(NamespaceOnboardingAction.completed?(source.namespace, :user_added)).to be(false)
expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(false)
end
end
end
......@@ -58,11 +58,15 @@ RSpec.describe MergeRequests::AfterCreateService do
execute_service
end
it 'records an onboarding progress action' do
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
expect { execute_service }.to change(NamespaceOnboardingAction, :count).by(1)
execute_service
expect(OnboardingProgress.completed?(merge_request.target_project.namespace, :merge_request_created)).to be(true)
end
end
end
......@@ -11,32 +11,38 @@ RSpec.describe OnboardingProgressService do
subject(:execute_service) { described_class.new(namespace).execute(action: :subscription_created) }
context 'when the namespace is a root' do
it 'records a namespace onboarding progress action fot the given namespace' do
expect(NamespaceOnboardingAction).to receive(:create_action)
.with(namespace, :subscription_created).and_call_original
before do
OnboardingProgress.onboard(namespace)
end
it 'registers a namespace onboarding progress action for the given namespace' do
execute_service
expect { execute_service }.to change(NamespaceOnboardingAction, :count).by(1)
expect(OnboardingProgress.completed?(namespace, :subscription_created)).to eq(true)
end
end
context 'when the namespace is not the root' do
let(:root_namespace) { build(:namespace) }
it 'records a namespace onboarding progress action for the root namespace' do
expect(NamespaceOnboardingAction).to receive(:create_action)
.with(root_namespace, :subscription_created).and_call_original
before do
OnboardingProgress.onboard(root_namespace)
end
it 'registers a namespace onboarding progress action for the root namespace' do
execute_service
expect { execute_service }.to change(NamespaceOnboardingAction, :count).by(1)
expect(OnboardingProgress.completed?(root_namespace, :subscription_created)).to eq(true)
end
end
context 'when no namespace is passed' do
let(:namespace) { nil }
it 'does not record a namespace onboarding progress action' do
expect(NamespaceOnboardingAction).not_to receive(:create_action)
it 'does not register a namespace onboarding progress action' do
execute_service
expect(OnboardingProgress.completed?(root_namespace, :subscription_created)).to be(nil)
end
end
end
......
......@@ -7,20 +7,26 @@ RSpec.describe Namespaces::OnboardingPipelineCreatedWorker, '#perform' do
let_it_be(:ci_pipeline) { create(:ci_pipeline) }
it 'records the event' do
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
expect do
subject.perform(ci_pipeline.project.namespace_id)
end.to change(NamespaceOnboardingAction, :count).by(1)
subject.perform(ci_pipeline.project.namespace_id)
expect(OnboardingProgress.completed?(ci_pipeline.project.namespace, :pipeline_created)).to eq(true)
end
context "when a namespace doesn't exist" do
it "does nothing" do
it 'does not register an onboarding progress action' do
expect_next(OnboardingProgressService, ci_pipeline.project.namespace).not_to receive(:execute)
expect { subject.perform(nil) }.not_to change(NamespaceOnboardingAction, :count)
subject.perform(nil)
expect(OnboardingProgress.completed?(ci_pipeline.project.namespace, :pipeline_created)).to eq(false)
end
end
end
......@@ -7,10 +7,16 @@ RSpec.describe Namespaces::OnboardingUserAddedWorker, '#perform' do
let_it_be(:group) { create(:group) }
it 'records the event' do
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
expect { subject.perform(group.id) }.to change(NamespaceOnboardingAction, :count).by(1)
subject.perform(group.id)
expect(OnboardingProgress.completed?(group, :user_added)).to be(true)
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