summaryrefslogtreecommitdiff
path: root/spec/factories/alerting/alert.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/factories/alerting/alert.rb')
-rw-r--r--spec/factories/alerting/alert.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/factories/alerting/alert.rb b/spec/factories/alerting/alert.rb
new file mode 100644
index 00000000000..285bb14efa2
--- /dev/null
+++ b/spec/factories/alerting/alert.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :alerting_alert, class: 'Gitlab::Alerting::Alert' do
+ project
+ payload { {} }
+
+ transient do
+ metric_id { nil }
+
+ after(:build) do |alert, evaluator|
+ unless alert.payload.key?('startsAt')
+ alert.payload['startsAt'] = Time.now.rfc3339
+ end
+
+ if metric_id = evaluator.metric_id
+ alert.payload['labels'] ||= {}
+ alert.payload['labels']['gitlab_alert_id'] = metric_id.to_s
+ end
+ end
+ end
+
+ skip_create
+ end
+end