Commit 45c09e5d authored by Sean Arnold's avatar Sean Arnold

Add search to the resolver

- add specs
- update docs
parent f0bce4cb
......@@ -15,6 +15,10 @@ module Resolvers
description: 'Sort alerts by this criteria',
required: false
argument :search, GraphQL::STRING_TYPE,
description: 'Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.',
required: false
type Types::AlertManagement::AlertType, null: true
def resolve(**args)
......
......@@ -6894,6 +6894,11 @@ type Project {
"""
iid: String
"""
Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.
"""
search: String
"""
Sort alerts by this criteria
"""
......@@ -6934,6 +6939,11 @@ type Project {
"""
last: Int
"""
Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.
"""
search: String
"""
Sort alerts by this criteria
"""
......
......@@ -20655,6 +20655,16 @@
"ofType": null
},
"defaultValue": null
},
{
"name": "search",
"description": "Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"type": {
......@@ -20707,6 +20717,16 @@
},
"defaultValue": null
},
{
"name": "search",
"description": "Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
......
......@@ -10,6 +10,7 @@ describe 'getting Alert Management Alerts' do
let_it_be(:alert_1) { create(:alert_management_alert, :all_fields, :resolved, project: project, issue: nil, severity: :low) }
let_it_be(:alert_2) { create(:alert_management_alert, :all_fields, project: project, severity: :critical, payload: payload) }
let_it_be(:other_project_alert) { create(:alert_management_alert, :all_fields) }
let(:params) { {} }
let(:fields) do
<<~QUERY
......@@ -23,7 +24,7 @@ describe 'getting Alert Management Alerts' do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('alertManagementAlerts', {}, fields)
query_graphql_field('alertManagementAlerts', params, fields)
)
end
......@@ -83,13 +84,7 @@ describe 'getting Alert Management Alerts' do
end
context 'with iid given' do
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('alertManagementAlerts', { iid: alert_1.iid.to_s }, fields)
)
end
let(:params) { { iid: alert_1.iid.to_s } }
it_behaves_like 'a working graphql query'
......@@ -98,14 +93,6 @@ describe 'getting Alert Management Alerts' do
end
context 'sorting data given' do
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('alertManagementAlerts', params, fields)
)
end
let(:params) { 'sort: SEVERITY_DESC' }
let(:iids) { alerts.map { |a| a['iid'] } }
......@@ -123,6 +110,21 @@ describe 'getting Alert Management Alerts' do
end
end
end
context 'searching' do
let(:params) { { search: alert_1.title } }
it_behaves_like 'a working graphql query'
it { expect(alerts.size).to eq(1) }
it { expect(first_alert['iid']).to eq(alert_1.iid.to_s) }
context 'unknown criteria' do
let(:params) { { search: 'something random' } }
it { expect(alerts.size).to eq(0) }
end
end
end
end
end
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