Sha256: 061f13c0d70f703f30c81cb49aa87f3f132fd42479a7e215d4bd757f2349f512

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

require 'support/test_data_builder'

describe "Creating a webhook" do

  before do
    TestDataBuilder.new.create_pact_with_hierarchy("Some Consumer", "1", "Some Provider")
  end

  let(:path) { "/webhooks/provider/Some%20Provider/consumer/Some%20Consumer" }
  let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
  let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
  let(:webhook_json) { webhook_hash.to_json }

  subject { post path, webhook_json, headers }

  context "with invalid attributes" do

    let(:webhook_hash) { {} }

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

    it "returns a JSON content type" do
      subject
      expect(last_response.headers['Content-Type']).to eq 'application/json;charset=utf-8'
    end

    it "returns the validation errors" do
      subject
      expect(response_body[:errors]).to_not be_empty
    end

  end

  context "with valid attributes" do

    let(:webhook_hash) do
      {
        events: [{
          name: 'something_happened'
        }],
        request: {
          method: 'POST',
          url: 'http://example.org',
          headers: {
            :"Content-Type" => "application/json"
          },
          body: {
            a: 'body'
          }
        }
      }
    end

    let(:webhook_json) { webhook_hash.to_json }

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

    it "returns the Location header" do
      subject
      expect(last_response.headers['Location']).to match(%r{http://example.org/webhooks/.+})
    end

    it "returns a JSON Content Type" do
      subject
      expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
    end

    it "returns the newly created webhook" do
      subject
      expect(response_body).to include webhook_hash
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.19.2 spec/features/create_webhook_spec.rb
pact_broker-2.19.1 spec/features/create_webhook_spec.rb
pact_broker-2.19.0 spec/features/create_webhook_spec.rb
pact_broker-2.18.0 spec/features/create_webhook_spec.rb
pact_broker-2.17.1 spec/features/create_webhook_spec.rb
pact_broker-2.17.0 spec/features/create_webhook_spec.rb
pact_broker-2.16.1 spec/features/create_webhook_spec.rb
pact_broker-2.16.0 spec/features/create_webhook_spec.rb
pact_broker-2.15.0 spec/features/create_webhook_spec.rb
pact_broker-2.14.0 spec/features/create_webhook_spec.rb
pact_broker-2.13.1 spec/features/create_webhook_spec.rb
pact_broker-2.13.0 spec/features/create_webhook_spec.rb