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 ...@@ -15,6 +15,10 @@ module Resolvers
description: 'Sort alerts by this criteria', description: 'Sort alerts by this criteria',
required: false 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 type Types::AlertManagement::AlertType, null: true
def resolve(**args) def resolve(**args)
......
...@@ -6894,6 +6894,11 @@ type Project { ...@@ -6894,6 +6894,11 @@ type Project {
""" """
iid: String iid: String
"""
Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.
"""
search: String
""" """
Sort alerts by this criteria Sort alerts by this criteria
""" """
...@@ -6934,6 +6939,11 @@ type Project { ...@@ -6934,6 +6939,11 @@ type Project {
""" """
last: Int last: Int
"""
Search criteria for filtering alerts. This will search on title, description, service, monitoring_tool.
"""
search: String
""" """
Sort alerts by this criteria Sort alerts by this criteria
""" """
......
...@@ -20655,6 +20655,16 @@ ...@@ -20655,6 +20655,16 @@
"ofType": null "ofType": null
}, },
"defaultValue": 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": { "type": {
...@@ -20707,6 +20717,16 @@ ...@@ -20707,6 +20717,16 @@
}, },
"defaultValue": 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
},
{ {
"name": "after", "name": "after",
"description": "Returns the elements in the list that come after the specified cursor.", "description": "Returns the elements in the list that come after the specified cursor.",
......
...@@ -10,6 +10,7 @@ describe 'getting Alert Management Alerts' do ...@@ -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_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(: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_it_be(:other_project_alert) { create(:alert_management_alert, :all_fields) }
let(:params) { {} }
let(:fields) do let(:fields) do
<<~QUERY <<~QUERY
...@@ -23,7 +24,7 @@ describe 'getting Alert Management Alerts' do ...@@ -23,7 +24,7 @@ describe 'getting Alert Management Alerts' do
graphql_query_for( graphql_query_for(
'project', 'project',
{ 'fullPath' => project.full_path }, { 'fullPath' => project.full_path },
query_graphql_field('alertManagementAlerts', {}, fields) query_graphql_field('alertManagementAlerts', params, fields)
) )
end end
...@@ -83,13 +84,7 @@ describe 'getting Alert Management Alerts' do ...@@ -83,13 +84,7 @@ describe 'getting Alert Management Alerts' do
end end
context 'with iid given' do context 'with iid given' do
let(:query) do let(:params) { { iid: alert_1.iid.to_s } }
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('alertManagementAlerts', { iid: alert_1.iid.to_s }, fields)
)
end
it_behaves_like 'a working graphql query' it_behaves_like 'a working graphql query'
...@@ -98,14 +93,6 @@ describe 'getting Alert Management Alerts' do ...@@ -98,14 +93,6 @@ describe 'getting Alert Management Alerts' do
end end
context 'sorting data given' do 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(:params) { 'sort: SEVERITY_DESC' }
let(:iids) { alerts.map { |a| a['iid'] } } let(:iids) { alerts.map { |a| a['iid'] } }
...@@ -123,6 +110,21 @@ describe 'getting Alert Management Alerts' do ...@@ -123,6 +110,21 @@ describe 'getting Alert Management Alerts' do
end end
end 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 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