diff options
Diffstat (limited to 'spec')
6 files changed, 136 insertions, 11 deletions
diff --git a/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb index 69db8d016d7..75b5d31d134 100644 --- a/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb +++ b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb @@ -59,6 +59,12 @@ describe Mutations::ResolvesIssuable do expect(result).to be_nil end + + it 'returns nil if parent path is empty' do + result = mutation.resolve_issuable(type: type, parent_path: "", iid: issuable.iid) + + expect(result).to be_nil + end end end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 0bd5043d855..4217d257ab3 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -52,6 +52,12 @@ describe Resolvers::MergeRequestsResolver do expect(result).to be_empty end + + it 'resolves an unknown project to be empty' do + result = batch_sync { resolve_mr(nil, iid: iid_1) } + + expect(result.compact).to be_empty + end end def resolve_mr(project, args) diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb index 877a760152d..f52fe8ef612 100644 --- a/spec/lib/gitlab/git_access_snippet_spec.rb +++ b/spec/lib/gitlab/git_access_snippet_spec.rb @@ -209,16 +209,6 @@ describe Gitlab::GitAccessSnippet do expect { push_access_check }.to raise_forbidden('foo') end - - context 'when feature flag :snippet_count_check is disabled' do - it 'does not check push file count' do - stub_feature_flags(snippet_count_check: false) - - expect(Gitlab::Checks::PushFileCountCheck).not_to receive(:new) - - expect { push_access_check }.not_to raise_error - end - end end private diff --git a/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb b/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb index 31359abdce3..4f21bd14122 100644 --- a/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb +++ b/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::Middleware::RailsQueueDuration do let(:transaction) { Gitlab::Metrics::WebTransaction.new(env) } before do - expect(app).to receive(:call).with(env).and_return('yay') + allow(app).to receive(:call).with(env).and_return('yay') end describe '#call' do @@ -42,6 +42,13 @@ describe Gitlab::Middleware::RailsQueueDuration do expect(middleware.call(env)).to eq('yay') end end + + it 'creates a metric with a docstring' do + metric = middleware.send(:metric_rails_queue_duration_seconds) + + expect(metric).to be_instance_of(Prometheus::Client::Histogram) + expect(metric.docstring).to eq('Measures latency between GitLab Workhorse forwarding a request to Rails') + end end end end diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index af191172d33..65ae85ea78f 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -179,6 +179,16 @@ describe ProjectPresenter do end end + describe '#storage_anchor_data' do + it 'returns storage data' do + expect(presenter.storage_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0 Bytes'), + link: nil + ) + end + end + describe '#releases_anchor_data' do it 'does not return release count' do expect(presenter.releases_anchor_data).to be_nil @@ -232,6 +242,16 @@ describe ProjectPresenter do end end + describe '#storage_anchor_data' do + it 'returns storage data' do + expect(presenter.storage_anchor_data).to have_attributes( + is_link: true, + label: a_string_including('0 Bytes'), + link: presenter.project_tree_path(project) + ) + end + end + describe '#releases_anchor_data' do it 'returns release count if user can read release' do project.add_maintainer(user) diff --git a/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb b/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb new file mode 100644 index 00000000000..a66150be42c --- /dev/null +++ b/spec/services/metrics/dashboard/gitlab_alert_embed_service_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Metrics::Dashboard::GitlabAlertEmbedService do + include MetricsDashboardHelpers + + let_it_be(:alert) { create(:prometheus_alert) } + let_it_be(:project) { alert.project } + let_it_be(:user) { create(:user) } + let(:alert_id) { alert.id } + + before do + project.add_maintainer(user) + project.clear_memoization(:licensed_feature_available) + end + + describe '.valid_params?' do + let(:valid_params) do + { + embedded: true, + prometheus_alert_id: alert_id + } + end + + subject { described_class.valid_params?(params) } + + let(:params) { valid_params } + + it { is_expected.to be_truthy } + + context 'missing embedded' do + let(:params) { valid_params.except(:embedded) } + + it { is_expected.to be_falsey } + end + + context 'not embedded' do + let(:params) { valid_params.merge(embedded: 'false') } + + it { is_expected.to be_falsey } + end + + context 'missing alert id' do + let(:params) { valid_params.except(:prometheus_alert_id) } + + it { is_expected.to be_falsey } + end + + context 'missing alert id' do + let(:params) { valid_params.merge(prometheus_alert_id: 'none') } + + it { is_expected.to be_falsey } + end + end + + describe '#get_dashboard' do + let(:service_params) do + [ + project, + user, + { + embedded: true, + prometheus_alert_id: alert_id + } + ] + end + + let(:service_call) { described_class.new(*service_params).get_dashboard } + + context 'when alerting is available' do + it_behaves_like 'valid embedded dashboard service response' + it_behaves_like 'raises error for users with insufficient permissions' + + it 'uses the metric info corresponding to the alert' do + result = service_call + metrics = result[:dashboard][:panel_groups][0][:panels][0][:metrics] + + expect(metrics.length).to eq 1 + expect(metrics.first[:metric_id]).to eq alert.prometheus_metric_id + end + + context 'when the metric does not exist' do + let(:alert_id) { -4 } + + it_behaves_like 'misconfigured dashboard service response', :not_found + end + + it 'does not cache the unprocessed dashboard' do + expect(Gitlab::Metrics::Dashboard::Cache).not_to receive(:fetch) + + described_class.new(*service_params).get_dashboard + end + end + end +end |