Commit f0bce4cb authored by Sean Arnold's avatar Sean Arnold

Add alert management alert search

- Scope & specs
- Finder & specs
parent 08d5d350
......@@ -13,6 +13,7 @@ module AlertManagement
collection = project.alert_management_alerts
collection = by_status(collection)
collection = by_search(collection)
collection = by_iid(collection)
sort(collection)
end
......@@ -33,6 +34,10 @@ module AlertManagement
values.present? ? collection.for_status(values) : collection
end
def by_search(collection)
params[:search] ? collection.search(params[:search]) : collection
end
def sort(collection)
params[:sort] ? collection.sort_by_attribute(params[:sort]) : collection
end
......
......@@ -5,6 +5,7 @@ module AlertManagement
include AtomicInternalId
include ShaAttribute
include Sortable
include Gitlab::SQL::Pattern
STATUSES = {
triggered: 0,
......@@ -97,6 +98,7 @@ module AlertManagement
scope :for_iid, -> (iid) { where(iid: iid) }
scope :for_status, -> (status) { where(status: status) }
scope :for_fingerprint, -> (project, fingerprint) { where(project: project, fingerprint: fingerprint) }
scope :search, -> (query) { fuzzy_search(query, [:title, :description, :monitoring_tool, :service]) }
scope :order_start_time, -> (sort_order) { order(started_at: sort_order) }
scope :order_end_time, -> (sort_order) { order(ended_at: sort_order) }
......
......@@ -24,6 +24,10 @@ FactoryBot.define do
monitoring_tool { FFaker::AWS.product_description }
end
trait :with_description do
description { FFaker::Lorem.sentence }
end
trait :with_host do
hosts { [FFaker::Internet.ip_v4_address] }
end
......@@ -66,6 +70,7 @@ FactoryBot.define do
with_service
with_monitoring_tool
with_host
with_description
low_severity
end
end
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
describe AlertManagement::AlertsFinder, '#execute' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:alert_1) { create(:alert_management_alert, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:alert_2) { create(:alert_management_alert, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:alert_3) { create(:alert_management_alert) }
let_it_be(:alert_1) { create(:alert_management_alert, :all_fields, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:alert_2) { create(:alert_management_alert, :all_fields, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:alert_3) { create(:alert_management_alert, :all_fields) }
let(:params) { {} }
subject { described_class.new(current_user, project, params).execute }
......@@ -222,5 +222,37 @@ describe AlertManagement::AlertsFinder, '#execute' do
end
end
end
context 'search query given' do
context 'searching title' do
let(:params) { { search: alert_1.title } }
it { is_expected.to match_array([alert_1]) }
end
context 'searching description' do
let(:params) { { search: alert_1.description } }
it { is_expected.to match_array([alert_1]) }
end
context 'searching service' do
let(:params) { { search: alert_1.service } }
it { is_expected.to match_array([alert_1]) }
end
context 'searching monitoring tool' do
let(:params) { { search: alert_1.monitoring_tool } }
it { is_expected.to match_array([alert_1]) }
end
context 'searching something else' do
let(:params) { { search: alert_1.fingerprint } }
it { is_expected.to be_empty }
end
end
end
end
......@@ -162,7 +162,44 @@ describe AlertManagement::Alert do
it { is_expected.to contain_exactly(alert_1) }
end
describe '.details' do
describe '.search' do
let(:query) { 'rspec' }
let(:attribute_data) { 'RSPEC data' }
subject { AlertManagement::Alert.search(query) }
context 'does not contain search string' do
let!(:alert) { create(:alert_management_alert) }
it { is_expected.to be_empty }
end
context 'title includes query' do
let!(:alert) { create(:alert_management_alert, title: attribute_data) }
it { is_expected.to contain_exactly(alert) }
end
context 'description includes query' do
let!(:alert) { create(:alert_management_alert, description: attribute_data) }
it { is_expected.to contain_exactly(alert) }
end
context 'service includes query' do
let!(:alert) { create(:alert_management_alert, service: attribute_data) }
it { is_expected.to contain_exactly(alert) }
end
context 'monitoring tool includes query' do
let!(:alert) { create(:alert_management_alert, monitoring_tool: attribute_data) }
it { is_expected.to contain_exactly(alert) }
end
end
describe '#details' do
let(:payload) do
{
'title' => 'Details title',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment