Commit 9160e428 authored by Sean Arnold's avatar Sean Arnold

Tweak & fix alert specs

- Add more cases
- Simplify contexts
- Fix creating of existing_alert
parent d61cc087
......@@ -83,24 +83,21 @@ RSpec.describe AlertManagement::Alert do
end
describe 'fingerprint' do
let_it_be(:project) { create(:project) }
let_it_be(:fingerprint) { 'fingerprint' }
let_it_be(:existing_alert) { create(:alert_management_alert, fingerprint: fingerprint) }
let(:new_alert) { build(:alert_management_alert, fingerprint: fingerprint, project: project) }
subject { new_alert }
context 'adding an alert with the same fingerprint' do
context 'same project' do
let(:project) { existing_alert.project }
it { is_expected.not_to be_valid }
context 'various states' do
context 'same project, various states' do
using RSpec::Parameterized::TableSyntax
# We are only validating uniqueness for non-resolved alerts
where(:existing_status, :new_status, :valid) do
:resolved | :triggered | true
:resolved | :acknowledged | true
:resolved | :ignored | true
:resolved | :resolved | true
:triggered | :triggered | false
:triggered | :acknowledged | false
......@@ -117,18 +114,19 @@ RSpec.describe AlertManagement::Alert do
end
with_them do
let(:existing_alert) { create(:alert_management_alert, existing_status, fingerprint: fingerprint) }
let!(:existing_alert) { create(:alert_management_alert, existing_status, fingerprint: fingerprint, project: project) }
let(:new_alert) { build(:alert_management_alert, new_status, fingerprint: fingerprint, project: project) }
it 'gives the correct validity' do
expect(new_alert.valid?).to eq(valid)
end
if params[:valid]
it { is_expected.to be_valid }
else
it { is_expected.to be_invalid }
end
end
end
context 'different project' do
let(:project) { create(:project) }
let!(:existing_alert) { create(:alert_management_alert, fingerprint: fingerprint) }
it { is_expected.to be_valid }
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