2020-12-03 13:10:10 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe OnboardingProgressService do
|
2021-02-23 10:10:47 -05:00
|
|
|
describe '.async' do
|
|
|
|
let_it_be(:namespace) { create(:namespace) }
|
|
|
|
let_it_be(:action) { :git_pull }
|
|
|
|
|
|
|
|
subject(:execute_service) { described_class.async(namespace.id).execute(action: action) }
|
|
|
|
|
|
|
|
context 'when not onboarded' do
|
|
|
|
it 'does not schedule a worker' do
|
|
|
|
expect(Namespaces::OnboardingProgressWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
execute_service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when onboarded' do
|
|
|
|
before do
|
|
|
|
OnboardingProgress.onboard(namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when action is already completed' do
|
|
|
|
before do
|
|
|
|
OnboardingProgress.register(namespace, action)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not schedule a worker' do
|
|
|
|
expect(Namespaces::OnboardingProgressWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
execute_service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when action is not yet completed' do
|
|
|
|
it 'schedules a worker' do
|
|
|
|
expect(Namespaces::OnboardingProgressWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
execute_service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-03 13:10:10 -05:00
|
|
|
describe '#execute' do
|
2021-03-01 10:10:53 -05:00
|
|
|
let(:namespace) { create(:namespace) }
|
2020-12-23 07:10:26 -05:00
|
|
|
let(:action) { :namespace_action }
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2020-12-15 19:09:58 -05:00
|
|
|
subject(:execute_service) { described_class.new(namespace).execute(action: :subscription_created) }
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2020-12-15 19:09:58 -05:00
|
|
|
context 'when the namespace is a root' do
|
2021-01-11 07:10:41 -05:00
|
|
|
before do
|
|
|
|
OnboardingProgress.onboard(namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'registers a namespace onboarding progress action for the given namespace' do
|
|
|
|
execute_service
|
2020-12-15 19:09:58 -05:00
|
|
|
|
2021-01-11 07:10:41 -05:00
|
|
|
expect(OnboardingProgress.completed?(namespace, :subscription_created)).to eq(true)
|
2020-12-15 19:09:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the namespace is not the root' do
|
2021-03-01 10:10:53 -05:00
|
|
|
let(:group) { create(:group, :nested) }
|
2020-12-15 19:09:58 -05:00
|
|
|
|
2021-01-11 07:10:41 -05:00
|
|
|
before do
|
2021-03-01 10:10:53 -05:00
|
|
|
OnboardingProgress.onboard(group)
|
2021-01-11 07:10:41 -05:00
|
|
|
end
|
|
|
|
|
2021-03-01 10:10:53 -05:00
|
|
|
it 'does not register a namespace onboarding progress action' do
|
2021-01-11 07:10:41 -05:00
|
|
|
execute_service
|
2020-12-15 19:09:58 -05:00
|
|
|
|
2021-03-01 10:10:53 -05:00
|
|
|
expect(OnboardingProgress.completed?(group, :subscription_created)).to be(nil)
|
2020-12-15 19:09:58 -05:00
|
|
|
end
|
2020-12-03 13:10:10 -05:00
|
|
|
end
|
2020-12-23 07:10:26 -05:00
|
|
|
|
|
|
|
context 'when no namespace is passed' do
|
|
|
|
let(:namespace) { nil }
|
|
|
|
|
2021-01-11 07:10:41 -05:00
|
|
|
it 'does not register a namespace onboarding progress action' do
|
2020-12-23 07:10:26 -05:00
|
|
|
execute_service
|
2021-01-11 07:10:41 -05:00
|
|
|
|
2021-03-01 10:10:53 -05:00
|
|
|
expect(OnboardingProgress.completed?(namespace, :subscription_created)).to be(nil)
|
2020-12-23 07:10:26 -05:00
|
|
|
end
|
|
|
|
end
|
2020-12-03 13:10:10 -05:00
|
|
|
end
|
|
|
|
end
|