debian-mirror-gitlab/spec/graphql/resolvers/alert_management/alert_resolver_spec.rb

64 lines
2.1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::AlertManagement::AlertResolver do
2020-05-24 23:13:21 +05:30
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
2020-10-24 23:57:45 +05:30
let_it_be(:resolved_alert) { create(:alert_management_alert, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:ignored_alert) { create(:alert_management_alert, :ignored, project: project, events: 1, severity: :critical) }
2020-05-24 23:13:21 +05:30
let_it_be(:alert_other_proj) { create(:alert_management_alert) }
let(:args) { {} }
subject { resolve_alerts(args) }
context 'user does not have permission' do
it { is_expected.to eq(AlertManagement::Alert.none) }
end
context 'user has permission' do
before do
project.add_developer(current_user)
end
2020-10-24 23:57:45 +05:30
it { is_expected.to contain_exactly(resolved_alert, ignored_alert) }
2020-05-24 23:13:21 +05:30
context 'finding by iid' do
2020-10-24 23:57:45 +05:30
let(:args) { { iid: resolved_alert.iid } }
2020-05-24 23:13:21 +05:30
2020-10-24 23:57:45 +05:30
it { is_expected.to contain_exactly(resolved_alert) }
2020-05-24 23:13:21 +05:30
end
context 'finding by status' do
let(:args) { { status: [Types::AlertManagement::StatusEnum.values['IGNORED'].value] } }
2020-10-24 23:57:45 +05:30
it { is_expected.to contain_exactly(ignored_alert) }
2020-05-24 23:13:21 +05:30
end
describe 'sorting' do
# Other sorting examples in spec/finders/alert_management/alerts_finder_spec.rb
context 'when sorting by events count' do
let_it_be(:alert_count_6) { create(:alert_management_alert, project: project, events: 6) }
let_it_be(:alert_count_3) { create(:alert_management_alert, project: project, events: 3) }
it 'sorts alerts ascending' do
2020-10-24 23:57:45 +05:30
expect(resolve_alerts(sort: :event_count_asc)).to eq [ignored_alert, resolved_alert, alert_count_3, alert_count_6]
2020-05-24 23:13:21 +05:30
end
it 'sorts alerts descending' do
2020-10-24 23:57:45 +05:30
expect(resolve_alerts(sort: :event_count_desc)).to eq [alert_count_6, alert_count_3, resolved_alert, ignored_alert]
2020-05-24 23:13:21 +05:30
end
end
end
end
private
def resolve_alerts(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
end