diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/finders/alert_management | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/finders/alert_management')
-rw-r--r-- | spec/finders/alert_management/alerts_finder_spec.rb | 115 |
1 files changed, 64 insertions, 51 deletions
diff --git a/spec/finders/alert_management/alerts_finder_spec.rb b/spec/finders/alert_management/alerts_finder_spec.rb index 926446b31d5..e74f3ac68ed 100644 --- a/spec/finders/alert_management/alerts_finder_spec.rb +++ b/spec/finders/alert_management/alerts_finder_spec.rb @@ -39,19 +39,19 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do end context 'status given' do - let(:params) { { status: AlertManagement::Alert::STATUSES[:resolved] } } + let(:params) { { status: :resolved } } it { is_expected.to match_array(resolved_alert) } context 'with an array of statuses' do let(:triggered_alert) { create(:alert_management_alert) } - let(:params) { { status: [AlertManagement::Alert::STATUSES[:resolved]] } } + let(:params) { { status: [:resolved] } } it { is_expected.to match_array(resolved_alert) } end context 'with no alerts of status' do - let(:params) { { status: AlertManagement::Alert::STATUSES[:acknowledged] } } + let(:params) { { status: :acknowledged } } it { is_expected.to be_empty } end @@ -169,12 +169,6 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do end context 'when sorting by status' do - let(:statuses) { AlertManagement::Alert::STATUSES } - let(:triggered) { statuses[:triggered] } - let(:acknowledged) { statuses[:acknowledged] } - let(:resolved) { statuses[:resolved] } - let(:ignored) { statuses[:ignored] } - let_it_be(:alert_triggered) { create(:alert_management_alert, project: project) } let_it_be(:alert_acknowledged) { create(:alert_management_alert, :acknowledged, project: project) } let_it_be(:alert_resolved) { create(:alert_management_alert, :resolved, project: project) } @@ -184,7 +178,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do let(:params) { { sort: 'status_asc' } } it 'sorts by status: Ignored > Resolved > Acknowledged > Triggered' do - expect(execute.map(&:status).uniq).to eq([ignored, resolved, acknowledged, triggered]) + expect(execute.map(&:status_name).uniq).to eq([:ignored, :resolved, :acknowledged, :triggered]) end end @@ -192,64 +186,83 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do let(:params) { { sort: 'status_desc' } } it 'sorts by status: Triggered > Acknowledged > Resolved > Ignored' do - expect(execute.map(&:status).uniq).to eq([triggered, acknowledged, resolved, ignored]) + expect(execute.map(&:status_name).uniq).to eq([:triggered, :acknowledged, :resolved, :ignored]) end end end end - end - context 'search query given' do - let_it_be(:alert) do - create(:alert_management_alert, - :with_fingerprint, - title: 'Title', - description: 'Desc', - service: 'Service', - monitoring_tool: 'Monitor' - ) - end + context 'search query given' do + let_it_be(:alert) do + create(:alert_management_alert, + :with_fingerprint, + project: project, + title: 'Title', + description: 'Desc', + service: 'Service', + monitoring_tool: 'Monitor' + ) + end - before do - alert.project.add_developer(current_user) - end + context 'searching title' do + let(:params) { { search: alert.title } } - subject { described_class.new(current_user, alert.project, params).execute } + it { is_expected.to match_array([alert]) } + end - context 'searching title' do - let(:params) { { search: alert.title } } + context 'searching description' do + let(:params) { { search: alert.description } } - it { is_expected.to match_array([alert]) } - end + it { is_expected.to match_array([alert]) } + end - context 'searching description' do - let(:params) { { search: alert.description } } + context 'searching service' do + let(:params) { { search: alert.service } } - it { is_expected.to match_array([alert]) } - end + it { is_expected.to match_array([alert]) } + end - context 'searching service' do - let(:params) { { search: alert.service } } + context 'searching monitoring tool' do + let(:params) { { search: alert.monitoring_tool } } - it { is_expected.to match_array([alert]) } - end + it { is_expected.to match_array([alert]) } + end - context 'searching monitoring tool' do - let(:params) { { search: alert.monitoring_tool } } + context 'searching something else' do + let(:params) { { search: alert.fingerprint } } - it { is_expected.to match_array([alert]) } - end + it { is_expected.to be_empty } + end - context 'searching something else' do - let(:params) { { search: alert.fingerprint } } + context 'empty search' do + let(:params) { { search: ' ' } } - it { is_expected.to be_empty } + it { is_expected.not_to include(alert) } + end end - context 'empty search' do - let(:params) { { search: ' ' } } + context 'assignee username given' do + let_it_be(:assignee) { create(:user) } + let_it_be(:alert) { create(:alert_management_alert, project: project, assignees: [assignee]) } + let(:params) { { assignee_username: username } } + + context 'with valid assignee_username' do + let(:username) { assignee.username } + + it { is_expected.to match_array([alert]) } + end - it { is_expected.to match_array([alert]) } + context 'with invalid assignee_username' do + let(:username) { 'unknown username' } + + it { is_expected.to be_empty } + end + + context 'with empty assignee_username' do + let(:username) { ' ' } + + it { is_expected.not_to include(alert) } + end end end end @@ -261,12 +274,12 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do project.add_developer(current_user) end - it { is_expected.to match({ 2 => 1, 3 => 1 }) } # one resolved and one ignored + it { is_expected.to match(resolved: 1, ignored: 1) } context 'when filtering params are included' do - let(:params) { { status: AlertManagement::Alert::STATUSES[:resolved] } } + let(:params) { { status: :resolved } } - it { is_expected.to match({ 2 => 1 }) } # one resolved + it { is_expected.to match(resolved: 1) } end end end |