summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/autocomplete/move_to_project_finder_spec.rb13
-rw-r--r--spec/finders/metrics/dashboards/annotations_finder_spec.rb107
2 files changed, 114 insertions, 6 deletions
diff --git a/spec/finders/autocomplete/move_to_project_finder_spec.rb b/spec/finders/autocomplete/move_to_project_finder_spec.rb
index 9129a3b65be..f2da82bb9be 100644
--- a/spec/finders/autocomplete/move_to_project_finder_spec.rb
+++ b/spec/finders/autocomplete/move_to_project_finder_spec.rb
@@ -62,19 +62,20 @@ describe Autocomplete::MoveToProjectFinder do
expect(finder.execute.to_a).to eq([other_reporter_project])
end
- it 'returns a page of projects ordered by name' do
+ it 'returns a page of projects ordered by star count' do
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
- projects = create_list(:project, 3) do |project|
- project.add_developer(user)
- end
+ projects = [
+ create(:project, namespace: user.namespace, star_count: 1),
+ create(:project, namespace: user.namespace, star_count: 5),
+ create(:project, namespace: user.namespace)
+ ]
finder = described_class.new(user, project_id: project.id)
page = finder.execute.to_a
- expected_projects = projects.sort_by(&:name).first(2)
expect(page.length).to eq(2)
- expect(page).to eq(expected_projects)
+ expect(page).to eq([projects[1], projects[0]])
end
end
diff --git a/spec/finders/metrics/dashboards/annotations_finder_spec.rb b/spec/finders/metrics/dashboards/annotations_finder_spec.rb
new file mode 100644
index 00000000000..222875ba2e2
--- /dev/null
+++ b/spec/finders/metrics/dashboards/annotations_finder_spec.rb
@@ -0,0 +1,107 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboards::AnnotationsFinder do
+ describe '#execute' do
+ subject(:annotations) { described_class.new(dashboard: dashboard, params: params).execute }
+
+ let_it_be(:current_user) { create(:user) }
+ let(:path) { 'config/prometheus/common_metrics.yml' }
+ let(:params) { {} }
+ let(:environment) { create(:environment) }
+ let(:dashboard) { PerformanceMonitoring::PrometheusDashboard.new(path: path, environment: environment) }
+
+ context 'there are no annotations records' do
+ it 'returns empty array' do
+ expect(annotations).to be_empty
+ end
+ end
+
+ context 'with annotation records' do
+ let!(:nine_minutes_old_annotation) { create(:metrics_dashboard_annotation, environment: environment, starting_at: 9.minutes.ago, dashboard_path: path) }
+ let!(:fifteen_minutes_old_annotation) { create(:metrics_dashboard_annotation, environment: environment, starting_at: 15.minutes.ago, dashboard_path: path) }
+ let!(:just_created_annotation) { create(:metrics_dashboard_annotation, environment: environment, dashboard_path: path) }
+ let!(:annotation_for_different_env) { create(:metrics_dashboard_annotation, dashboard_path: path) }
+ let!(:annotation_for_different_dashboard) { create(:metrics_dashboard_annotation, dashboard_path: '.gitlab/dashboards/test.yml') }
+
+ it 'loads annotations' do
+ expect(annotations).to match_array [fifteen_minutes_old_annotation, nine_minutes_old_annotation, just_created_annotation]
+ end
+
+ context 'when the from filter is present' do
+ let(:params) do
+ {
+ from: 14.minutes.ago
+ }
+ end
+
+ it 'loads only younger annotations' do
+ expect(annotations).to match_array [nine_minutes_old_annotation, just_created_annotation]
+ end
+ end
+
+ context 'when the to filter is present' do
+ let(:params) do
+ {
+ to: 5.minutes.ago
+ }
+ end
+
+ it 'loads only older annotations' do
+ expect(annotations).to match_array [fifteen_minutes_old_annotation, nine_minutes_old_annotation]
+ end
+ end
+
+ context 'when from and to filters are present' do
+ context 'and to is bigger than from' do
+ let(:params) do
+ {
+ from: 14.minutes.ago,
+ to: 5.minutes.ago
+ }
+ end
+
+ it 'loads only annotations assigned to this interval' do
+ expect(annotations).to match_array [nine_minutes_old_annotation]
+ end
+ end
+
+ context 'and from is bigger than to' do
+ let(:params) do
+ {
+ to: 14.minutes.ago,
+ from: 5.minutes.ago
+ }
+ end
+
+ it 'ignores to parameter and returns annotations starting at from filter' do
+ expect(annotations).to match_array [just_created_annotation]
+ end
+ end
+
+ context 'when from or to filters are empty strings' do
+ let(:params) do
+ {
+ from: '',
+ to: ''
+ }
+ end
+
+ it 'ignores this parameters' do
+ expect(annotations).to match_array [fifteen_minutes_old_annotation, nine_minutes_old_annotation, just_created_annotation]
+ end
+ end
+ end
+
+ context 'dashboard environment is missing' do
+ let(:dashboard) { PerformanceMonitoring::PrometheusDashboard.new(path: path, environment: nil) }
+
+ it 'returns empty relation', :aggregate_failures do
+ expect(annotations).to be_kind_of ::ActiveRecord::Relation
+ expect(annotations).to be_empty
+ end
+ end
+ end
+ end
+end