debian-mirror-gitlab/spec/services/onboarding/progress_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.3 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Onboarding::ProgressService, feature_category: :onboarding do
2021-04-17 20:07:23 +05:30
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
2022-11-25 23:54:43 +05:30
expect(Onboarding::ProgressWorker).not_to receive(:perform_async)
2021-04-17 20:07:23 +05:30
execute_service
end
end
context 'when onboarded' do
before do
2022-10-11 01:57:18 +05:30
Onboarding::Progress.onboard(namespace)
2021-04-17 20:07:23 +05:30
end
context 'when action is already completed' do
before do
2022-10-11 01:57:18 +05:30
Onboarding::Progress.register(namespace, action)
2021-04-17 20:07:23 +05:30
end
it 'does not schedule a worker' do
2022-11-25 23:54:43 +05:30
expect(Onboarding::ProgressWorker).not_to receive(:perform_async)
2021-04-17 20:07:23 +05:30
execute_service
end
end
context 'when action is not yet completed' do
it 'schedules a worker' do
2022-11-25 23:54:43 +05:30
expect(Onboarding::ProgressWorker).to receive(:perform_async)
2021-04-17 20:07:23 +05:30
execute_service
end
end
end
end
2021-02-22 17:27:13 +05:30
describe '#execute' do
2021-04-17 20:07:23 +05:30
let(:namespace) { create(:namespace) }
2021-03-08 18:12:59 +05:30
let(:action) { :namespace_action }
2021-02-22 17:27:13 +05:30
subject(:execute_service) { described_class.new(namespace).execute(action: :subscription_created) }
context 'when the namespace is a root' do
2021-03-08 18:12:59 +05:30
before do
2022-10-11 01:57:18 +05:30
Onboarding::Progress.onboard(namespace)
2021-03-08 18:12:59 +05:30
end
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
it 'registers a namespace onboarding progress action for the given namespace' do
execute_service
2021-02-22 17:27:13 +05:30
2022-10-11 01:57:18 +05:30
expect(Onboarding::Progress.completed?(namespace, :subscription_created)).to eq(true)
2021-02-22 17:27:13 +05:30
end
end
context 'when the namespace is not the root' do
2021-04-17 20:07:23 +05:30
let(:group) { create(:group, :nested) }
2021-03-08 18:12:59 +05:30
before do
2022-10-11 01:57:18 +05:30
Onboarding::Progress.onboard(group)
2021-03-08 18:12:59 +05:30
end
2021-04-17 20:07:23 +05:30
it 'does not register a namespace onboarding progress action' do
2021-03-08 18:12:59 +05:30
execute_service
2022-10-11 01:57:18 +05:30
expect(Onboarding::Progress.completed?(group, :subscription_created)).to be(nil)
2021-03-08 18:12:59 +05:30
end
end
context 'when no namespace is passed' do
let(:namespace) { nil }
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
it 'does not register a namespace onboarding progress action' do
execute_service
2021-02-22 17:27:13 +05:30
2022-10-11 01:57:18 +05:30
expect(Onboarding::Progress.completed?(namespace, :subscription_created)).to be(nil)
2021-02-22 17:27:13 +05:30
end
end
end
end