debian-mirror-gitlab/spec/models/onboarding/completion_spec.rb

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

105 lines
2.9 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
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) }
2022-10-11 01:57:18 +05:30
describe '#percentage' do
let(:tracked_action_columns) do
2023-05-27 22:25:52 +05:30
[*described_class::ACTION_PATHS, :security_scan_enabled].map do |key|
::Onboarding::Progress.column_name(key)
end
2021-06-08 01:23:25 +05:30
end
2023-05-27 22:25:52 +05:30
subject(:percentage) { described_class.new(project).percentage }
2021-06-08 01:23:25 +05:30
context 'when no onboarding_progress exists' do
2023-05-27 22:25:52 +05:30
subject(:percentage) { described_class.new(build(:project)).percentage }
2021-06-08 01:23:25 +05:30
it { is_expected.to eq(0) }
end
context 'when no action has been completed' do
it { is_expected.to eq(0) }
end
context 'when all tracked actions have been completed' do
2023-05-27 22:25:52 +05:30
let(:project) { build(:project, :stubbed_commit_count, namespace: namespace) }
2021-06-08 01:23:25 +05:30
let(:completed_actions) do
2022-10-11 01:57:18 +05:30
tracked_action_columns.index_with { Time.current }
2021-06-08 01:23:25 +05:30
end
it { is_expected.to eq(100) }
end
2022-08-13 15:12:31 +05:30
2022-10-11 01:57:18 +05:30
context 'with security_actions_continuous_onboarding experiment' do
2022-08-13 15:12:31 +05:30
let(:completed_actions) { Hash[tracked_action_columns.first, Time.current] }
context 'when control' do
before do
stub_experiments(security_actions_continuous_onboarding: :control)
end
2023-05-27 22:25:52 +05:30
it { is_expected.to eq(10) }
2022-08-13 15:12:31 +05:30
end
context 'when candidate' do
before do
stub_experiments(security_actions_continuous_onboarding: :candidate)
end
2023-05-27 22:25:52 +05:30
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) }
2022-08-13 15:12:31 +05:30
end
end
2021-06-08 01:23:25 +05:30
end
end