Commit e731618e authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '216937-refactor-tests-for-redability' into 'master'

Rename variables to increase tests readability

Closes #216937

See merge request gitlab-org/gitlab!32114
parents 61ed46a4 40600094
......@@ -7,8 +7,8 @@ describe 'getting Alert Management Alerts' do
let_it_be(:payload) { { 'custom' => { 'alert' => 'payload' } } }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
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(:resolved_alert) { create(:alert_management_alert, :all_fields, :resolved, project: project, issue: nil, severity: :low) }
let_it_be(:triggered_alert) { 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) { {} }
......@@ -58,38 +58,38 @@ describe 'getting Alert Management Alerts' do
it 'returns the correct properties of the alerts' do
expect(first_alert).to include(
'iid' => alert_2.iid.to_s,
'issueIid' => alert_2.issue_iid.to_s,
'title' => alert_2.title,
'description' => alert_2.description,
'severity' => alert_2.severity.upcase,
'iid' => triggered_alert.iid.to_s,
'issueIid' => triggered_alert.issue_iid.to_s,
'title' => triggered_alert.title,
'description' => triggered_alert.description,
'severity' => triggered_alert.severity.upcase,
'status' => 'TRIGGERED',
'monitoringTool' => alert_2.monitoring_tool,
'service' => alert_2.service,
'hosts' => alert_2.hosts,
'eventCount' => alert_2.events,
'startedAt' => alert_2.started_at.strftime('%Y-%m-%dT%H:%M:%SZ'),
'monitoringTool' => triggered_alert.monitoring_tool,
'service' => triggered_alert.service,
'hosts' => triggered_alert.hosts,
'eventCount' => triggered_alert.events,
'startedAt' => triggered_alert.started_at.strftime('%Y-%m-%dT%H:%M:%SZ'),
'endedAt' => nil,
'details' => { 'custom.alert' => 'payload' },
'createdAt' => alert_2.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'),
'updatedAt' => alert_2.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ')
'createdAt' => triggered_alert.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'),
'updatedAt' => triggered_alert.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ')
)
expect(second_alert).to include(
'iid' => alert_1.iid.to_s,
'iid' => resolved_alert.iid.to_s,
'issueIid' => nil,
'status' => 'RESOLVED',
'endedAt' => alert_1.ended_at.strftime('%Y-%m-%dT%H:%M:%SZ')
'endedAt' => resolved_alert.ended_at.strftime('%Y-%m-%dT%H:%M:%SZ')
)
end
context 'with iid given' do
let(:params) { { iid: alert_1.iid.to_s } }
let(:params) { { iid: resolved_alert.iid.to_s } }
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) }
it { expect(first_alert['iid']).to eq(resolved_alert.iid.to_s) }
end
context 'sorting data given' do
......@@ -99,25 +99,25 @@ describe 'getting Alert Management Alerts' do
it_behaves_like 'a working graphql query'
it 'sorts in the correct order' do
expect(iids).to eq [alert_1.iid.to_s, alert_2.iid.to_s]
expect(iids).to eq [resolved_alert.iid.to_s, triggered_alert.iid.to_s]
end
context 'ascending order' do
let(:params) { 'sort: SEVERITY_ASC' }
it 'sorts in the correct order' do
expect(iids).to eq [alert_2.iid.to_s, alert_1.iid.to_s]
expect(iids).to eq [triggered_alert.iid.to_s, resolved_alert.iid.to_s]
end
end
end
context 'searching' do
let(:params) { { search: alert_1.title } }
let(:params) { { search: resolved_alert.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) }
it { expect(first_alert['iid']).to eq(resolved_alert.iid.to_s) }
context 'unknown criteria' do
let(:params) { { search: 'something random' } }
......
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