diff options
Diffstat (limited to 'spec/models/onboarding/completion_spec.rb')
-rw-r--r-- | spec/models/onboarding/completion_spec.rb | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/spec/models/onboarding/completion_spec.rb b/spec/models/onboarding/completion_spec.rb index e1fad4255bc..175f8d6ef68 100644 --- a/spec/models/onboarding/completion_spec.rb +++ b/spec/models/onboarding/completion_spec.rb @@ -2,10 +2,14 @@ require 'spec_helper' -RSpec.describe Onboarding::Completion do +RSpec.describe Onboarding::Completion, feature_category: :onboarding do + let(:completed_actions) { {} } + let(:project) { build(:project, namespace: namespace) } + let!(:onboarding_progress) { create(:onboarding_progress, namespace: namespace, **completed_actions) } + + let_it_be(:namespace) { create(:namespace) } + describe '#percentage' do - let(:completed_actions) { {} } - let!(:onboarding_progress) { create(:onboarding_progress, namespace: namespace, **completed_actions) } let(:tracked_action_columns) do [ *described_class::ACTION_ISSUE_IDS.keys, @@ -14,12 +18,10 @@ RSpec.describe Onboarding::Completion do ].map { |key| ::Onboarding::Progress.column_name(key) } end - let_it_be(:namespace) { create(:namespace) } - - subject { described_class.new(namespace).percentage } + subject(:percentage) { described_class.new(project).percentage } context 'when no onboarding_progress exists' do - subject { described_class.new(build(:namespace)).percentage } + subject(:percentage) { described_class.new(build(:project)).percentage } it { is_expected.to eq(0) } end @@ -29,6 +31,8 @@ RSpec.describe Onboarding::Completion do end context 'when all tracked actions have been completed' do + let(:project) { build(:project, :stubbed_commit_count, namespace: namespace) } + let(:completed_actions) do tracked_action_columns.index_with { Time.current } end @@ -44,7 +48,7 @@ RSpec.describe Onboarding::Completion do stub_experiments(security_actions_continuous_onboarding: :control) end - it { is_expected.to eq(11) } + it { is_expected.to eq(10) } end context 'when candidate' do @@ -52,7 +56,50 @@ RSpec.describe Onboarding::Completion do stub_experiments(security_actions_continuous_onboarding: :candidate) end - it { is_expected.to eq(9) } + it { is_expected.to eq(8) } + end + end + end + + describe '#completed?' do + subject(:completed?) { described_class.new(project).completed?(column) } + + context 'when code_added' do + let(:column) { :code_added } + + context 'when commit_count > 1' do + let(:project) { build(:project, :stubbed_commit_count, namespace: namespace) } + + it { is_expected.to eq(true) } + end + + context 'when branch_count > 1' do + let(:project) { build(:project, :stubbed_branch_count, namespace: namespace) } + + it { is_expected.to eq(true) } + end + + context 'when empty repository' do + let(:project) { build(:project, namespace: namespace) } + + it { is_expected.to eq(false) } + end + end + + context 'when security_scan_enabled' do + let(:column) { :security_scan_enabled_at } + let(:completed_actions) { { security_scan_enabled_at: security_scan_enabled_at } } + + context 'when is completed' do + let(:security_scan_enabled_at) { Time.current } + + it { is_expected.to eq(true) } + end + + context 'when is not completed' do + let(:security_scan_enabled_at) { nil } + + it { is_expected.to eq(false) } end end end |