From a69fe534e3f0052e6b1f74a0a5ee16497761397c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 22 Feb 2024 05:46:20 -0500 Subject: [PATCH] Add basic coverage for `WebhookService` class (#29331) --- spec/services/webhook_service_spec.rb | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/services/webhook_service_spec.rb diff --git a/spec/services/webhook_service_spec.rb b/spec/services/webhook_service_spec.rb new file mode 100644 index 0000000000..22a60db9f5 --- /dev/null +++ b/spec/services/webhook_service_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe WebhookService do + describe '#call' do + context 'with a relevant event webhook' do + let!(:report) { Fabricate(:report) } + let!(:webhook) { Fabricate(:webhook, events: ['report.created']) } + + it 'finds and delivers webhook payloads' do + expect { subject.call('report.created', report) } + .to enqueue_sidekiq_job(Webhooks::DeliveryWorker) + .with( + webhook.id, + anything + ) + end + end + + context 'without any relevant event webhooks' do + let!(:report) { Fabricate(:report) } + + it 'does not deliver webhook payloads' do + expect { subject.call('report.created', report) } + .to_not enqueue_sidekiq_job(Webhooks::DeliveryWorker) + end + end + end +end