summaryrefslogtreecommitdiff
path: root/spec/graphql
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb60
-rw-r--r--spec/graphql/types/metrics/dashboard_type_spec.rb11
-rw-r--r--spec/graphql/types/metrics/dashboards/annotation_type_spec.rb17
3 files changed, 86 insertions, 2 deletions
diff --git a/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb
new file mode 100644
index 00000000000..c06fbef53b6
--- /dev/null
+++ b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::Metrics::Dashboards::AnnotationResolver do
+ include GraphqlHelpers
+
+ describe '#resolve' do
+ context 'user with developer access' do
+ subject(:resolve_annotations) { resolve(described_class, obj: dashboard, args: args, ctx: { current_user: current_user }) }
+
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:environment) { create(:environment) }
+ let_it_be(:path) { 'config/prometheus/common_metrics.yml' }
+ let(:dashboard) { PerformanceMonitoring::PrometheusDashboard.new(path: path, environment: environment) }
+ let(:args) do
+ {
+ from: 10.minutes.ago,
+ to: 5.minutes.ago
+ }
+ end
+
+ before_all do
+ environment.project.add_developer(current_user)
+ end
+
+ context 'with annotation records' do
+ let_it_be(:annotation_1) { create(:metrics_dashboard_annotation, environment: environment, starting_at: 9.minutes.ago, dashboard_path: path) }
+
+ it 'loads annotations with usage of finder class', :aggregate_failures do
+ expect_next_instance_of(::Metrics::Dashboards::AnnotationsFinder, dashboard: dashboard, params: args) do |finder|
+ expect(finder).to receive(:execute).and_return [annotation_1]
+ end
+
+ expect(resolve_annotations).to eql [annotation_1]
+ end
+
+ context 'dashboard is missing' do
+ let(:dashboard) { nil }
+
+ it 'returns empty array', :aggregate_failures do
+ expect(::Metrics::Dashboards::AnnotationsFinder).not_to receive(:new)
+
+ expect(resolve_annotations).to be_empty
+ end
+ end
+
+ context 'there are no annotations records' do
+ it 'returns empty array' do
+ allow_next_instance_of(::Metrics::Dashboards::AnnotationsFinder) do |finder|
+ allow(finder).to receive(:execute).and_return []
+ end
+
+ expect(resolve_annotations).to be_empty
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/graphql/types/metrics/dashboard_type_spec.rb b/spec/graphql/types/metrics/dashboard_type_spec.rb
index 4795fd77537..76f2b4b8935 100644
--- a/spec/graphql/types/metrics/dashboard_type_spec.rb
+++ b/spec/graphql/types/metrics/dashboard_type_spec.rb
@@ -7,9 +7,16 @@ describe GitlabSchema.types['MetricsDashboard'] do
it 'has the expected fields' do
expected_fields = %w[
- path
- ]
+ path annotations
+ ]
expect(described_class).to have_graphql_fields(*expected_fields)
end
+
+ describe 'annotations field' do
+ subject { described_class.fields['annotations'] }
+
+ it { is_expected.to have_graphql_type(Types::Metrics::Dashboards::AnnotationType.connection_type) }
+ it { is_expected.to have_graphql_resolver(Resolvers::Metrics::Dashboards::AnnotationResolver) }
+ end
end
diff --git a/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb b/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb
new file mode 100644
index 00000000000..2956a2512eb
--- /dev/null
+++ b/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GitlabSchema.types['MetricsDashboardAnnotation'] do
+ it { expect(described_class.graphql_name).to eq('MetricsDashboardAnnotation') }
+
+ it 'has the expected fields' do
+ expected_fields = %w[
+ description id panel_id starting_at ending_at
+ ]
+
+ expect(described_class).to have_graphql_fields(*expected_fields)
+ end
+
+ it { expect(described_class).to require_graphql_authorizations(:read_metrics_dashboard_annotation) }
+end