diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-17 09:10:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-17 09:10:44 +0000 |
commit | b9b58dba70466949d761132d2d96f0f24c0b469c (patch) | |
tree | 12fa5fa325cb89b7a5620f5d5556d3a80c931b8f /spec | |
parent | 7118851f0272b099335a34d8ca18a045aa5de51d (diff) | |
download | gitlab-ce-b9b58dba70466949d761132d2d96f0f24c0b469c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
10 files changed, 125 insertions, 31 deletions
diff --git a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js index 3176b28d547..bf4026b65db 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js @@ -33,6 +33,7 @@ describe('View branch rules', () => { let fakeApollo; const projectPath = 'test/testing'; const protectedBranchesPath = 'protected/branches'; + const approvalRulesPath = 'approval/rules'; const branchProtectionsMockRequestHandler = jest .fn() .mockResolvedValue(branchProtectionsMockResponse); @@ -42,7 +43,7 @@ describe('View branch rules', () => { wrapper = shallowMountExtended(RuleView, { apolloProvider: fakeApollo, - provide: { projectPath, protectedBranchesPath }, + provide: { projectPath, protectedBranchesPath, approvalRulesPath }, }); await waitForPromises(); @@ -57,6 +58,7 @@ describe('View branch rules', () => { const findBranchProtectionTitle = () => wrapper.findByText(I18N.protectBranchTitle); const findBranchProtections = () => wrapper.findAllComponents(Protection); const findForcePushTitle = () => wrapper.findByText(I18N.allowForcePushDescription); + const findApprovalsTitle = () => wrapper.findByText(I18N.approvalsTitle); it('gets the branch param from url and renders it in the view', () => { expect(util.getParameterByName).toHaveBeenCalledWith('branch'); @@ -98,4 +100,14 @@ describe('View branch rules', () => { ...protectionMockProps, }); }); + + it('renders a branch protection component for approvals', () => { + expect(findApprovalsTitle().exists()).toBe(true); + + expect(findBranchProtections().at(2).props()).toMatchObject({ + header: sprintf(I18N.approvalsHeader, { total: 0 }), + headerLinkHref: approvalRulesPath, + headerLinkTitle: I18N.manageApprovalsLinkTitle, + }); + }); }); diff --git a/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js b/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js index c5774977205..c3f573061da 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/mock_data.js @@ -36,6 +36,8 @@ const accessLevelsMock = [ { accessLevelDescription: 'Maintainer' }, ]; +const approvalsRequired = 3; + const groupsMock = [{ name: 'test_group_1' }, { name: 'test_group_2' }]; export const protectionPropsMock = { @@ -45,12 +47,20 @@ export const protectionPropsMock = { roles: accessLevelsMock, users: usersMock, groups: groupsMock, + approvals: [ + { + name: 'test', + eligibleApprovers: { nodes: usersMock }, + approvalsRequired, + }, + ], }; export const protectionRowPropsMock = { title: 'Test title', users: usersMock, accessLevels: accessLevelsMock, + approvalsRequired, }; export const accessLevelsMockResponse = [ diff --git a/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js index 7770e1fb2aa..b0a69bedd3e 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/protection_row_spec.js @@ -25,6 +25,8 @@ describe('Branch rule protection row', () => { const findAvatarLinks = () => wrapper.findAllComponents(GlAvatarLink); const findAvatars = () => wrapper.findAllComponents(GlAvatar); const findAccessLevels = () => wrapper.findAllByTestId('access-level'); + const findApprovalsRequired = () => + wrapper.findByText(`${protectionRowPropsMock.approvalsRequired} approvals required`); it('renders a title', () => { expect(findTitle().exists()).toBe(true); @@ -62,4 +64,8 @@ describe('Branch rule protection row', () => { protectionRowPropsMock.accessLevels[1].accessLevelDescription, ); }); + + it('renders the number of approvals required', () => { + expect(findApprovalsRequired().exists()).toBe(true); + }); }); diff --git a/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js index 91d16fd86a6..e2fbb4f5bbb 100644 --- a/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js +++ b/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js @@ -56,4 +56,13 @@ describe('Branch rule protection', () => { title: i18n.groupsTitle, }); }); + + it('renders a protection row for approvals', () => { + const approval = protectionPropsMock.approvals[0]; + expect(findProtectionRows().at(3).props()).toMatchObject({ + title: approval.name, + users: approval.eligibleApprovers.nodes, + approvalsRequired: approval.approvalsRequired, + }); + }); }); diff --git a/spec/frontend/vue_shared/components/sidebar/labels_select_vue/store/mutations_spec.js b/spec/frontend/vue_shared/components/sidebar/labels_select_vue/store/mutations_spec.js index 99034e360a1..2b2508b5e11 100644 --- a/spec/frontend/vue_shared/components/sidebar/labels_select_vue/store/mutations_spec.js +++ b/spec/frontend/vue_shared/components/sidebar/labels_select_vue/store/mutations_spec.js @@ -193,6 +193,16 @@ describe('LabelsSelect Mutations', () => { expect(state.labels[l.id - 1].set).toBe(false); }); }); + it('allows selection of multiple scoped labels', () => { + const state = { labels: cloneDeep(labels), allowMultipleScopedLabels: true }; + + mutations[types.UPDATE_SELECTED_LABELS](state, { labels: [{ id: labels[4].id }] }); + mutations[types.UPDATE_SELECTED_LABELS](state, { labels: [{ id: labels[5].id }] }); + + expect(state.labels[4].set).toBe(true); + expect(state.labels[5].set).toBe(true); + expect(state.labels[6].set).toBe(true); + }); }); describe(`${types.UPDATE_LABELS_SET_STATE}`, () => { diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/work_items_activity_aggregated_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/work_items_activity_aggregated_metric_spec.rb index c13a5ba4d72..3e315692d0a 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/work_items_activity_aggregated_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/work_items_activity_aggregated_metric_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::WorkItemsActivityAggreg let(:metric_definition) do { data_source: 'redis_hll', - time_frame: '7d', + time_frame: time_frame, options: { aggregate: { operator: 'OR' @@ -15,6 +15,7 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::WorkItemsActivityAggreg users_creating_work_items users_updating_work_item_title users_updating_work_item_dates + users_updating_work_item_iteration ] } } @@ -24,31 +25,36 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::WorkItemsActivityAggreg freeze_time { example.run } end - describe '#available?' do - it 'returns false without track_work_items_activity feature' do - stub_feature_flags(track_work_items_activity: false) + where(:time_frame) { [['28d'], ['7d']] } - expect(described_class.new(metric_definition).available?).to eq(false) - end + with_them do + describe '#available?' do + it 'returns false without track_work_items_activity feature' do + stub_feature_flags(track_work_items_activity: false) + + expect(described_class.new(metric_definition).available?).to eq(false) + end - it 'returns true with track_work_items_activity feature' do - stub_feature_flags(track_work_items_activity: true) + it 'returns true with track_work_items_activity feature' do + stub_feature_flags(track_work_items_activity: true) - expect(described_class.new(metric_definition).available?).to eq(true) + expect(described_class.new(metric_definition).available?).to eq(true) + end end - end - describe '#value', :clean_gitlab_redis_shared_state do - let(:counter) { Gitlab::UsageDataCounters::HLLRedisCounter } + describe '#value', :clean_gitlab_redis_shared_state do + let(:counter) { Gitlab::UsageDataCounters::HLLRedisCounter } - before do - counter.track_event(:users_creating_work_items, values: 1, time: 1.week.ago) - counter.track_event(:users_updating_work_item_title, values: 1, time: 1.week.ago) - counter.track_event(:users_updating_work_item_dates, values: 2, time: 1.week.ago) - end + before do + counter.track_event(:users_creating_work_items, values: 1, time: 1.week.ago) + counter.track_event(:users_updating_work_item_title, values: 1, time: 1.week.ago) + counter.track_event(:users_updating_work_item_dates, values: 2, time: 1.week.ago) + counter.track_event(:users_updating_work_item_iteration, values: 2, time: 1.week.ago) + end - it 'has correct value' do - expect(described_class.new(metric_definition).value).to eq 2 + it 'has correct value' do + expect(described_class.new(metric_definition).value).to eq 2 + end end end end diff --git a/spec/migrations/populate_releases_access_level_from_repository_spec.rb b/spec/migrations/populate_releases_access_level_from_repository_spec.rb new file mode 100644 index 00000000000..2bb97662923 --- /dev/null +++ b/spec/migrations/populate_releases_access_level_from_repository_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe PopulateReleasesAccessLevelFromRepository, :migration do + let(:projects) { table(:projects) } + let(:groups) { table(:namespaces) } + let(:project_features) { table(:project_features) } + + let(:group) { groups.create!(name: 'test-group', path: 'test-group') } + let(:project) { projects.create!(namespace_id: group.id, project_namespace_id: group.id) } + let(:project_feature) do + project_features.create!(project_id: project.id, pages_access_level: 20, **project_feature_attributes) + end + + # repository_access_level and releases_access_level default to ENABLED + describe '#up' do + context 'when releases_access_level is greater than repository_access_level' do + let(:project_feature_attributes) { { repository_access_level: ProjectFeature::PRIVATE } } + + it 'reduces releases_access_level to match repository_access_level' do + expect { migrate! }.to change { project_feature.reload.releases_access_level } + .from(ProjectFeature::ENABLED) + .to(ProjectFeature::PRIVATE) + end + end + + context 'when releases_access_level is less than repository_access_level' do + let(:project_feature_attributes) { { releases_access_level: ProjectFeature::DISABLED } } + + it 'does not change releases_access_level' do + expect { migrate! }.not_to change { project_feature.reload.releases_access_level } + .from(ProjectFeature::DISABLED) + end + end + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ec0fe456d99..9713734e97a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -632,15 +632,6 @@ RSpec.describe Ci::Build do it { expect(subject).to be_falsey } end - context 'when prevent_outdated_deployment_jobs FF is disabled' do - before do - stub_feature_flags(prevent_outdated_deployment_jobs: false) - expect(build.deployment).not_to receive(:rollback?) - end - - it { expect(subject).to be_falsey } - end - context 'when build can prevent rollback deployment' do before do expect(build.deployment).to receive(:older_than_last_successful_deployment?).and_return(true) diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 87fa5289795..bf1cf9856a0 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -171,11 +171,22 @@ RSpec.describe Deployment do end it 'executes Deployments::DropOlderDeploymentsWorker asynchronously' do + stub_feature_flags(prevent_outdated_deployment_jobs: false) + expect(Deployments::DropOlderDeploymentsWorker) .to receive(:perform_async).once.with(deployment.id) deployment.run! end + + it 'does not execute Deployments::DropOlderDeploymentsWorker when FF enabled' do + stub_feature_flags(prevent_outdated_deployment_jobs: true) + + expect(Deployments::DropOlderDeploymentsWorker) + .not_to receive(:perform_async).with(deployment.id) + + deployment.run! + end end context 'when deployment succeeded' do diff --git a/spec/models/namespace/aggregation_schedule_spec.rb b/spec/models/namespace/aggregation_schedule_spec.rb index 3f6a890654a..45b66fa12dd 100644 --- a/spec/models/namespace/aggregation_schedule_spec.rb +++ b/spec/models/namespace/aggregation_schedule_spec.rb @@ -12,14 +12,14 @@ RSpec.describe Namespace::AggregationSchedule, :clean_gitlab_redis_shared_state, describe "#default_lease_timeout" do subject(:default_lease_timeout) { default_timeout } - it { is_expected.to eq 1.hour.to_i } + it { is_expected.to eq 30.minutes.to_i } context 'when remove_namespace_aggregator_delay FF is disabled' do before do stub_feature_flags(remove_namespace_aggregator_delay: false) end - it { is_expected.to eq 1.5.hours.to_i } + it { is_expected.to eq 1.hour.to_i } end end |