Sha256: 4a690251623fbea26e397fd399d92dfe3207bc4d1a98ec2ce4f3bc3622f45c8e

Contents?: true

Size: 1.49 KB

Versions: 63

Compression:

Stored size: 1.49 KB

Contents

require 'support/test_data_builder'
require 'webmock/rspec'
require 'rack/pact_broker/database_transaction'

describe "Execute a webhook" do

  let(:td) { TestDataBuilder.new }

  before do
    td.create_pact_with_hierarchy("Foo", "1", "Bar")
    allow(PactBroker.configuration).to receive(:webhook_scheme_whitelist).and_return(%w[http])
  end

  let(:params) do
    {
      request: {
        method: 'POST',
        url: 'http://example.org',
        headers: {'Content-Type' => 'application/json'},
        body: '${pactbroker.pactUrl}'
      }
    }
  end
  let(:rack_headers) { { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/hal+json" } }

  let(:path) { "/webhooks/execute" }
  let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}

  subject { post(path, params.to_json, rack_headers) }

  context "when the execution is successful" do
    let!(:request) do
      stub_request(:post, /http/).with(body: expected_webhook_url).to_return(:status => 200, body: response_body)
    end

    let(:expected_webhook_url) { %r{http://example.org/pacts/provider/Bar/consumer/Foo.*} }
    let(:response_body) { "webhook-response-body" }

    it "performs the HTTP request" do
      subject
      expect(request).to have_been_made
    end

    it "returns a 200 response" do
      expect(subject.status).to be 200
    end
  end

  context "when there is a validation error" do
    let(:params) { {} }

    it "returns a 400" do
      expect(subject.status).to be 400
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
pact_broker-2.79.1 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.79.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.78.1 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.78.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.77.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.76.2 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.76.1 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.76.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.75.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.74.1 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.74.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.73.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.72.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.71.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.70.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.69.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.68.1 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.68.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.67.0 spec/features/execute_unsaved_webhook_spec.rb
pact_broker-2.66.0 spec/features/execute_unsaved_webhook_spec.rb