Commit 0a05e9d6 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Use presence for every attribute

Use presence for every attribute in
`Gitlab::Alerting::NotificationPayloadParser`
parent 6651b215
......@@ -31,15 +31,15 @@ module Gitlab
def annotations
{
'title' => title,
'description' => payload[:description],
'monitoring_tool' => payload[:monitoring_tool],
'service' => payload[:service],
'description' => payload[:description].presence,
'monitoring_tool' => payload[:monitoring_tool].presence,
'service' => payload[:service].presence,
'hosts' => hosts
}.compact
end
def hosts
payload[:hosts].presence && Array(payload[:hosts])
Array(payload[:hosts]).reject(&:blank?).presence
end
def current_time
......
......@@ -58,7 +58,7 @@ describe Gitlab::Alerting::NotificationPayloadParser do
payload[:start_time] = 'invalid/date/format'
end
it 'sets startsAt to a currurrent time in RFC3339 format' do
it 'sets startsAt to a current time in RFC3339 format' do
expect(subject['startsAt']).to eq(starts_at.rfc3339)
end
end
......@@ -73,5 +73,25 @@ describe Gitlab::Alerting::NotificationPayloadParser do
)
end
end
context 'when payload attributes have blank lines' do
let(:payload) do
{
'title' => '',
'start_time' => '',
'description' => '',
'monitoring_tool' => '',
'service' => '',
'hosts' => ['']
}
end
it 'returns default parameters' do
is_expected.to eq(
'annotations' => { 'title' => 'New: Incident' },
'startsAt' => starts_at.rfc3339
)
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