Sha256: 5c79768e13fd59ca14917ce13a3674cdd3a67a93d49723888400ed10e365db01

Contents?: true

Size: 1.71 KB

Versions: 20

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'
require 'pact_broker/services/webhook_service'

module PactBroker

  module Services
    describe WebhookService do

      describe ".execute_webhooks" do

        let(:pact) { instance_double(PactBroker::Domain::Pact, consumer: consumer, provider: provider, consumer_version: consumer_version)}
        let(:consumer_version) { PactBroker::Domain::Version.new(number: '1.2.3') }
        let(:consumer) { PactBroker::Domain::Pacticipant.new(name: 'Consumer') }
        let(:provider) { PactBroker::Domain::Pacticipant.new(name: 'Provider') }
        let(:webhooks) { [instance_double(PactBroker::Domain::Webhook)]}

        before do
          allow_any_instance_of(PactBroker::Repositories::WebhookRepository).to receive(:find_by_consumer_and_provider).and_return(webhooks)
          allow(WebhookService).to receive(:run_later)
        end

        subject { WebhookService.execute_webhooks pact }

        it "finds the webhooks" do
          expect_any_instance_of(PactBroker::Repositories::WebhookRepository).to receive(:find_by_consumer_and_provider).with(consumer, provider)
          subject
        end

        context "when webhooks are found" do
          it "executes the webhook" do
            expect(WebhookService).to receive(:run_later).with(webhooks)
            subject
          end
        end

        context "when no webhooks are found" do
          let(:webhooks) { [] }
          it "does nothing" do
            expect(WebhookService).to_not receive(:run_later)
            subject
          end

          it "logs that no webhook was found" do
            expect(PactBroker.logger).to receive(:debug).with(/No webhook found/)
            subject
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
pact_broker-1.15.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.14.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.13.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.12.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.11.2 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.11.1 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.11.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.10.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.9.3 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.9.2 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.9.1 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.9.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.9.0.rc1 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.8.1 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.8.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.7.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.6.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.5.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.4.0 spec/lib/pact_broker/services/webhook_service_spec.rb
pact_broker-1.3.2.rc1 spec/lib/pact_broker/services/webhook_service_spec.rb