debian-mirror-gitlab/spec/requests/api/graphql/metrics/dashboard/annotations_spec.rb

88 lines
3 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'Getting Metrics Dashboard Annotations' do
2020-04-22 19:07:51 +05:30
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:current_user) { create(:user) }
let_it_be(:path) { 'config/prometheus/common_metrics.yml' }
let_it_be(:from) { "2020-04-01T03:29:25Z" }
let_it_be(:to) { Time.zone.now.advance(minutes: 5) }
let_it_be(:annotation) { create(:metrics_dashboard_annotation, environment: environment, dashboard_path: path) }
let_it_be(:annotation_for_different_env) { create(:metrics_dashboard_annotation, dashboard_path: path) }
let_it_be(:annotation_for_different_dashboard) { create(:metrics_dashboard_annotation, environment: environment, dashboard_path: ".gitlab/dashboards/test.yml") }
let_it_be(:to_old_annotation) do
create(:metrics_dashboard_annotation, environment: environment, starting_at: Time.parse(from).advance(minutes: -5), dashboard_path: path)
end
let_it_be(:to_new_annotation) do
create(:metrics_dashboard_annotation, environment: environment, starting_at: to.advance(minutes: 5), dashboard_path: path)
end
2020-05-24 23:13:21 +05:30
let(:args) { "from: \"#{from}\", to: \"#{to}\"" }
2020-04-22 19:07:51 +05:30
let(:fields) do
<<~QUERY
#{all_graphql_fields_for('MetricsDashboardAnnotation'.classify)}
QUERY
end
let(:query) do
%(
2020-10-24 23:57:45 +05:30
query {
project(fullPath: "#{project.full_path}") {
environments(name: "#{environment.name}") {
nodes {
metricsDashboard(path: "#{path}") {
annotations(#{args}) {
nodes {
#{fields}
2020-04-22 19:07:51 +05:30
}
}
}
}
}
2020-10-24 23:57:45 +05:30
}
}
)
2020-04-22 19:07:51 +05:30
end
2020-05-24 23:13:21 +05:30
before do
project.add_developer(current_user)
post_graphql(query, current_user: current_user)
end
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'a working graphql query'
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
it 'returns annotations' do
annotations = graphql_data.dig('project', 'environments', 'nodes')[0].dig('metricsDashboard', 'annotations', 'nodes')
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
expect(annotations).to match_array [{
"description" => annotation.description,
"id" => annotation.to_global_id.to_s,
"panelId" => annotation.panel_xid,
"startingAt" => annotation.starting_at.iso8601,
"endingAt" => nil
}]
end
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
context 'arguments' do
context 'from is missing' do
let(:args) { "to: \"#{from}\"" }
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
it 'returns error' do
2020-04-22 19:07:51 +05:30
post_graphql(query, current_user: current_user)
2020-05-24 23:13:21 +05:30
expect(graphql_errors[0]).to include("message" => "Field 'annotations' is missing required arguments: from")
2020-04-22 19:07:51 +05:30
end
2020-05-24 23:13:21 +05:30
end
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
context 'to is missing' do
let(:args) { "from: \"#{from}\"" }
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
it_behaves_like 'a working graphql query'
2020-04-22 19:07:51 +05:30
end
end
end