Sha256: 815712a9723d4b13a336b850f7b13017da0e2b6575a8d1c6c8545e24810b1352

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require 'pact/consumer_contract/consumer_contract_writer'
require 'pact/consumer/mock_service/web_request_administration'

module Pact
  module Consumer
    class PactPost < WebRequestAdministration

      attr_accessor :consumer_contract, :verified_interactions, :default_options

      def initialize name, logger, verified_interactions, pact_dir, consumer_contract_details
        super name, logger
        @verified_interactions = verified_interactions
        @default_options = {pact_dir: pact_dir}
        if consumer_contract_details
          @default_options.merge!(consumer_contract_details)
        end
      end

      def request_path
        '/pact'
      end

      def request_method
        'POST'
      end

      def respond env
        consumer_contract_details = JSON.parse(env['rack.input'].string, symbolize_names: true)
        logger.info "Writing pact with details #{consumer_contract_details}"
        consumer_contract_params = default_options.merge(consumer_contract_details.merge(interactions: verified_interactions))
        consumer_contract_writer = ConsumerContractWriter.new(consumer_contract_params, logger)
        json = consumer_contract_writer.write

        [200, {'Content-Type' =>'application/json'}, [json]]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact-mock_service-0.2.3 lib/pact/consumer/mock_service/pact_post.rb
pact-mock_service-0.2.3.pre.rc2 lib/pact/consumer/mock_service/pact_post.rb